barkey/src/client/app/desktop/views/components/mentions.vue

126 lines
2.7 KiB
Vue
Raw Normal View History

2018-02-20 00:48:30 +00:00
<template>
<div class="mk-mentions">
<header>
<span :data-is-active="mode == 'all'" @click="mode = 'all'">すべて</span>
<span :data-is-active="mode == 'following'" @click="mode = 'following'">フォロー中</span>
</header>
<div class="fetching" v-if="fetching">
<mk-ellipsis-icon/>
</div>
2018-04-07 17:30:37 +00:00
<p class="empty" v-if="notes.length == 0 && !fetching">
2018-02-20 00:48:30 +00:00
%fa:R comments%
<span v-if="mode == 'all'">あなた宛ての投稿はありません</span>
<span v-if="mode == 'following'">あなたがフォローしているユーザーからの言及はありません</span>
</p>
2018-04-07 17:30:37 +00:00
<mk-notes :notes="notes" ref="timeline"/>
2018-02-20 00:48:30 +00:00
</div>
</template>
<script lang="ts">
import Vue from 'vue';
export default Vue.extend({
data() {
return {
fetching: true,
moreFetching: false,
mode: 'all',
2018-04-07 17:30:37 +00:00
notes: []
2018-02-20 00:48:30 +00:00
};
},
watch: {
mode() {
this.fetch();
}
},
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();
}
}
},
onScroll() {
const current = window.scrollY + window.innerHeight;
if (current > document.body.offsetHeight - 8) this.more();
},
fetch(cb?) {
this.fetching = true;
2018-04-07 17:30:37 +00:00
this.notes = [];
(this as any).api('notes/mentions', {
2018-02-20 00:48:30 +00:00
following: this.mode == 'following'
2018-04-07 17:30:37 +00:00
}).then(notes => {
this.notes = notes;
2018-02-20 00:48:30 +00:00
this.fetching = false;
if (cb) cb();
});
},
more() {
2018-04-07 17:30:37 +00:00
if (this.moreFetching || this.fetching || this.notes.length == 0) return;
2018-02-20 00:48:30 +00:00
this.moreFetching = true;
2018-04-07 17:30:37 +00:00
(this as any).api('notes/mentions', {
2018-02-20 00:48:30 +00:00
following: this.mode == 'following',
2018-04-07 17:30:37 +00:00
untilId: this.notes[this.notes.length - 1].id
}).then(notes => {
this.notes = this.notes.concat(notes);
2018-02-20 00:48:30 +00:00
this.moreFetching = false;
});
}
}
});
</script>
<style lang="stylus" scoped>
2018-03-03 04:47:55 +00:00
@import '~const.styl'
2018-02-20 00:48:30 +00:00
.mk-mentions
background #fff
border solid 1px rgba(0, 0, 0, 0.075)
border-radius 6px
> 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
> .fetching
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>