Whalebird-desktop-client-ma.../src/renderer/components/TimelineSpace/Contents/Lists.vue

139 lines
4.2 KiB
Vue
Raw Normal View History

<template>
2018-04-25 15:28:42 +02:00
<div name="lists">
<div class="unread">{{ unread.length > 0 ? unread.length : '' }}</div>
<transition-group name="timeline" tag="div">
<div class="list-timeline" v-for="message in timeline" v-bind:key="message.id">
<toot :message="message" v-on:update="updateToot" v-on:delete="deleteToot"></toot>
</div>
</transition-group>
<div class="loading-card" v-loading="lazyLoading" :element-loading-background="backgroundColor"></div>
</div>
</template>
<script>
2018-04-09 14:10:25 +02:00
import { mapState } from 'vuex'
import Toot from './Cards/Toot'
export default {
2018-04-09 14:10:25 +02:00
name: 'lists',
props: ['list_id'],
components: { Toot },
computed: {
...mapState({
timeline: state => state.TimelineSpace.Contents.Lists.timeline,
lazyLoading: state => state.TimelineSpace.Contents.Lists.lazyLoading,
backgroundColor: state => state.App.theme.background_color,
heading: state => state.TimelineSpace.Contents.Lists.heading,
unread: state => state.TimelineSpace.Contents.Lists.unreadTimeline
2018-04-09 14:10:25 +02:00
})
},
created () {
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()
.then(() => {
loading.close()
})
document.getElementById('scrollable').addEventListener('scroll', this.onScroll)
2018-04-09 14:10:25 +02:00
},
watch: {
list_id: function () {
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()
.then(() => {
loading.close()
})
2018-04-09 14:10:25 +02:00
}
},
beforeDestroy () {
this.$store.dispatch('TimelineSpace/Contents/Lists/stopStreaming')
},
destroyed () {
this.$store.commit('TimelineSpace/Contents/Lists/changeHeading', true)
this.$store.commit('TimelineSpace/Contents/Lists/mergeTimeline')
this.$store.commit('TimelineSpace/Contents/Lists/archiveTimeline')
this.$store.commit('TimelineSpace/Contents/Lists/clearTimeline')
if (document.getElementById('scrollable') !== undefined && document.getElementById('scrollable') !== null) {
document.getElementById('scrollable').removeEventListener('scroll', this.onScroll)
document.getElementById('scrollable').scrollTop = 0
}
},
2018-04-09 14:10:25 +02:00
methods: {
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
})
}
this.$store.dispatch('TimelineSpace/Contents/Lists/startStreaming', this.list_id)
2018-04-09 14:10:25 +02:00
.catch(() => {
this.$message({
message: 'Failed to start streaming',
2018-04-09 14:10:25 +02:00
type: 'error'
})
})
return 'started'
},
updateToot (message) {
this.$store.commit('TimelineSpace/Contents/Lists/updateToot', message)
},
deleteToot (message) {
this.$store.commit('TimelineSpace/Contents/Lists/deleteToot', message)
},
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]
})
}
// for unread control
if ((event.target.scrollTop > 10) && this.heading) {
this.$store.commit('TimelineSpace/Contents/Lists/changeHeading', false)
} else if ((event.target.scrollTop <= 10) && !this.heading) {
this.$store.commit('TimelineSpace/Contents/Lists/changeHeading', true)
this.$store.commit('TimelineSpace/Contents/Lists/mergeTimeline')
}
2018-04-09 14:10:25 +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-25 15:28:42 +02:00
&:empty {
display: none;
}
2018-04-25 15:28:42 +02:00
}
2018-04-25 15:28:42 +02:00
.loading-card {
height: 60px;
}
2018-04-25 15:28:42 +02:00
.loading-card:empty {
height: 0;
}
</style>
<style src="@/assets/timeline-transition.scss"></style>