misskey/src/client/app/mobile/views/components/user-timeline.vue

77 lines
1.7 KiB
Vue
Raw Normal View History

2018-02-16 12:53:15 +01:00
<template>
<div class="mk-user-timeline">
<mk-posts :posts="posts">
<div class="init" v-if="fetching">
%fa:spinner .pulse%%i18n:common.loading%
</div>
<div class="empty" v-if="!fetching && posts.length == 0">
%fa:R comments%
{{ withMedia ? '%i18n:mobile.tags.mk-user-timeline.no-posts-with-media%' : '%i18n:mobile.tags.mk-user-timeline.no-posts%' }}
</div>
2018-02-23 00:07:30 +01:00
<button v-if="!fetching && existMore" @click="more" :disabled="moreFetching" slot="tail">
<span v-if="!moreFetching">%i18n:mobile.tags.mk-user-timeline.load-more%</span>
<span v-if="moreFetching">%i18n:common.loading%<mk-ellipsis/></span>
2018-02-16 12:53:15 +01:00
</button>
</mk-posts>
</div>
</template>
<script lang="ts">
import Vue from 'vue';
2018-02-23 00:07:30 +01:00
const limit = 10;
2018-02-16 12:53:15 +01:00
export default Vue.extend({
props: ['user', 'withMedia'],
data() {
return {
fetching: true,
2018-02-23 00:07:30 +01:00
posts: [],
existMore: false,
moreFetching: false
2018-02-16 12:53:15 +01:00
};
},
mounted() {
2018-02-18 04:35:18 +01:00
(this as any).api('users/posts', {
2018-03-29 07:48:47 +02:00
userId: this.user.id,
withMedia: this.withMedia,
2018-02-23 00:07:30 +01:00
limit: limit + 1
2018-02-16 12:53:15 +01:00
}).then(posts => {
2018-02-23 00:07:30 +01:00
if (posts.length == limit + 1) {
posts.pop();
this.existMore = true;
}
2018-02-16 12:53:15 +01:00
this.posts = posts;
2018-02-19 15:37:09 +01:00
this.fetching = false;
2018-02-16 12:53:15 +01:00
this.$emit('loaded');
});
2018-02-23 00:07:30 +01:00
},
methods: {
more() {
this.moreFetching = true;
(this as any).api('users/posts', {
2018-03-29 07:48:47 +02:00
userId: this.user.id,
withMedia: this.withMedia,
2018-02-23 00:07:30 +01:00
limit: limit + 1,
2018-03-29 07:48:47 +02:00
untilId: this.posts[this.posts.length - 1].id
2018-02-23 00:07:30 +01:00
}).then(posts => {
if (posts.length == limit + 1) {
posts.pop();
this.existMore = true;
} else {
this.existMore = false;
}
this.posts = this.posts.concat(posts);
this.moreFetching = false;
});
}
2018-02-16 12:53:15 +01:00
}
});
</script>
<style lang="stylus" scoped>
.mk-user-timeline
max-width 600px
margin 0 auto
</style>