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

83 lines
2.1 KiB
Vue
Raw Normal View History

<template>
<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">
<toot :message="message" v-on:update="updateToot"></toot>
2018-04-09 14:10:25 +02:00
</div>
<div class="loading-card" v-loading="lazyLoading"></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
2018-04-09 14:10:25 +02:00
})
},
created () {
this.load()
document.getElementById('scrollable').addEventListener('scroll', this.onScroll)
2018-04-09 14:10:25 +02:00
},
watch: {
list_id: function () {
this.load()
}
},
destroyed () {
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: {
load () {
const loading = this.$loading({
lock: true,
text: 'Loading',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
})
this.$store.dispatch('TimelineSpace/Contents/Lists/fetchTimeline', this.list_id)
.then(() => {
loading.close()
})
.catch(() => {
loading.close()
this.$message({
message: 'Failed to get timeline',
type: 'error'
})
})
},
updateToot (message) {
this.$store.commit('TimelineSpace/Contents/Lists/updateToot', message)
},
onScroll (event) {
console.log(document.getElementsByName('lists'))
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
}
}
}
</script>
<style lang="scss" scoped>
.loading-card {
height: 60px;
}
.loading-card:empty {
height: 0;
}
</style>