2018-04-09 01:43:11 +02:00
|
|
|
<template>
|
2018-06-16 08:33:52 +02:00
|
|
|
<div name="list">
|
2018-04-21 08:53:06 +02:00
|
|
|
<div class="unread">{{ unread.length > 0 ? unread.length : '' }}</div>
|
2018-06-10 08:00:33 +02:00
|
|
|
<div v-shortkey="{linux: ['ctrl', 'r'], mac: ['meta', 'r']}" @shortkey="reload()">
|
|
|
|
</div>
|
2018-04-23 12:03:47 +02:00
|
|
|
<transition-group name="timeline" tag="div">
|
|
|
|
<div class="list-timeline" v-for="message in timeline" v-bind:key="message.id">
|
2018-04-30 15:11:40 +02:00
|
|
|
<toot :message="message" v-on:update="updateToot" v-on:delete="deleteToot"></toot>
|
2018-04-23 12:03:47 +02:00
|
|
|
</div>
|
|
|
|
</transition-group>
|
2018-04-13 15:58:54 +02:00
|
|
|
<div class="loading-card" v-loading="lazyLoading" :element-loading-background="backgroundColor"></div>
|
2018-04-09 01:43:11 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2018-04-09 14:10:25 +02:00
|
|
|
import { mapState } from 'vuex'
|
2018-06-16 08:33:52 +02:00
|
|
|
import Toot from '../Cards/Toot'
|
2018-04-09 14:10:25 +02:00
|
|
|
|
2018-04-09 01:43:11 +02:00
|
|
|
export default {
|
2018-06-16 08:33:52 +02:00
|
|
|
name: 'list',
|
2018-04-09 14:10:25 +02:00
|
|
|
props: ['list_id'],
|
|
|
|
components: { Toot },
|
|
|
|
computed: {
|
|
|
|
...mapState({
|
2018-06-16 08:33:52 +02:00
|
|
|
timeline: state => state.TimelineSpace.Contents.Lists.Show.timeline,
|
|
|
|
lazyLoading: state => state.TimelineSpace.Contents.Lists.Show.lazyLoading,
|
2018-04-21 08:53:06 +02:00
|
|
|
backgroundColor: state => state.App.theme.background_color,
|
2018-06-16 08:33:52 +02:00
|
|
|
heading: state => state.TimelineSpace.Contents.Lists.Show.heading,
|
2018-06-27 15:27:46 +02:00
|
|
|
unread: state => state.TimelineSpace.Contents.Lists.Show.unreadTimeline,
|
|
|
|
startReload: state => state.TimelineSpace.HeaderMenu.reload
|
2018-04-09 14:10:25 +02:00
|
|
|
})
|
|
|
|
},
|
|
|
|
created () {
|
2018-07-02 14:53:09 +02:00
|
|
|
this.$store.commit('TimelineSpace/changeLoading', true)
|
2018-04-09 14:10:25 +02:00
|
|
|
this.load()
|
2018-07-02 14:53:09 +02:00
|
|
|
.finally(() => {
|
|
|
|
this.$store.commit('TimelineSpace/changeLoading', false)
|
2018-04-09 16:43:36 +02:00
|
|
|
})
|
2018-04-09 16:08:52 +02:00
|
|
|
document.getElementById('scrollable').addEventListener('scroll', this.onScroll)
|
2018-04-09 14:10:25 +02:00
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
list_id: function () {
|
2018-07-02 14:53:09 +02:00
|
|
|
this.$store.commit('TimelineSpace/changeLoading', true)
|
2018-04-09 14:10:25 +02:00
|
|
|
this.load()
|
2018-07-02 14:53:09 +02:00
|
|
|
.finally(() => {
|
|
|
|
this.$store.commit('TimelineSpace/changeLoading', false)
|
2018-04-09 16:43:36 +02:00
|
|
|
})
|
2018-06-27 15:27:46 +02:00
|
|
|
},
|
|
|
|
startReload: function (newState, oldState) {
|
|
|
|
if (!oldState && newState) {
|
|
|
|
this.reload()
|
|
|
|
.finally(() => {
|
|
|
|
this.$store.commit('TimelineSpace/HeaderMenu/changeReload', false)
|
|
|
|
})
|
|
|
|
}
|
2018-04-09 14:10:25 +02:00
|
|
|
}
|
|
|
|
},
|
2018-04-09 16:43:36 +02:00
|
|
|
beforeDestroy () {
|
2018-06-16 08:33:52 +02:00
|
|
|
this.$store.dispatch('TimelineSpace/Contents/Lists/Show/stopStreaming')
|
2018-04-09 16:43:36 +02:00
|
|
|
},
|
2018-04-09 16:08:52 +02:00
|
|
|
destroyed () {
|
2018-06-16 08:33:52 +02:00
|
|
|
this.$store.commit('TimelineSpace/Contents/Lists/Show/changeHeading', true)
|
|
|
|
this.$store.commit('TimelineSpace/Contents/Lists/Show/mergeTimeline')
|
|
|
|
this.$store.commit('TimelineSpace/Contents/Lists/Show/archiveTimeline')
|
|
|
|
this.$store.commit('TimelineSpace/Contents/Lists/Show/clearTimeline')
|
2018-04-09 16:08:52 +02:00
|
|
|
if (document.getElementById('scrollable') !== undefined && document.getElementById('scrollable') !== null) {
|
|
|
|
document.getElementById('scrollable').removeEventListener('scroll', this.onScroll)
|
2018-04-21 08:53:06 +02:00
|
|
|
document.getElementById('scrollable').scrollTop = 0
|
2018-04-09 16:08:52 +02:00
|
|
|
}
|
|
|
|
},
|
2018-04-09 14:10:25 +02:00
|
|
|
methods: {
|
2018-04-09 16:43:36 +02:00
|
|
|
async load () {
|
2018-06-16 08:33:52 +02:00
|
|
|
await this.$store.dispatch('TimelineSpace/Contents/Lists/Show/stopStreaming')
|
2018-04-09 16:43:36 +02:00
|
|
|
try {
|
2018-06-16 08:33:52 +02:00
|
|
|
await this.$store.dispatch('TimelineSpace/Contents/Lists/Show/fetchTimeline', this.list_id)
|
2018-04-09 16:43:36 +02:00
|
|
|
} catch (err) {
|
|
|
|
this.$message({
|
|
|
|
message: 'Failed to get timeline',
|
|
|
|
type: 'error'
|
2018-04-09 14:10:25 +02:00
|
|
|
})
|
2018-04-09 16:43:36 +02:00
|
|
|
}
|
2018-06-16 08:33:52 +02:00
|
|
|
this.$store.dispatch('TimelineSpace/Contents/Lists/Show/startStreaming', this.list_id)
|
2018-04-09 14:10:25 +02:00
|
|
|
.catch(() => {
|
|
|
|
this.$message({
|
2018-04-09 16:43:36 +02:00
|
|
|
message: 'Failed to start streaming',
|
2018-04-09 14:10:25 +02:00
|
|
|
type: 'error'
|
|
|
|
})
|
|
|
|
})
|
2018-04-09 16:43:36 +02:00
|
|
|
return 'started'
|
2018-04-09 15:05:15 +02:00
|
|
|
},
|
|
|
|
updateToot (message) {
|
2018-06-16 08:33:52 +02:00
|
|
|
this.$store.commit('TimelineSpace/Contents/Lists/Show/updateToot', message)
|
2018-04-09 16:08:52 +02:00
|
|
|
},
|
2018-04-30 15:11:40 +02:00
|
|
|
deleteToot (message) {
|
2018-06-16 08:33:52 +02:00
|
|
|
this.$store.commit('TimelineSpace/Contents/Lists/Show/deleteToot', message)
|
2018-04-30 15:11:40 +02:00
|
|
|
},
|
2018-04-09 16:08:52 +02:00
|
|
|
onScroll (event) {
|
2018-06-16 08:33:52 +02:00
|
|
|
if (((event.target.clientHeight + event.target.scrollTop) >= document.getElementsByName('list')[0].clientHeight - 10) && !this.lazyloading) {
|
|
|
|
this.$store.dispatch('TimelineSpace/Contents/Lists/Show/lazyFetchTimeline', {
|
2018-04-09 16:08:52 +02:00
|
|
|
list_id: this.list_id,
|
|
|
|
last: this.timeline[this.timeline.length - 1]
|
|
|
|
})
|
|
|
|
}
|
2018-04-21 08:53:06 +02:00
|
|
|
// for unread control
|
|
|
|
if ((event.target.scrollTop > 10) && this.heading) {
|
2018-06-16 08:33:52 +02:00
|
|
|
this.$store.commit('TimelineSpace/Contents/Lists/Show/changeHeading', false)
|
2018-04-21 08:53:06 +02:00
|
|
|
} else if ((event.target.scrollTop <= 10) && !this.heading) {
|
2018-06-16 08:33:52 +02:00
|
|
|
this.$store.commit('TimelineSpace/Contents/Lists/Show/changeHeading', true)
|
|
|
|
this.$store.commit('TimelineSpace/Contents/Lists/Show/mergeTimeline')
|
2018-04-21 08:53:06 +02:00
|
|
|
}
|
2018-06-10 08:00:33 +02:00
|
|
|
},
|
|
|
|
async reload () {
|
2018-07-02 14:53:09 +02:00
|
|
|
this.$store.commit('TimelineSpace/changeLoading', true)
|
|
|
|
try {
|
|
|
|
const account = await this.$store.dispatch('TimelineSpace/localAccount', this.$route.params.id).catch((err) => {
|
2018-06-10 08:00:33 +02:00
|
|
|
this.$message({
|
2018-07-02 14:53:09 +02:00
|
|
|
message: 'Could not find account',
|
2018-06-10 08:00:33 +02:00
|
|
|
type: 'error'
|
|
|
|
})
|
2018-07-02 14:53:09 +02:00
|
|
|
throw err
|
2018-06-10 08:00:33 +02:00
|
|
|
})
|
|
|
|
|
2018-07-02 14:53:09 +02:00
|
|
|
await this.$store.dispatch('TimelineSpace/stopUserStreaming')
|
|
|
|
await this.$store.dispatch('TimelineSpace/stopLocalStreaming')
|
|
|
|
await this.$store.dispatch('TimelineSpace/Contents/Lists/Show/stopStreaming')
|
|
|
|
|
|
|
|
await this.$store.dispatch('TimelineSpace/Contents/Home/fetchTimeline', account)
|
|
|
|
await this.$store.dispatch('TimelineSpace/Contents/Local/fetchLocalTimeline', account)
|
|
|
|
await this.$store.dispatch('TimelineSpace/Contents/Lists/Show/fetchTimeline', this.list_id)
|
|
|
|
.catch(() => {
|
|
|
|
this.$message({
|
|
|
|
message: 'Could not fetch timeline',
|
|
|
|
type: 'error'
|
|
|
|
})
|
2018-06-10 08:00:33 +02:00
|
|
|
})
|
2018-07-02 14:53:09 +02:00
|
|
|
|
|
|
|
this.$store.dispatch('TimelineSpace/startUserStreaming', account)
|
|
|
|
this.$store.dispatch('TimelineSpace/startLocalStreaming', account)
|
|
|
|
this.$store.dispatch('TimelineSpace/Contents/Lists/Show/startStreaming', this.list_id)
|
|
|
|
.catch(() => {
|
|
|
|
this.$message({
|
|
|
|
message: 'Failed to restart streaming',
|
|
|
|
type: 'error'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
} finally {
|
|
|
|
this.$store.commit('TimelineSpace/changeLoading', false)
|
|
|
|
}
|
2018-04-09 14:10:25 +02:00
|
|
|
}
|
|
|
|
}
|
2018-04-09 01:43:11 +02:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2018-04-25 15:28:42 +02:00
|
|
|
.unread {
|
|
|
|
position: fixed;
|
|
|
|
right: 24px;
|
|
|
|
top: 48px;
|
|
|
|
background-color: rgba(0, 0, 0, 0.7);
|
|
|
|
color: #ffffff;
|
|
|
|
padding: 4px 8px;
|
|
|
|
border-radius: 0 0 2px 2px;
|
2018-04-21 08:53:06 +02:00
|
|
|
|
2018-04-25 15:28:42 +02:00
|
|
|
&:empty {
|
|
|
|
display: none;
|
2018-04-21 08:53:06 +02:00
|
|
|
}
|
2018-04-25 15:28:42 +02:00
|
|
|
}
|
2018-04-21 08:53:06 +02:00
|
|
|
|
2018-04-25 15:28:42 +02:00
|
|
|
.loading-card {
|
|
|
|
height: 60px;
|
|
|
|
}
|
2018-04-09 16:08:52 +02:00
|
|
|
|
2018-04-25 15:28:42 +02:00
|
|
|
.loading-card:empty {
|
|
|
|
height: 0;
|
2018-04-09 16:08:52 +02:00
|
|
|
}
|
2018-04-09 01:43:11 +02:00
|
|
|
</style>
|
2018-04-23 12:03:47 +02:00
|
|
|
<style src="@/assets/timeline-transition.scss"></style>
|