Sharkey/src/client/app/desktop/views/pages/user/user.timeline.vue

155 lines
3 KiB
Vue
Raw Normal View History

2018-02-16 10:17:05 +02:00
<template>
2018-02-20 18:39:51 +02:00
<div class="timeline">
2018-02-16 10:17:05 +02:00
<header>
<span :data-active="mode == 'default'" @click="mode = 'default'">%i18n:@default%</span>
<span :data-active="mode == 'with-replies'" @click="mode = 'with-replies'">%i18n:@with-replies%</span>
<span :data-active="mode == 'with-media'" @click="mode = 'with-media'">%i18n:@with-media%</span>
2018-02-16 10:17:05 +02:00
</header>
<div class="loading" v-if="fetching">
<mk-ellipsis-icon/>
</div>
2018-04-26 05:19:57 +03:00
<mk-notes ref="timeline" :more="existMore ? more : null">
<p class="empty" slot="empty">%fa:R comments%%i18n:@empty%</p>
2018-04-07 20:30:37 +03:00
</mk-notes>
2018-02-16 10:17:05 +02:00
</div>
</template>
<script lang="ts">
import Vue from 'vue';
2018-04-26 05:19:57 +03:00
const fetchLimit = 10;
2018-02-16 10:17:05 +02:00
export default Vue.extend({
props: ['user'],
2018-05-26 17:53:22 +03:00
2018-02-16 10:17:05 +02:00
data() {
return {
fetching: true,
moreFetching: false,
2018-04-26 05:19:57 +03:00
existMore: false,
2018-02-16 10:17:05 +02:00
mode: 'default',
unreadCount: 0,
date: null
};
},
2018-05-26 17:53:22 +03:00
2018-04-16 09:13:31 +03:00
watch: {
mode() {
this.fetch();
}
},
2018-05-26 17:53:22 +03:00
2018-02-16 10:17:05 +02:00
mounted() {
document.addEventListener('keydown', this.onDocumentKeydown);
this.fetch(() => this.$emit('loaded'));
},
2018-05-26 17:53:22 +03:00
2018-02-16 10:17:05 +02:00
beforeDestroy() {
document.removeEventListener('keydown', this.onDocumentKeydown);
},
2018-05-26 17:53:22 +03:00
2018-02-16 10:17:05 +02:00
methods: {
onDocumentKeydown(e) {
if (e.target.tagName !== 'INPUT' && e.target.tagName !== 'TEXTAREA') {
if (e.which == 84) { // [t]
(this.$refs.timeline as any).focus();
}
}
},
2018-05-26 17:53:22 +03:00
2018-02-16 10:17:05 +02:00
fetch(cb?) {
2018-04-26 05:19:57 +03:00
this.fetching = true;
(this.$refs.timeline as any).init(() => new Promise((res, rej) => {
(this as any).api('users/notes', {
userId: this.user.id,
limit: fetchLimit + 1,
untilDate: this.date ? this.date.getTime() : undefined,
includeReplies: this.mode == 'with-replies',
withMedia: this.mode == 'with-media'
}).then(notes => {
if (notes.length == fetchLimit + 1) {
notes.pop();
this.existMore = true;
}
res(notes);
this.fetching = false;
if (cb) cb();
}, rej);
}));
2018-02-16 10:17:05 +02:00
},
2018-05-26 17:53:22 +03:00
2018-02-16 10:17:05 +02:00
more() {
this.moreFetching = true;
2018-05-26 17:53:22 +03:00
const promise = (this as any).api('users/notes', {
2018-03-29 08:48:47 +03:00
userId: this.user.id,
2018-04-26 05:19:57 +03:00
limit: fetchLimit + 1,
2018-04-16 09:13:31 +03:00
includeReplies: this.mode == 'with-replies',
withMedia: this.mode == 'with-media',
2018-04-26 05:19:57 +03:00
untilId: (this.$refs.timeline as any).tail().id
2018-05-26 17:53:22 +03:00
});
promise.then(notes => {
2018-04-26 05:19:57 +03:00
if (notes.length == fetchLimit + 1) {
notes.pop();
} else {
this.existMore = false;
}
notes.forEach(n => (this.$refs.timeline as any).append(n));
2018-02-16 10:17:05 +02:00
this.moreFetching = false;
});
2018-05-26 17:53:22 +03:00
return promise;
2018-02-16 10:17:05 +02:00
},
2018-05-26 17:53:22 +03:00
2018-02-22 14:39:36 +02:00
warp(date) {
this.date = date;
this.fetch();
2018-02-16 10:17:05 +02:00
}
}
});
</script>
<style lang="stylus" scoped>
2018-03-03 06:47:55 +02:00
@import '~const.styl'
2018-02-20 18:39:51 +02:00
.timeline
2018-02-16 10:17:05 +02:00
background #fff
> header
padding 8px 16px
border-bottom solid 1px #eee
> span
margin-right 16px
line-height 27px
font-size 18px
color #555
2018-04-26 08:38:37 +03:00
&:not([data-active])
2018-02-16 10:17:05 +02:00
color $theme-color
cursor pointer
&:hover
text-decoration underline
> .loading
padding 64px 0
> .empty
display block
margin 0 auto
padding 32px
max-width 400px
text-align center
color #999
> [data-fa]
display block
margin-bottom 16px
font-size 3em
color #ccc
</style>