2018-04-09 01:43:11 +02:00
|
|
|
<template>
|
2018-04-09 16:08:52 +02:00
|
|
|
<div name="lists">
|
2018-04-09 14:10:25 +02:00
|
|
|
<div class="list-timeline" v-for="message in timeline" v-bind:key="message.id">
|
2018-04-09 15:05:15 +02:00
|
|
|
<toot :message="message" v-on:update="updateToot"></toot>
|
2018-04-09 14:10:25 +02:00
|
|
|
</div>
|
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'
|
|
|
|
import Toot from './Cards/Toot'
|
|
|
|
|
2018-04-09 01:43:11 +02:00
|
|
|
export default {
|
2018-04-09 14:10:25 +02:00
|
|
|
name: 'lists',
|
|
|
|
props: ['list_id'],
|
|
|
|
components: { Toot },
|
|
|
|
computed: {
|
|
|
|
...mapState({
|
2018-04-09 16:08:52 +02:00
|
|
|
timeline: state => state.TimelineSpace.Contents.Lists.timeline,
|
2018-04-13 15:58:54 +02:00
|
|
|
lazyLoading: state => state.TimelineSpace.Contents.Lists.lazyLoading,
|
|
|
|
backgroundColor: state => state.App.theme.background_color
|
2018-04-09 14:10:25 +02:00
|
|
|
})
|
|
|
|
},
|
|
|
|
created () {
|
2018-04-09 16:43:36 +02:00
|
|
|
const loading = this.$loading({
|
|
|
|
lock: true,
|
|
|
|
text: 'Loading',
|
|
|
|
spinner: 'el-icon-loading',
|
|
|
|
background: 'rgba(0, 0, 0, 0.7)'
|
|
|
|
})
|
2018-04-09 14:10:25 +02:00
|
|
|
this.load()
|
2018-04-09 16:43:36 +02:00
|
|
|
.then(() => {
|
|
|
|
loading.close()
|
|
|
|
})
|
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-04-09 16:43:36 +02:00
|
|
|
const loading = this.$loading({
|
|
|
|
lock: true,
|
|
|
|
text: 'Loading',
|
|
|
|
spinner: 'el-icon-loading',
|
|
|
|
background: 'rgba(0, 0, 0, 0.7)'
|
|
|
|
})
|
2018-04-09 14:10:25 +02:00
|
|
|
this.load()
|
2018-04-09 16:43:36 +02:00
|
|
|
.then(() => {
|
|
|
|
loading.close()
|
|
|
|
})
|
2018-04-09 14:10:25 +02:00
|
|
|
}
|
|
|
|
},
|
2018-04-09 16:43:36 +02:00
|
|
|
beforeDestroy () {
|
|
|
|
this.$store.dispatch('TimelineSpace/Contents/Lists/stopStreaming')
|
|
|
|
},
|
2018-04-09 16:08:52 +02:00
|
|
|
destroyed () {
|
2018-04-16 17:48:26 +02:00
|
|
|
this.$store.commit('TimelineSpace/Contents/Lists/updateTimeline', [])
|
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-09 14:10:25 +02:00
|
|
|
methods: {
|
2018-04-09 16:43:36 +02:00
|
|
|
async load () {
|
|
|
|
await this.$store.dispatch('TimelineSpace/Contents/Lists/stopStreaming')
|
|
|
|
try {
|
|
|
|
await this.$store.dispatch('TimelineSpace/Contents/Lists/fetchTimeline', this.list_id)
|
|
|
|
} 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
|
|
|
}
|
|
|
|
this.$store.dispatch('TimelineSpace/Contents/Lists/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) {
|
|
|
|
this.$store.commit('TimelineSpace/Contents/Lists/updateToot', message)
|
2018-04-09 16:08:52 +02:00
|
|
|
},
|
|
|
|
onScroll (event) {
|
|
|
|
if (((event.target.clientHeight + event.target.scrollTop) >= document.getElementsByName('lists')[0].clientHeight - 10) && !this.lazyloading) {
|
|
|
|
this.$store.dispatch('TimelineSpace/Contents/Lists/lazyFetchTimeline', {
|
|
|
|
list_id: this.list_id,
|
|
|
|
last: this.timeline[this.timeline.length - 1]
|
|
|
|
})
|
|
|
|
}
|
2018-04-09 14:10:25 +02:00
|
|
|
}
|
|
|
|
}
|
2018-04-09 01:43:11 +02:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2018-04-09 16:08:52 +02:00
|
|
|
.loading-card {
|
|
|
|
height: 60px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.loading-card:empty {
|
|
|
|
height: 0;
|
|
|
|
}
|
2018-04-09 01:43:11 +02:00
|
|
|
</style>
|