2018-02-16 05:53:15 -06:00
|
|
|
<template>
|
|
|
|
<div class="mk-user-timeline">
|
2018-04-07 12:30:37 -05:00
|
|
|
<mk-notes :notes="notes">
|
2018-02-16 05:53:15 -06:00
|
|
|
<div class="init" v-if="fetching">
|
|
|
|
%fa:spinner .pulse%%i18n:common.loading%
|
|
|
|
</div>
|
2018-04-07 12:30:37 -05:00
|
|
|
<div class="empty" v-if="!fetching && notes.length == 0">
|
2018-02-16 05:53:15 -06:00
|
|
|
%fa:R comments%
|
2018-04-14 11:04:40 -05:00
|
|
|
{{ withMedia ? '%i18n:@no-notes-with-media%' : '%i18n:@no-notes%' }}
|
2018-02-16 05:53:15 -06:00
|
|
|
</div>
|
2018-02-22 17:07:30 -06:00
|
|
|
<button v-if="!fetching && existMore" @click="more" :disabled="moreFetching" slot="tail">
|
2018-04-14 11:04:40 -05:00
|
|
|
<span v-if="!moreFetching">%i18n:@load-more%</span>
|
2018-02-22 17:07:30 -06:00
|
|
|
<span v-if="moreFetching">%i18n:common.loading%<mk-ellipsis/></span>
|
2018-02-16 05:53:15 -06:00
|
|
|
</button>
|
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
|
|
|
|
|
|
|
const limit = 10;
|
|
|
|
|
2018-02-16 05:53:15 -06:00
|
|
|
export default Vue.extend({
|
|
|
|
props: ['user', 'withMedia'],
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
fetching: true,
|
2018-04-07 12:30:37 -05:00
|
|
|
notes: [],
|
2018-02-22 17:07:30 -06:00
|
|
|
existMore: false,
|
|
|
|
moreFetching: false
|
2018-02-16 05:53:15 -06:00
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
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-02-22 17:07:30 -06:00
|
|
|
limit: limit + 1
|
2018-04-07 12:30:37 -05:00
|
|
|
}).then(notes => {
|
|
|
|
if (notes.length == limit + 1) {
|
|
|
|
notes.pop();
|
2018-02-22 17:07:30 -06:00
|
|
|
this.existMore = true;
|
|
|
|
}
|
2018-04-07 12:30:37 -05:00
|
|
|
this.notes = notes;
|
2018-02-19 08:37:09 -06:00
|
|
|
this.fetching = false;
|
2018-02-16 05:53:15 -06:00
|
|
|
this.$emit('loaded');
|
|
|
|
});
|
2018-02-22 17:07:30 -06:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
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-02-22 17:07:30 -06:00
|
|
|
limit: limit + 1,
|
2018-04-07 12:30:37 -05:00
|
|
|
untilId: this.notes[this.notes.length - 1].id
|
|
|
|
}).then(notes => {
|
|
|
|
if (notes.length == limit + 1) {
|
|
|
|
notes.pop();
|
2018-02-22 17:07:30 -06:00
|
|
|
this.existMore = true;
|
|
|
|
} else {
|
|
|
|
this.existMore = false;
|
|
|
|
}
|
2018-04-07 12:30:37 -05:00
|
|
|
this.notes = this.notes.concat(notes);
|
2018-02-22 17:07:30 -06:00
|
|
|
this.moreFetching = false;
|
|
|
|
});
|
|
|
|
}
|
2018-02-16 05:53:15 -06:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus" scoped>
|
|
|
|
.mk-user-timeline
|
|
|
|
max-width 600px
|
|
|
|
margin 0 auto
|
|
|
|
</style>
|