2018-03-09 07:21:25 +01:00
|
|
|
<template>
|
|
|
|
<div id="home">
|
2018-04-20 14:23:53 +02:00
|
|
|
<div class="unread">{{ unread.length > 0 ? unread.length : '' }}</div>
|
2018-03-20 14:21:16 +01:00
|
|
|
<div class="home-timeline" v-for="(message, index) in timeline" v-bind:key="index">
|
2018-04-22 17:36:56 +02:00
|
|
|
<toot :message="message" :key="message.id" v-on:update="updateToot"></toot>
|
2018-03-12 08:42:05 +01:00
|
|
|
</div>
|
2018-04-13 02:09:51 +02:00
|
|
|
<div class="loading-card" v-loading="lazyLoading" :element-loading-background="backgroundColor">
|
2018-03-27 08:33:20 +02:00
|
|
|
</div>
|
2018-03-09 07:21:25 +01:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2018-03-12 08:42:05 +01:00
|
|
|
import { mapState } from 'vuex'
|
2018-03-12 15:13:55 +01:00
|
|
|
import Toot from './Cards/Toot'
|
2018-03-12 08:42:05 +01:00
|
|
|
|
2018-03-09 07:21:25 +01:00
|
|
|
export default {
|
2018-03-12 08:42:05 +01:00
|
|
|
name: 'home',
|
|
|
|
components: { Toot },
|
|
|
|
computed: {
|
|
|
|
...mapState({
|
2018-04-20 17:06:29 +02:00
|
|
|
timeline: state => state.TimelineSpace.Contents.Home.timeline,
|
2018-04-13 02:09:51 +02:00
|
|
|
lazyLoading: state => state.TimelineSpace.Contents.Home.lazyLoading,
|
2018-04-20 02:17:52 +02:00
|
|
|
backgroundColor: state => state.App.theme.background_color,
|
2018-04-20 17:06:29 +02:00
|
|
|
heading: state => state.TimelineSpace.Contents.Home.heading,
|
|
|
|
unread: state => state.TimelineSpace.Contents.Home.unreadTimeline
|
2018-03-12 08:42:05 +01:00
|
|
|
})
|
2018-03-26 14:58:58 +02:00
|
|
|
},
|
|
|
|
mounted () {
|
|
|
|
this.$store.commit('TimelineSpace/SideMenu/changeUnreadHomeTimeline', false)
|
2018-03-30 10:25:13 +02:00
|
|
|
document.getElementById('scrollable').addEventListener('scroll', this.onScroll)
|
2018-03-26 14:58:58 +02:00
|
|
|
},
|
|
|
|
beforeUpdate () {
|
|
|
|
if (this.$store.state.TimelineSpace.SideMenu.unreadHomeTimeline) {
|
|
|
|
this.$store.commit('TimelineSpace/SideMenu/changeUnreadHomeTimeline', false)
|
|
|
|
}
|
2018-03-27 06:58:20 +02:00
|
|
|
},
|
|
|
|
destroyed () {
|
2018-04-20 17:06:29 +02:00
|
|
|
this.$store.commit('TimelineSpace/Contents/Home/changeHeading', true)
|
|
|
|
this.$store.commit('TimelineSpace/Contents/Home/mergeTimeline')
|
|
|
|
this.$store.commit('TimelineSpace/Contents/Home/archiveTimeline')
|
2018-04-02 15:33:12 +02:00
|
|
|
if (document.getElementById('scrollable') !== undefined && document.getElementById('scrollable') !== null) {
|
|
|
|
document.getElementById('scrollable').removeEventListener('scroll', this.onScroll)
|
2018-04-20 16:30:56 +02:00
|
|
|
document.getElementById('scrollable').scrollTop = 0
|
2018-04-02 15:33:12 +02:00
|
|
|
}
|
2018-03-27 08:33:20 +02:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onScroll (event) {
|
2018-04-20 02:17:52 +02:00
|
|
|
// for lazyLoading
|
2018-03-30 10:25:13 +02:00
|
|
|
if (((event.target.clientHeight + event.target.scrollTop) >= document.getElementById('home').clientHeight - 10) && !this.lazyloading) {
|
2018-03-29 17:20:15 +02:00
|
|
|
this.$store.dispatch('TimelineSpace/Contents/Home/lazyFetchTimeline', this.timeline[this.timeline.length - 1])
|
2018-04-14 14:55:22 +02:00
|
|
|
.catch(() => {
|
|
|
|
this.$message({
|
|
|
|
message: 'Could not fetch home timeline',
|
|
|
|
type: 'error'
|
|
|
|
})
|
|
|
|
})
|
2018-03-27 08:33:20 +02:00
|
|
|
}
|
2018-04-20 02:17:52 +02:00
|
|
|
// for unread control
|
|
|
|
if ((event.target.scrollTop > 10) && this.heading) {
|
2018-04-20 17:06:29 +02:00
|
|
|
this.$store.commit('TimelineSpace/Contents/Home/changeHeading', false)
|
2018-04-20 02:17:52 +02:00
|
|
|
} else if ((event.target.scrollTop <= 10) && !this.heading) {
|
2018-04-20 17:06:29 +02:00
|
|
|
this.$store.commit('TimelineSpace/Contents/Home/changeHeading', true)
|
|
|
|
this.$store.commit('TimelineSpace/Contents/Home/mergeTimeline')
|
2018-04-20 02:17:52 +02:00
|
|
|
}
|
2018-04-22 17:36:56 +02:00
|
|
|
},
|
|
|
|
updateToot (message) {
|
|
|
|
this.$store.commit('TimelineSpace/Contents/Home/updateToot', message)
|
2018-03-27 08:33:20 +02:00
|
|
|
}
|
2018-03-12 08:42:05 +01:00
|
|
|
}
|
2018-03-09 07:21:25 +01:00
|
|
|
}
|
|
|
|
</script>
|
2018-03-12 08:42:05 +01:00
|
|
|
|
2018-03-27 08:33:20 +02:00
|
|
|
<style lang="scss" scoped>
|
2018-04-20 14:23:53 +02:00
|
|
|
#home {
|
|
|
|
.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;
|
|
|
|
|
|
|
|
&:empty {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
2018-03-27 08:33:20 +02:00
|
|
|
|
2018-04-20 14:23:53 +02:00
|
|
|
.loading-card {
|
|
|
|
height: 60px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.loading-card:empty {
|
|
|
|
height: 0;
|
|
|
|
}
|
2018-03-27 08:33:20 +02:00
|
|
|
}
|
|
|
|
</style>
|