2018-02-17 01:19:16 +01:00
|
|
|
<template>
|
|
|
|
<mk-ui>
|
2018-02-25 16:39:05 +01:00
|
|
|
<span slot="header">%fa:search% {{ q }}</span>
|
2018-02-17 01:19:16 +01:00
|
|
|
<main v-if="!fetching">
|
2018-02-17 01:19:37 +01:00
|
|
|
<mk-posts :class="$style.posts" :posts="posts">
|
2018-02-25 16:39:05 +01:00
|
|
|
<span v-if="posts.length == 0">{{ '%i18n:mobile.tags.mk-search-posts.empty%'.replace('{}', q) }}</span>
|
|
|
|
<button v-if="existMore" @click="more" :disabled="fetching" slot="tail">
|
2018-02-17 01:19:16 +01:00
|
|
|
<span v-if="!fetching">%i18n:mobile.tags.mk-timeline.load-more%</span>
|
|
|
|
<span v-if="fetching">%i18n:common.loading%<mk-ellipsis/></span>
|
|
|
|
</button>
|
|
|
|
</mk-posts>
|
|
|
|
</main>
|
|
|
|
</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 16:39:05 +01:00
|
|
|
const limit = 20;
|
2018-02-17 01:19:16 +01:00
|
|
|
|
|
|
|
export default Vue.extend({
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
fetching: true,
|
2018-02-25 16:39:05 +01:00
|
|
|
existMore: false,
|
2018-02-17 01:19:16 +01:00
|
|
|
posts: [],
|
|
|
|
offset: 0
|
|
|
|
};
|
|
|
|
},
|
2018-02-25 16:39:05 +01:00
|
|
|
watch: {
|
|
|
|
$route: 'fetch'
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
q(): string {
|
|
|
|
return this.$route.query.q;
|
|
|
|
}
|
|
|
|
},
|
2018-02-17 01:19:16 +01:00
|
|
|
mounted() {
|
2018-02-25 16:39:05 +01:00
|
|
|
document.title = `%i18n:mobile.tags.mk-search-page.search%: ${this.q} | Misskey`;
|
2018-02-17 01:19:16 +01:00
|
|
|
document.documentElement.style.background = '#313a42';
|
|
|
|
|
2018-02-25 16:39:05 +01:00
|
|
|
this.fetch();
|
2018-02-17 01:19:16 +01:00
|
|
|
},
|
|
|
|
methods: {
|
2018-02-25 16:39:05 +01:00
|
|
|
fetch() {
|
|
|
|
this.fetching = true;
|
|
|
|
Progress.start();
|
|
|
|
|
|
|
|
(this as any).api('posts/search', Object.assign({
|
|
|
|
limit: limit + 1
|
|
|
|
}, parse(this.q))).then(posts => {
|
|
|
|
if (posts.length == limit + 1) {
|
|
|
|
posts.pop();
|
|
|
|
this.existMore = true;
|
|
|
|
}
|
|
|
|
this.posts = posts;
|
|
|
|
this.fetching = false;
|
|
|
|
Progress.done();
|
|
|
|
});
|
|
|
|
},
|
2018-02-17 01:19:16 +01:00
|
|
|
more() {
|
|
|
|
this.offset += limit;
|
2018-02-25 16:39:05 +01:00
|
|
|
(this as any).api('posts/search', Object.assign({
|
|
|
|
limit: limit + 1,
|
2018-02-17 01:19:16 +01:00
|
|
|
offset: this.offset
|
2018-02-25 16:39:05 +01:00
|
|
|
}, parse(this.q))).then(posts => {
|
|
|
|
if (posts.length == limit + 1) {
|
|
|
|
posts.pop();
|
|
|
|
} else {
|
|
|
|
this.existMore = false;
|
|
|
|
}
|
|
|
|
this.posts = this.posts.concat(posts);
|
|
|
|
});
|
2018-02-17 01:19:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus" module>
|
|
|
|
.posts
|
|
|
|
margin 8px auto
|
|
|
|
max-width 500px
|
|
|
|
width calc(100% - 16px)
|
|
|
|
background #fff
|
|
|
|
border-radius 8px
|
|
|
|
box-shadow 0 0 0 1px rgba(0, 0, 0, 0.2)
|
|
|
|
|
|
|
|
@media (min-width 500px)
|
|
|
|
margin 16px auto
|
|
|
|
width calc(100% - 32px)
|
|
|
|
</style>
|