2018-03-09 07:21:25 +01:00
|
|
|
<template>
|
|
|
|
<div id="local">
|
2018-03-14 04:24:54 +01:00
|
|
|
<div class="local-timeline" v-for="message in timeline" v-bind:key="message.id">
|
2018-03-14 10:11:38 +01:00
|
|
|
<toot :message="message" v-on:update="updateToot"></toot>
|
2018-03-14 04:24:54 +01:00
|
|
|
</div>
|
2018-03-27 15:16:23 +02:00
|
|
|
<div class="loading-card" v-loading="lazyLoading">
|
|
|
|
</div>
|
2018-03-09 07:21:25 +01:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2018-03-14 04:24:54 +01:00
|
|
|
import { mapState } from 'vuex'
|
|
|
|
import Toot from './Cards/Toot'
|
|
|
|
|
2018-03-09 07:21:25 +01:00
|
|
|
export default {
|
2018-03-14 04:24:54 +01:00
|
|
|
name: 'local',
|
|
|
|
components: { Toot },
|
|
|
|
computed: {
|
|
|
|
...mapState({
|
2018-03-27 15:16:23 +02:00
|
|
|
timeline: state => state.TimelineSpace.Local.timeline,
|
|
|
|
lazyLoading: state => state.TimelineSpace.Local.lazyLoading
|
2018-03-14 04:24:54 +01:00
|
|
|
})
|
|
|
|
},
|
|
|
|
created () {
|
2018-03-23 17:48:05 +01:00
|
|
|
const loading = this.$loading({
|
|
|
|
lock: true,
|
|
|
|
text: 'Loading',
|
|
|
|
spinner: 'el-icon-loading',
|
|
|
|
background: 'rgba(0, 0, 0, 0.7)'
|
|
|
|
})
|
|
|
|
this.initialize()
|
|
|
|
.then(() => {
|
|
|
|
loading.close()
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
loading.close()
|
|
|
|
})
|
2018-03-27 15:16:23 +02:00
|
|
|
window.addEventListener('scroll', this.onScroll)
|
2018-03-14 04:24:54 +01:00
|
|
|
},
|
|
|
|
beforeDestroy () {
|
|
|
|
this.$store.dispatch('TimelineSpace/Local/stopLocalStreaming')
|
2018-03-14 10:11:38 +01:00
|
|
|
},
|
2018-03-27 15:16:23 +02:00
|
|
|
destroyed () {
|
|
|
|
window.removeEventListener('scroll', this.onScroll)
|
|
|
|
},
|
2018-03-14 10:11:38 +01:00
|
|
|
methods: {
|
2018-03-23 17:48:05 +01:00
|
|
|
async initialize () {
|
|
|
|
try {
|
2018-03-23 17:50:42 +01:00
|
|
|
await this.$store.dispatch('TimelineSpace/Local/fetchLocalTimeline')
|
2018-03-23 17:48:05 +01:00
|
|
|
} catch (err) {
|
|
|
|
this.$message({
|
|
|
|
message: 'Could not fetch timeline',
|
|
|
|
type: 'error'
|
|
|
|
})
|
|
|
|
}
|
2018-03-23 17:50:42 +01:00
|
|
|
this.$store.dispatch('TimelineSpace/Local/startLocalStreaming')
|
2018-03-23 17:48:05 +01:00
|
|
|
},
|
2018-03-14 10:11:38 +01:00
|
|
|
updateToot (message) {
|
|
|
|
this.$store.commit('TimelineSpace/Local/updateToot', message)
|
2018-03-27 15:16:23 +02:00
|
|
|
},
|
|
|
|
onScroll (event) {
|
|
|
|
if (((document.documentElement.clientHeight + event.target.defaultView.scrollY) >= document.getElementById('local').clientHeight - 10) && !this.lazyloading) {
|
|
|
|
this.$store.dispatch('TimelineSpace/Local/lazyFetchTimeline', this.timeline[this.timeline.length - 1])
|
|
|
|
}
|
2018-03-14 10:11:38 +01:00
|
|
|
}
|
2018-03-14 04:24:54 +01:00
|
|
|
}
|
2018-03-09 07:21:25 +01:00
|
|
|
}
|
|
|
|
</script>
|
2018-03-27 15:16:23 +02:00
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.loading-card {
|
|
|
|
background-color: #ffffff;
|
|
|
|
height: 60px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.loading-card:empty {
|
|
|
|
height: 0;
|
|
|
|
}
|
|
|
|
</style>
|