refs #197 Manage unread statuses in public

This commit is contained in:
AkiraFukushima 2018-04-21 14:50:09 +09:00
parent 195bc073a2
commit a6760117ad
2 changed files with 62 additions and 9 deletions

View File

@ -1,5 +1,6 @@
<template> <template>
<div id="public"> <div id="public">
<div class="unread">{{ unread.length > 0 ? unread.length : '' }}</div>
<div class="public-timeline" v-for="message in timeline" v-bind:key="message.id"> <div class="public-timeline" v-for="message in timeline" v-bind:key="message.id">
<toot :message="message" v-on:update="updateToot"></toot> <toot :message="message" v-on:update="updateToot"></toot>
</div> </div>
@ -19,7 +20,9 @@ export default {
...mapState({ ...mapState({
timeline: state => state.TimelineSpace.Contents.Public.timeline, timeline: state => state.TimelineSpace.Contents.Public.timeline,
lazyLoading: state => state.TimelineSpace.Contents.Public.lazyLoading, lazyLoading: state => state.TimelineSpace.Contents.Public.lazyLoading,
backgroundColor: state => state.App.theme.background_color backgroundColor: state => state.App.theme.background_color,
heading: state => state.TimelineSpace.Contents.Public.heading,
unread: state => state.TimelineSpace.Contents.Public.unreadTimeline
}) })
}, },
created () { created () {
@ -42,9 +45,13 @@ export default {
this.$store.dispatch('TimelineSpace/Contents/Public/stopPublicStreaming') this.$store.dispatch('TimelineSpace/Contents/Public/stopPublicStreaming')
}, },
destroyed () { destroyed () {
this.$store.commit('TimelineSpace/Contents/Public/updateTimeline', []) this.$store.commit('TimelineSpace/Contents/Public/changeHeading', true)
this.$store.commit('TimelineSpace/Contents/Public/mergeTimeline')
this.$store.commit('TimelineSpace/Contents/Public/archiveTimeline')
this.$store.commit('TimelineSpace/Contents/Public/clearTimeline')
if (document.getElementById('scrollable') !== undefined && document.getElementById('scrollable') !== null) { if (document.getElementById('scrollable') !== undefined && document.getElementById('scrollable') !== null) {
document.getElementById('scrollable').removeEventListener('scroll', this.onScroll) document.getElementById('scrollable').removeEventListener('scroll', this.onScroll)
document.getElementById('scrollable').scrollTop = 0
} }
}, },
methods: { methods: {
@ -78,17 +85,40 @@ export default {
}) })
}) })
} }
// for unread control
if ((event.target.scrollTop > 10) && this.heading) {
this.$store.commit('TimelineSpace/Contents/Public/changeHeading', false)
} else if ((event.target.scrollTop <= 10) && !this.heading) {
this.$store.commit('TimelineSpace/Contents/Public/changeHeading', true)
this.$store.commit('TimelineSpace/Contents/Public/mergeTimeline')
}
} }
} }
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.loading-card { #public {
height: 60px; .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 { &:empty {
height: 0; display: none;
}
}
.loading-card {
height: 60px;
}
.loading-card:empty {
height: 0;
}
} }
</style> </style>

View File

@ -5,18 +5,38 @@ const Public = {
namespaced: true, namespaced: true,
state: { state: {
timeline: [], timeline: [],
lazyLoading: false unreadTimeline: [],
lazyLoading: false,
heading: true
}, },
mutations: { mutations: {
changeHeading (state, value) {
state.heading = value
},
appendTimeline (state, update) { 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) { updateTimeline (state, messages) {
state.timeline = messages state.timeline = messages
}, },
mergeTimeline (state, messages) {
state.timeline = state.unreadTimeline.concat(state.timeline)
state.unreadTimeline = []
},
insertTimeline (state, messages) { insertTimeline (state, messages) {
state.timeline = state.timeline.concat(messages) state.timeline = state.timeline.concat(messages)
}, },
archiveTimeline (state, messages) {
state.timeline = state.timeline.slice(0, 40)
},
clearTimeline (state) {
state.timeline = []
state.unreadTimeline = []
},
updateToot (state, message) { updateToot (state, message) {
state.timeline = state.timeline.map((toot) => { state.timeline = state.timeline.map((toot) => {
if (toot.id === message.id) { if (toot.id === message.id) {
@ -56,6 +76,9 @@ const Public = {
startPublicStreaming ({ state, commit, rootState }) { startPublicStreaming ({ state, commit, rootState }) {
ipcRenderer.on('update-start-public-streaming', (event, update) => { ipcRenderer.on('update-start-public-streaming', (event, update) => {
commit('appendTimeline', update) commit('appendTimeline', update)
if (state.heading && Math.random() > 0.8) {
commit('archiveTimeline')
}
}) })
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
ipcRenderer.send('start-public-streaming', rootState.TimelineSpace.account) ipcRenderer.send('start-public-streaming', rootState.TimelineSpace.account)