mirror of
https://github.com/h3poteto/whalebird-desktop
synced 2025-02-06 20:33:33 +01:00
refs #197 Manage unread statuses in local
This commit is contained in:
parent
575a9eb043
commit
195bc073a2
@ -1,5 +1,6 @@
|
||||
<template>
|
||||
<div id="local">
|
||||
<div class="unread">{{ unread.length > 0 ? unread.length : '' }}</div>
|
||||
<div class="local-timeline" v-for="message in timeline" v-bind:key="message.id">
|
||||
<toot :message="message" v-on:update="updateToot"></toot>
|
||||
</div>
|
||||
@ -19,7 +20,9 @@ export default {
|
||||
...mapState({
|
||||
timeline: state => state.TimelineSpace.Contents.Local.timeline,
|
||||
lazyLoading: state => state.TimelineSpace.Contents.Local.lazyLoading,
|
||||
backgroundColor: state => state.App.theme.background_color
|
||||
backgroundColor: state => state.App.theme.background_color,
|
||||
heading: state => state.TimelineSpace.Contents.Local.heading,
|
||||
unread: state => state.TimelineSpace.Contents.Local.unreadTimeline
|
||||
})
|
||||
},
|
||||
created () {
|
||||
@ -42,9 +45,13 @@ export default {
|
||||
this.$store.dispatch('TimelineSpace/Contents/Local/stopLocalStreaming')
|
||||
},
|
||||
destroyed () {
|
||||
this.$store.commit('TimelineSpace/Contents/Local/updateTimeline', [])
|
||||
this.$store.commit('TimelineSpace/Contents/Local/changeHeading', true)
|
||||
this.$store.commit('TimelineSpace/Contents/Local/mergeTimeline')
|
||||
this.$store.commit('TimelineSpace/Contents/Local/archiveTimeline')
|
||||
this.$store.commit('TimelineSpace/Contents/Local/clearTimeline')
|
||||
if (document.getElementById('scrollable') !== undefined && document.getElementById('scrollable') !== null) {
|
||||
document.getElementById('scrollable').removeEventListener('scroll', this.onScroll)
|
||||
document.getElementById('scrollable').scrollTop = 0
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@ -78,17 +85,40 @@ export default {
|
||||
})
|
||||
})
|
||||
}
|
||||
// for unread control
|
||||
if ((event.target.scrollTop > 10) && this.heading) {
|
||||
this.$store.commit('TimelineSpace/Contents/Local/changeHeading', false)
|
||||
} else if ((event.target.scrollTop <= 10) && !this.heading) {
|
||||
this.$store.commit('TimelineSpace/Contents/Local/changeHeading', true)
|
||||
this.$store.commit('TimelineSpace/Contents/Local/mergeTimeline')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.loading-card {
|
||||
height: 60px;
|
||||
}
|
||||
#local {
|
||||
.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;
|
||||
|
||||
.loading-card:empty {
|
||||
height: 0;
|
||||
&:empty {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.loading-card {
|
||||
height: 60px;
|
||||
}
|
||||
|
||||
.loading-card:empty {
|
||||
height: 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
@ -5,18 +5,38 @@ const Local = {
|
||||
namespaced: true,
|
||||
state: {
|
||||
timeline: [],
|
||||
lazyLoading: false
|
||||
unreadTimeline: [],
|
||||
lazyLoading: false,
|
||||
heading: true
|
||||
},
|
||||
mutations: {
|
||||
changeHeading (state, value) {
|
||||
state.heading = value
|
||||
},
|
||||
appendTimeline (state, update) {
|
||||
state.timeline = [update].concat(state.timeline)
|
||||
if (state.heading) {
|
||||
state.timeline = [update].concat(state.timeline)
|
||||
} else {
|
||||
state.unreadTimeline = [update].concat(state.unreadTimeline)
|
||||
}
|
||||
},
|
||||
updateTimeline (state, messages) {
|
||||
state.timeline = messages
|
||||
},
|
||||
mergeTimeline (state) {
|
||||
state.timeline = state.unreadTimeline.concat(state.timeline)
|
||||
state.unreadTimeline = []
|
||||
},
|
||||
insertTimeline (state, messages) {
|
||||
state.timeline = state.timeline.concat(messages)
|
||||
},
|
||||
archiveTimeline (state) {
|
||||
state.timeline = state.timeline.slice(0, 40)
|
||||
},
|
||||
clearTimeline (state) {
|
||||
state.timeline = []
|
||||
state.unreadTimeline = []
|
||||
},
|
||||
updateToot (state, message) {
|
||||
state.timeline = state.timeline.map((toot) => {
|
||||
if (toot.id === message.id) {
|
||||
@ -56,6 +76,9 @@ const Local = {
|
||||
startLocalStreaming ({ state, commit, rootState }) {
|
||||
ipcRenderer.on('update-start-local-streaming', (event, update) => {
|
||||
commit('appendTimeline', update)
|
||||
if (state.heading && Math.random() > 0.8) {
|
||||
commit('archiveTimeline')
|
||||
}
|
||||
})
|
||||
return new Promise((resolve, reject) => {
|
||||
ipcRenderer.send('start-local-streaming', rootState.TimelineSpace.account)
|
||||
|
Loading…
x
Reference in New Issue
Block a user