2018-02-16 01:35:15 -07:00
|
|
|
<template>
|
|
|
|
<mk-ui>
|
|
|
|
<header :class="$style.header">
|
2018-02-25 08:39:05 -07:00
|
|
|
<h1>{{ q }}</h1>
|
2018-02-16 01:35:15 -07:00
|
|
|
</header>
|
|
|
|
<div :class="$style.loading" v-if="fetching">
|
|
|
|
<mk-ellipsis-icon/>
|
|
|
|
</div>
|
2018-02-25 08:39:05 -07:00
|
|
|
<p :class="$style.empty" v-if="!fetching && empty">%fa:search%「{{ q }}」に関する投稿は見つかりませんでした。</p>
|
2018-04-07 11:30:37 -06:00
|
|
|
<mk-notes ref="timeline" :class="$style.notes" :notes="notes">
|
2018-02-16 01:35:15 -07:00
|
|
|
<div slot="footer">
|
|
|
|
<template v-if="!moreFetching">%fa:search%</template>
|
|
|
|
<template v-if="moreFetching">%fa:spinner .pulse .fw%</template>
|
|
|
|
</div>
|
2018-04-07 11:30:37 -06:00
|
|
|
</mk-notes>
|
2018-02-16 01:35:15 -07:00
|
|
|
</mk-ui>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
|
|
|
import Progress from '../../../common/scripts/loading';
|
|
|
|
import parse from '../../../common/scripts/parse-search-query';
|
|
|
|
|
2018-02-25 08:39:05 -07:00
|
|
|
const limit = 20;
|
2018-02-16 01:35:15 -07:00
|
|
|
|
|
|
|
export default Vue.extend({
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
fetching: true,
|
|
|
|
moreFetching: false,
|
2018-02-25 08:39:05 -07:00
|
|
|
existMore: false,
|
2018-02-16 01:35:15 -07:00
|
|
|
offset: 0,
|
2018-04-07 11:30:37 -06:00
|
|
|
notes: []
|
2018-02-16 01:35:15 -07:00
|
|
|
};
|
|
|
|
},
|
2018-02-25 08:39:05 -07:00
|
|
|
watch: {
|
|
|
|
$route: 'fetch'
|
|
|
|
},
|
2018-02-16 01:35:15 -07:00
|
|
|
computed: {
|
|
|
|
empty(): boolean {
|
2018-04-07 11:30:37 -06:00
|
|
|
return this.notes.length == 0;
|
2018-02-25 08:39:05 -07:00
|
|
|
},
|
|
|
|
q(): string {
|
|
|
|
return this.$route.query.q;
|
2018-02-16 01:35:15 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
document.addEventListener('keydown', this.onDocumentKeydown);
|
|
|
|
window.addEventListener('scroll', this.onScroll);
|
|
|
|
|
2018-02-25 08:39:05 -07:00
|
|
|
this.fetch();
|
2018-02-16 01:35:15 -07:00
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
document.removeEventListener('keydown', this.onDocumentKeydown);
|
|
|
|
window.removeEventListener('scroll', this.onScroll);
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onDocumentKeydown(e) {
|
|
|
|
if (e.target.tagName != 'INPUT' && e.target.tagName != 'TEXTAREA') {
|
|
|
|
if (e.which == 84) { // t
|
|
|
|
(this.$refs.timeline as any).focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2018-02-25 08:39:05 -07:00
|
|
|
fetch() {
|
|
|
|
this.fetching = true;
|
|
|
|
Progress.start();
|
|
|
|
|
2018-04-07 11:30:37 -06:00
|
|
|
(this as any).api('notes/search', Object.assign({
|
2018-02-25 08:39:05 -07:00
|
|
|
limit: limit + 1,
|
|
|
|
offset: this.offset
|
2018-04-07 11:30:37 -06:00
|
|
|
}, parse(this.q))).then(notes => {
|
|
|
|
if (notes.length == limit + 1) {
|
|
|
|
notes.pop();
|
2018-02-25 08:39:05 -07:00
|
|
|
this.existMore = true;
|
|
|
|
}
|
2018-04-07 11:30:37 -06:00
|
|
|
this.notes = notes;
|
2018-02-25 08:39:05 -07:00
|
|
|
this.fetching = false;
|
|
|
|
Progress.done();
|
|
|
|
});
|
|
|
|
},
|
2018-02-16 01:35:15 -07:00
|
|
|
more() {
|
2018-04-07 11:30:37 -06:00
|
|
|
if (this.moreFetching || this.fetching || this.notes.length == 0 || !this.existMore) return;
|
2018-02-16 01:35:15 -07:00
|
|
|
this.offset += limit;
|
|
|
|
this.moreFetching = true;
|
2018-04-07 11:30:37 -06:00
|
|
|
return (this as any).api('notes/search', Object.assign({
|
2018-02-25 08:39:05 -07:00
|
|
|
limit: limit + 1,
|
2018-02-16 01:35:15 -07:00
|
|
|
offset: this.offset
|
2018-04-07 11:30:37 -06:00
|
|
|
}, parse(this.q))).then(notes => {
|
|
|
|
if (notes.length == limit + 1) {
|
|
|
|
notes.pop();
|
2018-02-25 08:39:05 -07:00
|
|
|
} else {
|
|
|
|
this.existMore = false;
|
|
|
|
}
|
2018-04-07 11:30:37 -06:00
|
|
|
this.notes = this.notes.concat(notes);
|
2018-02-25 08:39:05 -07:00
|
|
|
this.moreFetching = false;
|
2018-02-16 01:35:15 -07:00
|
|
|
});
|
|
|
|
},
|
|
|
|
onScroll() {
|
|
|
|
const current = window.scrollY + window.innerHeight;
|
|
|
|
if (current > document.body.offsetHeight - 16) this.more();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus" module>
|
|
|
|
.header
|
|
|
|
width 100%
|
|
|
|
max-width 600px
|
|
|
|
margin 0 auto
|
|
|
|
color #555
|
|
|
|
|
2018-04-07 11:30:37 -06:00
|
|
|
.notes
|
2018-02-16 01:35:15 -07:00
|
|
|
max-width 600px
|
|
|
|
margin 0 auto
|
2018-04-28 17:51:17 -06:00
|
|
|
border solid 1px rgba(#000, 0.075)
|
2018-02-16 01:35:15 -07:00
|
|
|
border-radius 6px
|
|
|
|
overflow hidden
|
|
|
|
|
|
|
|
.loading
|
|
|
|
padding 64px 0
|
|
|
|
|
|
|
|
.empty
|
|
|
|
display block
|
|
|
|
margin 0 auto
|
|
|
|
padding 32px
|
|
|
|
max-width 400px
|
|
|
|
text-align center
|
|
|
|
color #999
|
|
|
|
|
|
|
|
> [data-fa]
|
|
|
|
display block
|
|
|
|
margin-bottom 16px
|
|
|
|
font-size 3em
|
|
|
|
color #ccc
|
|
|
|
|
|
|
|
</style>
|