2018-02-11 00:52:37 -07:00
|
|
|
<template>
|
2018-02-12 16:31:03 -07:00
|
|
|
<div class="mk-timeline">
|
2018-02-19 03:46:31 -07:00
|
|
|
<mk-friends-maker v-if="alone"/>
|
2018-02-19 17:48:30 -07:00
|
|
|
<div class="fetching" v-if="fetching">
|
2018-02-12 17:12:54 -07:00
|
|
|
<mk-ellipsis-icon/>
|
|
|
|
</div>
|
2018-02-22 04:52:39 -07:00
|
|
|
<p class="empty" v-if="posts.length == 0 && !fetching">
|
|
|
|
%fa:R comments%自分の投稿や、自分がフォローしているユーザーの投稿が表示されます。
|
|
|
|
</p>
|
|
|
|
<mk-posts :posts="posts" ref="timeline">
|
2018-03-05 04:09:26 -07:00
|
|
|
<button slot="footer" @click="more" :disabled="moreFetching" :style="{ cursor: moreFetching ? 'wait' : 'pointer' }">
|
|
|
|
<template v-if="!moreFetching">もっと見る</template>
|
2018-02-22 04:52:39 -07:00
|
|
|
<template v-if="moreFetching">%fa:spinner .pulse .fw%</template>
|
2018-03-05 04:09:26 -07:00
|
|
|
</button>
|
2018-02-22 04:52:39 -07:00
|
|
|
</mk-posts>
|
2018-02-11 07:26:35 -07:00
|
|
|
</div>
|
2018-02-11 00:52:37 -07:00
|
|
|
</template>
|
|
|
|
|
2018-02-11 01:04:03 -07:00
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
2018-03-04 02:50:30 -07:00
|
|
|
import { url } from '../../../config';
|
2018-02-11 00:52:37 -07:00
|
|
|
|
2018-02-11 01:04:03 -07:00
|
|
|
export default Vue.extend({
|
2018-02-12 17:12:54 -07:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
fetching: true,
|
|
|
|
moreFetching: false,
|
2018-02-25 08:39:05 -07:00
|
|
|
existMore: false,
|
2018-02-12 17:12:54 -07:00
|
|
|
posts: [],
|
|
|
|
connection: null,
|
2018-02-19 02:26:20 -07:00
|
|
|
connectionId: null,
|
|
|
|
date: null
|
2018-02-12 17:12:54 -07:00
|
|
|
};
|
|
|
|
},
|
2018-02-11 01:04:03 -07:00
|
|
|
computed: {
|
2018-02-12 17:12:54 -07:00
|
|
|
alone(): boolean {
|
2018-02-17 20:35:18 -07:00
|
|
|
return (this as any).os.i.following_count == 0;
|
2018-02-11 01:04:03 -07:00
|
|
|
}
|
|
|
|
},
|
2018-02-12 17:12:54 -07:00
|
|
|
mounted() {
|
2018-02-17 20:35:18 -07:00
|
|
|
this.connection = (this as any).os.stream.getConnection();
|
|
|
|
this.connectionId = (this as any).os.stream.use();
|
2018-02-12 17:12:54 -07:00
|
|
|
|
|
|
|
this.connection.on('post', this.onPost);
|
|
|
|
this.connection.on('follow', this.onChangeFollowing);
|
|
|
|
this.connection.on('unfollow', this.onChangeFollowing);
|
|
|
|
|
|
|
|
document.addEventListener('keydown', this.onKeydown);
|
|
|
|
window.addEventListener('scroll', this.onScroll);
|
|
|
|
|
|
|
|
this.fetch();
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
this.connection.off('post', this.onPost);
|
|
|
|
this.connection.off('follow', this.onChangeFollowing);
|
|
|
|
this.connection.off('unfollow', this.onChangeFollowing);
|
2018-02-17 20:35:18 -07:00
|
|
|
(this as any).os.stream.dispose(this.connectionId);
|
2018-02-12 17:12:54 -07:00
|
|
|
|
|
|
|
document.removeEventListener('keydown', this.onKeydown);
|
|
|
|
window.removeEventListener('scroll', this.onScroll);
|
|
|
|
},
|
2018-02-11 01:04:03 -07:00
|
|
|
methods: {
|
2018-02-12 17:12:54 -07:00
|
|
|
fetch(cb?) {
|
|
|
|
this.fetching = true;
|
|
|
|
|
2018-02-17 20:35:18 -07:00
|
|
|
(this as any).api('posts/timeline', {
|
2018-02-25 08:39:05 -07:00
|
|
|
limit: 11,
|
2018-02-19 02:26:20 -07:00
|
|
|
until_date: this.date ? this.date.getTime() : undefined
|
2018-02-12 17:12:54 -07:00
|
|
|
}).then(posts => {
|
2018-02-25 08:39:05 -07:00
|
|
|
if (posts.length == 11) {
|
|
|
|
posts.pop();
|
|
|
|
this.existMore = true;
|
|
|
|
}
|
2018-02-12 17:12:54 -07:00
|
|
|
this.posts = posts;
|
2018-02-19 07:37:09 -07:00
|
|
|
this.fetching = false;
|
2018-02-20 09:12:18 -07:00
|
|
|
this.$emit('loaded');
|
2018-02-12 17:12:54 -07:00
|
|
|
if (cb) cb();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
more() {
|
2018-02-25 08:39:05 -07:00
|
|
|
if (this.moreFetching || this.fetching || this.posts.length == 0 || !this.existMore) return;
|
2018-02-12 17:12:54 -07:00
|
|
|
this.moreFetching = true;
|
2018-02-17 20:35:18 -07:00
|
|
|
(this as any).api('posts/timeline', {
|
2018-02-25 08:39:05 -07:00
|
|
|
limit: 11,
|
2018-02-12 17:12:54 -07:00
|
|
|
until_id: this.posts[this.posts.length - 1].id
|
|
|
|
}).then(posts => {
|
2018-02-25 08:39:05 -07:00
|
|
|
if (posts.length == 11) {
|
|
|
|
posts.pop();
|
|
|
|
} else {
|
|
|
|
this.existMore = false;
|
|
|
|
}
|
2018-02-22 04:52:39 -07:00
|
|
|
this.posts = this.posts.concat(posts);
|
2018-02-12 17:12:54 -07:00
|
|
|
this.moreFetching = false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onPost(post) {
|
2018-03-04 02:50:30 -07:00
|
|
|
// サウンドを再生する
|
|
|
|
if ((this as any).os.isEnableSounds) {
|
|
|
|
new Audio(`${url}/assets/post.mp3`).play();
|
|
|
|
}
|
|
|
|
|
2018-02-12 17:12:54 -07:00
|
|
|
this.posts.unshift(post);
|
|
|
|
},
|
|
|
|
onChangeFollowing() {
|
|
|
|
this.fetch();
|
|
|
|
},
|
|
|
|
onScroll() {
|
2018-03-05 04:09:26 -07:00
|
|
|
if ((this as any).os.i.client_settings.fetchOnScroll !== false) {
|
|
|
|
const current = window.scrollY + window.innerHeight;
|
|
|
|
if (current > document.body.offsetHeight - 8) this.more();
|
|
|
|
}
|
2018-02-12 17:12:54 -07:00
|
|
|
},
|
|
|
|
onKeydown(e) {
|
|
|
|
if (e.target.tagName != 'INPUT' && e.target.tagName != 'TEXTAREA') {
|
|
|
|
if (e.which == 84) { // t
|
|
|
|
(this.$refs.timeline as any).focus();
|
|
|
|
}
|
|
|
|
}
|
2018-02-19 02:26:20 -07:00
|
|
|
},
|
|
|
|
warp(date) {
|
|
|
|
this.date = date;
|
|
|
|
this.fetch();
|
2018-02-11 01:04:03 -07:00
|
|
|
}
|
|
|
|
}
|
2018-02-11 00:52:37 -07:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus" scoped>
|
|
|
|
.mk-timeline
|
2018-02-12 17:12:54 -07:00
|
|
|
background #fff
|
|
|
|
border solid 1px rgba(0, 0, 0, 0.075)
|
|
|
|
border-radius 6px
|
2018-02-11 00:52:37 -07:00
|
|
|
|
2018-02-22 04:52:39 -07:00
|
|
|
> .mk-friends-maker
|
2018-02-12 17:12:54 -07:00
|
|
|
border-bottom solid 1px #eee
|
2018-02-11 00:52:37 -07:00
|
|
|
|
2018-02-19 17:48:30 -07:00
|
|
|
> .fetching
|
2018-02-12 17:12:54 -07:00
|
|
|
padding 64px 0
|
2018-02-11 00:52:37 -07:00
|
|
|
|
2018-02-12 17:12:54 -07:00
|
|
|
> .empty
|
|
|
|
display block
|
|
|
|
margin 0 auto
|
|
|
|
padding 32px
|
|
|
|
max-width 400px
|
2018-02-11 00:52:37 -07:00
|
|
|
text-align center
|
2018-02-12 17:12:54 -07:00
|
|
|
color #999
|
|
|
|
|
|
|
|
> [data-fa]
|
|
|
|
display block
|
|
|
|
margin-bottom 16px
|
|
|
|
font-size 3em
|
|
|
|
color #ccc
|
2018-02-11 00:52:37 -07:00
|
|
|
|
|
|
|
</style>
|