2018-02-16 08:35:15 +00:00
|
|
|
<template>
|
|
|
|
<mk-ui>
|
|
|
|
<header :class="$style.header">
|
2018-02-25 15:39:05 +00:00
|
|
|
<h1>{{ q }}</h1>
|
2018-02-16 08:35:15 +00:00
|
|
|
</header>
|
|
|
|
<div :class="$style.loading" v-if="fetching">
|
|
|
|
<mk-ellipsis-icon/>
|
|
|
|
</div>
|
2018-08-01 16:20:41 +00:00
|
|
|
<p :class="$style.notAvailable" v-if="!fetching && notAvailable">%i18n:@not-available%</p>
|
2018-08-01 23:04:16 +00:00
|
|
|
<p :class="$style.empty" v-if="!fetching && empty">%fa:search% {{ '%i18n:not-found%'.split('{}')[0] }}{{ q }}{{ '%i18n:not-found%'.split('{}')[1] }}</p>
|
2018-07-04 12:23:50 +00:00
|
|
|
<mk-notes ref="timeline" :class="$style.notes" :more="existMore ? more : null"/>
|
2018-02-16 08:35:15 +00:00
|
|
|
</mk-ui>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
|
|
|
import Progress from '../../../common/scripts/loading';
|
|
|
|
|
2018-02-25 15:39:05 +00:00
|
|
|
const limit = 20;
|
2018-02-16 08:35:15 +00:00
|
|
|
|
|
|
|
export default Vue.extend({
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
fetching: true,
|
|
|
|
moreFetching: false,
|
2018-02-25 15:39:05 +00:00
|
|
|
existMore: false,
|
2018-02-16 08:35:15 +00:00
|
|
|
offset: 0,
|
2018-07-18 23:24:03 +00:00
|
|
|
empty: false,
|
|
|
|
notAvailable: false
|
2018-02-16 08:35:15 +00:00
|
|
|
};
|
|
|
|
},
|
2018-02-25 15:39:05 +00:00
|
|
|
watch: {
|
|
|
|
$route: 'fetch'
|
|
|
|
},
|
2018-02-16 08:35:15 +00:00
|
|
|
computed: {
|
2018-02-25 15:39:05 +00:00
|
|
|
q(): string {
|
|
|
|
return this.$route.query.q;
|
2018-02-16 08:35:15 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
document.addEventListener('keydown', this.onDocumentKeydown);
|
2018-06-06 16:52:03 +00:00
|
|
|
window.addEventListener('scroll', this.onScroll, { passive: true });
|
2018-02-16 08:35:15 +00:00
|
|
|
|
2018-02-25 15:39:05 +00:00
|
|
|
this.fetch();
|
2018-02-16 08:35:15 +00: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 15:39:05 +00:00
|
|
|
fetch() {
|
|
|
|
this.fetching = true;
|
|
|
|
Progress.start();
|
|
|
|
|
2018-07-04 12:23:50 +00:00
|
|
|
(this.$refs.timeline as any).init(() => new Promise((res, rej) => {
|
|
|
|
(this as any).api('notes/search', {
|
|
|
|
limit: limit + 1,
|
|
|
|
offset: this.offset,
|
|
|
|
query: this.q
|
|
|
|
}).then(notes => {
|
|
|
|
if (notes.length == 0) this.empty = true;
|
|
|
|
if (notes.length == limit + 1) {
|
|
|
|
notes.pop();
|
|
|
|
this.existMore = true;
|
|
|
|
}
|
|
|
|
res(notes);
|
|
|
|
this.fetching = false;
|
|
|
|
Progress.done();
|
2018-07-18 23:24:03 +00:00
|
|
|
}, (e: string) => {
|
|
|
|
this.fetching = false;
|
|
|
|
Progress.done();
|
|
|
|
if (e === 'searching not available') this.notAvailable = true;
|
|
|
|
});
|
2018-07-04 12:23:50 +00:00
|
|
|
}));
|
2018-02-25 15:39:05 +00:00
|
|
|
},
|
2018-02-16 08:35:15 +00:00
|
|
|
more() {
|
|
|
|
this.offset += limit;
|
2018-07-04 12:23:50 +00:00
|
|
|
|
|
|
|
const promise = (this as any).api('notes/search', {
|
2018-02-25 15:39:05 +00:00
|
|
|
limit: limit + 1,
|
2018-07-04 11:44:13 +00:00
|
|
|
offset: this.offset,
|
|
|
|
query: this.q
|
2018-07-04 12:23:50 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
promise.then(notes => {
|
2018-04-07 17:30:37 +00:00
|
|
|
if (notes.length == limit + 1) {
|
|
|
|
notes.pop();
|
2018-02-25 15:39:05 +00:00
|
|
|
} else {
|
|
|
|
this.existMore = false;
|
|
|
|
}
|
2018-07-04 12:23:50 +00:00
|
|
|
notes.forEach(n => (this.$refs.timeline as any).append(n));
|
2018-02-25 15:39:05 +00:00
|
|
|
this.moreFetching = false;
|
2018-02-16 08:35:15 +00:00
|
|
|
});
|
2018-07-04 12:23:50 +00:00
|
|
|
|
|
|
|
return promise;
|
2018-02-16 08:35:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus" module>
|
|
|
|
.header
|
|
|
|
width 100%
|
|
|
|
max-width 600px
|
|
|
|
margin 0 auto
|
|
|
|
color #555
|
|
|
|
|
2018-04-07 17:30:37 +00:00
|
|
|
.notes
|
2018-02-16 08:35:15 +00:00
|
|
|
max-width 600px
|
|
|
|
margin 0 auto
|
2018-04-28 23:51:17 +00:00
|
|
|
border solid 1px rgba(#000, 0.075)
|
2018-02-16 08:35:15 +00: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
|
|
|
|
|
2018-07-18 23:24:03 +00:00
|
|
|
|
|
|
|
.notAvailable
|
|
|
|
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
|
2018-02-16 08:35:15 +00:00
|
|
|
</style>
|