monkeeShark/src/client/app/desktop/views/deck/deck.favorites-column.vue

89 lines
1.5 KiB
Vue
Raw Normal View History

2018-09-16 14:15:02 +00:00
<template>
<x-column>
<span slot="header">
<fa :icon="['fa', 'star']"/>{{ $t('favorites') }}
</span>
<div>
<x-notes ref="timeline" :more="existMore ? more : null"/>
</div>
</x-column>
2018-09-16 14:15:02 +00:00
</template>
<script lang="ts">
import Vue from 'vue';
import i18n from '../../../i18n';
import XColumn from './deck.column.vue';
2018-09-16 14:15:02 +00:00
import XNotes from './deck.notes.vue';
const fetchLimit = 10;
export default Vue.extend({
i18n: i18n(),
2018-09-16 14:15:02 +00:00
components: {
XColumn,
XNotes,
2018-09-16 14:15:02 +00:00
},
data() {
return {
fetching: true,
moreFetching: false,
existMore: false,
};
},
mounted() {
this.fetch();
},
methods: {
fetch() {
this.fetching = true;
(this.$refs.timeline as any).init(() => new Promise((res, rej) => {
this.$root.api('i/favorites', {
2018-09-16 14:15:02 +00:00
limit: fetchLimit + 1,
}).then(notes => {
if (notes.length == fetchLimit + 1) {
notes.pop();
this.existMore = true;
}
res(notes.map(x => x.note));
2018-09-16 14:15:02 +00:00
this.fetching = false;
this.$emit('loaded');
}, rej);
}));
},
2018-09-16 14:15:02 +00:00
more() {
this.moreFetching = true;
const promise = this.$root.api('i/favorites', {
2018-09-16 14:15:02 +00:00
limit: fetchLimit + 1,
untilId: (this.$refs.timeline as any).tail().id,
});
promise.then(notes => {
if (notes.length == fetchLimit + 1) {
notes.pop();
} else {
this.existMore = false;
}
for (const n of notes) {
(this.$refs.timeline as any).append(n);
}
2018-09-16 14:15:02 +00:00
this.moreFetching = false;
});
return promise;
},
focus() {
this.$refs.timeline.focus();
2018-10-21 07:18:02 +00:00
}
2018-09-16 14:15:02 +00:00
}
});
</script>