2018-02-16 02:17:05 -06:00
|
|
|
<template>
|
2018-02-20 10:39:51 -06:00
|
|
|
<div class="timeline">
|
2018-02-16 02:17:05 -06:00
|
|
|
<header>
|
|
|
|
<span :data-is-active="mode == 'default'" @click="mode = 'default'">投稿</span>
|
|
|
|
<span :data-is-active="mode == 'with-replies'" @click="mode = 'with-replies'">投稿と返信</span>
|
|
|
|
</header>
|
|
|
|
<div class="loading" v-if="fetching">
|
|
|
|
<mk-ellipsis-icon/>
|
|
|
|
</div>
|
|
|
|
<p class="empty" v-if="empty">%fa:R comments%このユーザーはまだ何も投稿していないようです。</p>
|
2018-04-07 12:30:37 -05:00
|
|
|
<mk-notes ref="timeline" :notes="notes">
|
2018-02-16 02:17:05 -06:00
|
|
|
<div slot="footer">
|
|
|
|
<template v-if="!moreFetching">%fa:moon%</template>
|
|
|
|
<template v-if="moreFetching">%fa:spinner .pulse .fw%</template>
|
|
|
|
</div>
|
2018-04-07 12:30:37 -05:00
|
|
|
</mk-notes>
|
2018-02-16 02:17:05 -06:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
|
|
|
export default Vue.extend({
|
|
|
|
props: ['user'],
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
fetching: true,
|
|
|
|
moreFetching: false,
|
|
|
|
mode: 'default',
|
|
|
|
unreadCount: 0,
|
2018-04-07 12:30:37 -05:00
|
|
|
notes: [],
|
2018-02-16 02:17:05 -06:00
|
|
|
date: null
|
|
|
|
};
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
mode() {
|
|
|
|
this.fetch();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
empty(): boolean {
|
2018-04-07 12:30:37 -05:00
|
|
|
return this.notes.length == 0;
|
2018-02-16 02:17:05 -06:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
document.addEventListener('keydown', this.onDocumentKeydown);
|
|
|
|
window.addEventListener('scroll', this.onScroll);
|
|
|
|
|
|
|
|
this.fetch(() => this.$emit('loaded'));
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
document.removeEventListener('keydown', this.onDocumentKeydown);
|
|
|
|
window.removeEventListener('scroll', this.onScroll);
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onDocumentKeydown(e) {
|
|
|
|
if (e.target.tagName !== 'INPUT' && e.target.tagName !== 'TEXTAREA') {
|
|
|
|
if (e.which == 84) { // [t]
|
|
|
|
(this.$refs.timeline as any).focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
fetch(cb?) {
|
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,
|
|
|
|
untilDate: this.date ? this.date.getTime() : undefined,
|
2018-02-16 02:17:05 -06:00
|
|
|
with_replies: this.mode == 'with-replies'
|
2018-04-07 12:30:37 -05:00
|
|
|
}).then(notes => {
|
|
|
|
this.notes = notes;
|
2018-02-19 08:37:09 -06:00
|
|
|
this.fetching = false;
|
2018-02-16 02:17:05 -06:00
|
|
|
if (cb) cb();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
more() {
|
2018-04-07 12:30:37 -05:00
|
|
|
if (this.moreFetching || this.fetching || this.notes.length == 0) return;
|
2018-02-16 02:17:05 -06:00
|
|
|
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,
|
2018-02-16 02:17:05 -06:00
|
|
|
with_replies: this.mode == 'with-replies',
|
2018-04-07 12:30:37 -05:00
|
|
|
untilId: this.notes[this.notes.length - 1].id
|
|
|
|
}).then(notes => {
|
2018-02-16 02:17:05 -06:00
|
|
|
this.moreFetching = false;
|
2018-04-07 12:30:37 -05:00
|
|
|
this.notes = this.notes.concat(notes);
|
2018-02-16 02:17:05 -06:00
|
|
|
});
|
|
|
|
},
|
|
|
|
onScroll() {
|
|
|
|
const current = window.scrollY + window.innerHeight;
|
|
|
|
if (current > document.body.offsetHeight - 16/*遊び*/) {
|
|
|
|
this.more();
|
|
|
|
}
|
2018-02-22 06:39:36 -06:00
|
|
|
},
|
|
|
|
warp(date) {
|
|
|
|
this.date = date;
|
|
|
|
this.fetch();
|
2018-02-16 02:17:05 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus" scoped>
|
2018-03-02 22:47:55 -06:00
|
|
|
@import '~const.styl'
|
|
|
|
|
2018-02-20 10:39:51 -06:00
|
|
|
.timeline
|
2018-02-16 02:17:05 -06:00
|
|
|
background #fff
|
|
|
|
|
|
|
|
> header
|
|
|
|
padding 8px 16px
|
|
|
|
border-bottom solid 1px #eee
|
|
|
|
|
|
|
|
> span
|
|
|
|
margin-right 16px
|
|
|
|
line-height 27px
|
|
|
|
font-size 18px
|
|
|
|
color #555
|
|
|
|
|
|
|
|
&:not([data-is-active])
|
|
|
|
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>
|