summaryrefslogtreecommitdiff
path: root/src/client/app/mobile/views/components/user-timeline.vue
blob: bd3e3d0c8749ca06aa924b2e78daee573c67ba52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<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>
		<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>
		</button>
	</mk-posts>
</div>
</template>

<script lang="ts">
import Vue from 'vue';

const limit = 10;

export default Vue.extend({
	props: ['user', 'withMedia'],
	data() {
		return {
			fetching: true,
			posts: [],
			existMore: false,
			moreFetching: false
		};
	},
	mounted() {
		(this as any).api('users/posts', {
			userId: this.user.id,
			withMedia: this.withMedia,
			limit: limit + 1
		}).then(posts => {
			if (posts.length == limit + 1) {
				posts.pop();
				this.existMore = true;
			}
			this.posts = posts;
			this.fetching = false;
			this.$emit('loaded');
		});
	},
	methods: {
		more() {
			this.moreFetching = true;
			(this as any).api('users/posts', {
				userId: this.user.id,
				withMedia: this.withMedia,
				limit: limit + 1,
				untilId: this.posts[this.posts.length - 1].id
			}).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;
			});
		}
	}
});
</script>

<style lang="stylus" scoped>
.mk-user-timeline
	max-width 600px
	margin 0 auto
</style>