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

68 lines
1.4 KiB
Vue
Raw Normal View History

2018-02-16 05:53:15 -06:00
<template>
<div class="mk-user-timeline">
2018-04-25 21:46:42 -05:00
<mk-notes ref="timeline" :more="existMore ? more : null">
<div slot="empty">
2018-02-16 05:53:15 -06:00
%fa:R comments%
2018-04-15 17:07:32 -05:00
{{ withMedia ? '%i18n:!@no-notes-with-media%' : '%i18n:!@no-notes%' }}
2018-02-16 05:53:15 -06:00
</div>
2018-04-07 12:30:37 -05:00
</mk-notes>
2018-02-16 05:53:15 -06:00
</div>
</template>
<script lang="ts">
import Vue from 'vue';
2018-02-22 17:07:30 -06:00
2018-04-25 21:46:42 -05:00
const fetchLimit = 10;
2018-02-22 17:07:30 -06:00
2018-02-16 05:53:15 -06:00
export default Vue.extend({
props: ['user', 'withMedia'],
data() {
return {
fetching: true,
2018-02-22 17:07:30 -06:00
existMore: false,
moreFetching: false
2018-02-16 05:53:15 -06:00
};
},
mounted() {
2018-04-25 21:46:42 -05:00
this.fetch();
2018-02-22 17:07:30 -06:00
},
methods: {
2018-04-25 21:46:42 -05:00
fetch() {
this.fetching = true;
(this.$refs.timeline as any).init(() => new Promise((res, rej) => {
(this as any).api('users/notes', {
userId: this.user.id,
withMedia: this.withMedia,
limit: fetchLimit + 1
}).then(notes => {
if (notes.length == fetchLimit + 1) {
notes.pop();
this.existMore = true;
}
res(notes);
this.fetching = false;
this.$emit('loaded');
}, rej);
}));
},
2018-02-22 17:07:30 -06:00
more() {
this.moreFetching = true;
2018-04-07 12:30:37 -05:00
(this as any).api('users/notes', {
2018-03-29 00:48:47 -05:00
userId: this.user.id,
withMedia: this.withMedia,
2018-04-25 21:46:42 -05:00
limit: fetchLimit + 1,
untilId: (this.$refs.timeline as any).tail().id
2018-04-07 12:30:37 -05:00
}).then(notes => {
2018-04-25 21:46:42 -05:00
if (notes.length == fetchLimit + 1) {
2018-04-07 12:30:37 -05:00
notes.pop();
2018-02-22 17:07:30 -06:00
} else {
this.existMore = false;
}
2018-04-25 21:46:42 -05:00
notes.forEach(n => (this.$refs.timeline as any).append(n));
2018-02-22 17:07:30 -06:00
this.moreFetching = false;
});
}
2018-02-16 05:53:15 -06:00
}
});
</script>