2018-02-16 18:19:16 -06:00
|
|
|
<template>
|
|
|
|
<mk-ui>
|
2018-11-05 10:40:11 -06:00
|
|
|
<span slot="header"><fa icon="search"/> {{ q }}</span>
|
2018-07-04 07:23:50 -05:00
|
|
|
|
|
|
|
<main>
|
2018-11-08 12:44:35 -06:00
|
|
|
<p :class="$style.empty" v-if="!fetching && empty"><fa icon="search"/> {{ $t('not-found', { q }) }}</p>
|
2018-07-04 07:23:50 -05:00
|
|
|
<mk-notes ref="timeline" :more="existMore ? more : null"/>
|
2018-02-16 18:19:16 -06:00
|
|
|
</main>
|
|
|
|
</mk-ui>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
2018-11-08 12:44:35 -06:00
|
|
|
import i18n from '../../../i18n';
|
2018-02-16 18:19:16 -06:00
|
|
|
import Progress from '../../../common/scripts/loading';
|
|
|
|
|
2018-02-25 09:39:05 -06:00
|
|
|
const limit = 20;
|
2018-02-16 18:19:16 -06:00
|
|
|
|
|
|
|
export default Vue.extend({
|
2018-11-08 12:44:35 -06:00
|
|
|
i18n: i18n('mobile/views/pages/search.vue'),
|
2018-02-16 18:19:16 -06:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
fetching: true,
|
2018-07-04 07:23:50 -05:00
|
|
|
moreFetching: false,
|
2018-02-25 09:39:05 -06:00
|
|
|
existMore: false,
|
2018-07-04 07:23:50 -05:00
|
|
|
empty: false,
|
2018-02-16 18:19:16 -06:00
|
|
|
offset: 0
|
|
|
|
};
|
|
|
|
},
|
2018-02-25 09:39:05 -06:00
|
|
|
watch: {
|
|
|
|
$route: 'fetch'
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
q(): string {
|
|
|
|
return this.$route.query.q;
|
|
|
|
}
|
|
|
|
},
|
2018-02-16 18:19:16 -06:00
|
|
|
mounted() {
|
2018-11-08 17:26:32 -06:00
|
|
|
document.title = `%i18n:@search%: ${this.q} | ${this.$root.instanceName}`;
|
2018-02-16 18:19:16 -06:00
|
|
|
|
2018-02-25 09:39:05 -06:00
|
|
|
this.fetch();
|
2018-02-16 18:19:16 -06:00
|
|
|
},
|
|
|
|
methods: {
|
2018-02-25 09:39:05 -06:00
|
|
|
fetch() {
|
|
|
|
this.fetching = true;
|
|
|
|
Progress.start();
|
|
|
|
|
2018-07-04 07:23:50 -05:00
|
|
|
(this.$refs.timeline as any).init(() => new Promise((res, rej) => {
|
2018-11-08 17:13:34 -06:00
|
|
|
this.$root.api('notes/search', {
|
2018-07-04 07:23:50 -05:00
|
|
|
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();
|
|
|
|
}, rej);
|
|
|
|
}));
|
2018-02-25 09:39:05 -06:00
|
|
|
},
|
2018-02-16 18:19:16 -06:00
|
|
|
more() {
|
|
|
|
this.offset += limit;
|
2018-07-04 07:23:50 -05:00
|
|
|
|
2018-11-08 17:13:34 -06:00
|
|
|
const promise = this.$root.api('notes/search', {
|
2018-02-25 09:39:05 -06:00
|
|
|
limit: limit + 1,
|
2018-07-04 06:44:13 -05:00
|
|
|
offset: this.offset,
|
|
|
|
query: this.q
|
2018-07-04 07:23:50 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
promise.then(notes => {
|
2018-04-07 12:30:37 -05:00
|
|
|
if (notes.length == limit + 1) {
|
|
|
|
notes.pop();
|
2018-02-25 09:39:05 -06:00
|
|
|
} else {
|
|
|
|
this.existMore = false;
|
|
|
|
}
|
2018-07-04 07:23:50 -05:00
|
|
|
notes.forEach(n => (this.$refs.timeline as any).append(n));
|
|
|
|
this.moreFetching = false;
|
2018-02-25 09:39:05 -06:00
|
|
|
});
|
2018-07-04 07:23:50 -05:00
|
|
|
|
|
|
|
return promise;
|
2018-02-16 18:19:16 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus" module>
|
2018-04-07 12:30:37 -05:00
|
|
|
.notes
|
2018-02-16 18:19:16 -06:00
|
|
|
margin 8px auto
|
|
|
|
max-width 500px
|
|
|
|
width calc(100% - 16px)
|
|
|
|
background #fff
|
|
|
|
border-radius 8px
|
2018-04-28 18:51:17 -05:00
|
|
|
box-shadow 0 0 0 1px rgba(#000, 0.2)
|
2018-02-16 18:19:16 -06:00
|
|
|
|
|
|
|
@media (min-width 500px)
|
|
|
|
margin 16px auto
|
|
|
|
width calc(100% - 32px)
|
|
|
|
</style>
|