2018-02-16 12:53:15 +01:00
|
|
|
<template>
|
|
|
|
<div class="mk-user-timeline">
|
2018-04-26 04:46:42 +02:00
|
|
|
<mk-notes ref="timeline" :more="existMore ? more : null">
|
|
|
|
<div slot="empty">
|
2018-11-05 17:40:11 +01:00
|
|
|
<fa :icon="['far', 'comments']"/>
|
2018-05-20 13:26:38 +02:00
|
|
|
{{ withMedia ? '%i18n:@no-notes-with-media%' : '%i18n:@no-notes%' }}
|
2018-02-16 12:53:15 +01:00
|
|
|
</div>
|
2018-04-07 19:30:37 +02:00
|
|
|
</mk-notes>
|
2018-02-16 12:53:15 +01:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
2018-02-23 00:07:30 +01:00
|
|
|
|
2018-04-26 04:46:42 +02:00
|
|
|
const fetchLimit = 10;
|
2018-02-23 00:07:30 +01:00
|
|
|
|
2018-02-16 12:53:15 +01:00
|
|
|
export default Vue.extend({
|
|
|
|
props: ['user', 'withMedia'],
|
2018-05-03 16:32:46 +02:00
|
|
|
|
2018-02-16 12:53:15 +01:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
fetching: true,
|
2018-02-23 00:07:30 +01:00
|
|
|
existMore: false,
|
|
|
|
moreFetching: false
|
2018-02-16 12:53:15 +01:00
|
|
|
};
|
|
|
|
},
|
2018-05-03 16:32:46 +02:00
|
|
|
|
|
|
|
computed: {
|
|
|
|
canFetchMore(): boolean {
|
|
|
|
return !this.moreFetching && !this.fetching && this.existMore;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-02-16 12:53:15 +01:00
|
|
|
mounted() {
|
2018-04-26 04:46:42 +02:00
|
|
|
this.fetch();
|
2018-02-23 00:07:30 +01:00
|
|
|
},
|
2018-05-03 16:32:46 +02:00
|
|
|
|
2018-02-23 00:07:30 +01:00
|
|
|
methods: {
|
2018-04-26 04:46:42 +02: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,
|
2018-09-05 12:32:46 +02:00
|
|
|
withFiles: this.withMedia,
|
2018-04-26 04:46:42 +02:00
|
|
|
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-05-03 16:32:46 +02:00
|
|
|
|
2018-02-23 00:07:30 +01:00
|
|
|
more() {
|
2018-05-03 16:32:46 +02:00
|
|
|
if (!this.canFetchMore) return;
|
|
|
|
|
2018-02-23 00:07:30 +01:00
|
|
|
this.moreFetching = true;
|
2018-05-26 16:53:22 +02:00
|
|
|
|
|
|
|
const promise = (this as any).api('users/notes', {
|
2018-03-29 07:48:47 +02:00
|
|
|
userId: this.user.id,
|
2018-09-05 12:32:46 +02:00
|
|
|
withFiles: this.withMedia,
|
2018-04-26 04:46:42 +02:00
|
|
|
limit: fetchLimit + 1,
|
|
|
|
untilId: (this.$refs.timeline as any).tail().id
|
2018-05-26 16:53:22 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
promise.then(notes => {
|
2018-04-26 04:46:42 +02:00
|
|
|
if (notes.length == fetchLimit + 1) {
|
2018-04-07 19:30:37 +02:00
|
|
|
notes.pop();
|
2018-02-23 00:07:30 +01:00
|
|
|
} else {
|
|
|
|
this.existMore = false;
|
|
|
|
}
|
2018-04-26 04:46:42 +02:00
|
|
|
notes.forEach(n => (this.$refs.timeline as any).append(n));
|
2018-02-23 00:07:30 +01:00
|
|
|
this.moreFetching = false;
|
|
|
|
});
|
2018-05-26 16:53:22 +02:00
|
|
|
|
|
|
|
return promise;
|
2018-02-23 00:07:30 +01:00
|
|
|
}
|
2018-02-16 12:53:15 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|