2018-02-16 20:53:15 +09:00
|
|
|
<template>
|
|
|
|
<div class="mk-user-timeline">
|
2018-04-26 11:46:42 +09:00
|
|
|
<mk-notes ref="timeline" :more="existMore ? more : null">
|
|
|
|
<div slot="empty">
|
2018-11-06 01:40:11 +09:00
|
|
|
<fa :icon="['far', 'comments']"/>
|
2018-11-09 03:44:35 +09:00
|
|
|
{{ withMedia ? this.$t('no-notes-with-media') : this.$t('no-notes') }}
|
2018-02-16 20:53:15 +09:00
|
|
|
</div>
|
2018-04-08 02:30:37 +09:00
|
|
|
</mk-notes>
|
2018-02-16 20:53:15 +09:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
2018-11-09 03:44:35 +09:00
|
|
|
import i18n from '../../../i18n';
|
2018-02-23 08:07:30 +09:00
|
|
|
|
2018-04-26 11:46:42 +09:00
|
|
|
const fetchLimit = 10;
|
2018-02-23 08:07:30 +09:00
|
|
|
|
2018-02-16 20:53:15 +09:00
|
|
|
export default Vue.extend({
|
2018-11-09 03:44:35 +09:00
|
|
|
i18n: i18n('mobile/views/components/user-timeline.vue'),
|
2018-02-16 20:53:15 +09:00
|
|
|
props: ['user', 'withMedia'],
|
2018-05-03 23:32:46 +09:00
|
|
|
|
2018-02-16 20:53:15 +09:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
fetching: true,
|
2018-02-23 08:07:30 +09:00
|
|
|
existMore: false,
|
|
|
|
moreFetching: false
|
2018-02-16 20:53:15 +09:00
|
|
|
};
|
|
|
|
},
|
2018-05-03 23:32:46 +09:00
|
|
|
|
|
|
|
computed: {
|
|
|
|
canFetchMore(): boolean {
|
|
|
|
return !this.moreFetching && !this.fetching && this.existMore;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-02-16 20:53:15 +09:00
|
|
|
mounted() {
|
2018-04-26 11:46:42 +09:00
|
|
|
this.fetch();
|
2018-02-23 08:07:30 +09:00
|
|
|
},
|
2018-05-03 23:32:46 +09:00
|
|
|
|
2018-02-23 08:07:30 +09:00
|
|
|
methods: {
|
2018-04-26 11:46:42 +09:00
|
|
|
fetch() {
|
|
|
|
this.fetching = true;
|
|
|
|
(this.$refs.timeline as any).init(() => new Promise((res, rej) => {
|
2018-11-09 08:13:34 +09:00
|
|
|
this.$root.api('users/notes', {
|
2018-04-26 11:46:42 +09:00
|
|
|
userId: this.user.id,
|
2018-09-05 19:32:46 +09:00
|
|
|
withFiles: this.withMedia,
|
2018-11-13 01:17:59 +09:00
|
|
|
limit: fetchLimit + 1,
|
|
|
|
untilDate: new Date().getTime() + 1000 * 86400 * 365
|
2018-04-26 11:46:42 +09:00
|
|
|
}).then(notes => {
|
|
|
|
if (notes.length == fetchLimit + 1) {
|
|
|
|
notes.pop();
|
|
|
|
this.existMore = true;
|
|
|
|
}
|
|
|
|
res(notes);
|
|
|
|
this.fetching = false;
|
|
|
|
this.$emit('loaded');
|
|
|
|
}, rej);
|
|
|
|
}));
|
|
|
|
},
|
2018-05-03 23:32:46 +09:00
|
|
|
|
2018-02-23 08:07:30 +09:00
|
|
|
more() {
|
2018-05-03 23:32:46 +09:00
|
|
|
if (!this.canFetchMore) return;
|
|
|
|
|
2018-02-23 08:07:30 +09:00
|
|
|
this.moreFetching = true;
|
2018-05-26 23:53:22 +09:00
|
|
|
|
2018-11-09 08:13:34 +09:00
|
|
|
const promise = this.$root.api('users/notes', {
|
2018-03-29 14:48:47 +09:00
|
|
|
userId: this.user.id,
|
2018-09-05 19:32:46 +09:00
|
|
|
withFiles: this.withMedia,
|
2018-04-26 11:46:42 +09:00
|
|
|
limit: fetchLimit + 1,
|
2018-11-13 01:17:59 +09:00
|
|
|
untilDate: new Date((this.$refs.timeline as any).tail().createdAt).getTime()
|
2018-05-26 23:53:22 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
promise.then(notes => {
|
2018-04-26 11:46:42 +09:00
|
|
|
if (notes.length == fetchLimit + 1) {
|
2018-04-08 02:30:37 +09:00
|
|
|
notes.pop();
|
2018-02-23 08:07:30 +09:00
|
|
|
} else {
|
|
|
|
this.existMore = false;
|
|
|
|
}
|
2018-12-11 20:36:55 +09:00
|
|
|
for (const n of notes) {
|
|
|
|
(this.$refs.timeline as any).append(n);
|
|
|
|
}
|
2018-02-23 08:07:30 +09:00
|
|
|
this.moreFetching = false;
|
|
|
|
});
|
2018-05-26 23:53:22 +09:00
|
|
|
|
|
|
|
return promise;
|
2018-02-23 08:07:30 +09:00
|
|
|
}
|
2018-02-16 20:53:15 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|