sharkey/src/client/app/desktop/views/home/search.vue

91 lines
1.8 KiB
Vue
Raw Normal View History

2018-02-16 17:35:15 +09:00
<template>
<div>
<mk-notes ref="timeline" :make-promise="makePromise" @inited="inited">
2019-02-18 11:13:56 +09:00
<template #header>
2019-02-18 09:48:00 +09:00
<header class="oxgbmvii">
<span><fa icon="search"/> {{ q }}</span>
</header>
</template>
</mk-notes>
</div>
2018-02-16 17:35:15 +09:00
</template>
<script lang="ts">
import Vue from 'vue';
import i18n from '../../../i18n';
2018-02-16 17:35:15 +09:00
import Progress from '../../../common/scripts/loading';
2018-02-26 00:39:05 +09:00
const limit = 20;
2018-02-16 17:35:15 +09:00
export default Vue.extend({
i18n: i18n('desktop/views/pages/search.vue'),
2018-02-16 17:35:15 +09:00
data() {
return {
makePromise: cursor => this.$root.api('notes/search', {
limit: limit + 1,
offset: cursor ? cursor : undefined,
query: this.q
}).then(notes => {
if (notes.length == limit + 1) {
notes.pop();
return {
notes: notes,
cursor: cursor ? cursor + limit : limit
};
} else {
return {
notes: notes,
more: false
};
}
})
2018-02-16 17:35:15 +09:00
};
},
computed: {
2018-02-26 00:39:05 +09:00
q(): string {
return this.$route.query.q;
2018-02-16 17:35:15 +09:00
}
},
watch: {
$route() {
this.$refs.timeline.reload();
}
},
2018-02-16 17:35:15 +09:00
mounted() {
document.addEventListener('keydown', this.onDocumentKeydown);
2018-06-07 01:52:03 +09:00
window.addEventListener('scroll', this.onScroll, { passive: true });
Progress.start();
2018-02-16 17:35:15 +09: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();
}
}
},
inited() {
Progress.done();
2018-02-26 00:39:05 +09:00
},
2018-02-16 17:35:15 +09:00
}
});
</script>
<style lang="stylus" scoped>
.oxgbmvii
padding 0 8px
z-index 10
background var(--faceHeader)
box-shadow 0 var(--lineWidth) var(--desktopTimelineHeaderShadow)
2018-02-16 17:35:15 +09:00
> span
padding 0 8px
font-size 0.9em
line-height 42px
color var(--text)
2018-02-16 17:35:15 +09:00
</style>