Remove unread timeline and fix scroll position in public
This commit is contained in:
parent
804ce36a1f
commit
5d7bc9f9dd
|
@ -117,8 +117,7 @@ let state = (): PublicState => {
|
|||
return {
|
||||
lazyLoading: false,
|
||||
heading: true,
|
||||
timeline: [],
|
||||
unreadTimeline: []
|
||||
timeline: []
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -180,7 +179,6 @@ describe('Home', () => {
|
|||
lazyLoading: false,
|
||||
heading: true,
|
||||
timeline: [status1],
|
||||
unreadTimeline: [],
|
||||
showReblogs: true,
|
||||
showReplies: true
|
||||
}
|
||||
|
|
|
@ -136,8 +136,7 @@ describe('TimelineSpace/Contents/Local', () => {
|
|||
state = {
|
||||
lazyLoading: false,
|
||||
heading: true,
|
||||
timeline: [status2, status1],
|
||||
unreadTimeline: []
|
||||
timeline: [status2, status1]
|
||||
}
|
||||
})
|
||||
it('should be deleted', () => {
|
||||
|
@ -151,8 +150,7 @@ describe('TimelineSpace/Contents/Local', () => {
|
|||
state = {
|
||||
lazyLoading: false,
|
||||
heading: true,
|
||||
timeline: [status2, rebloggedStatus],
|
||||
unreadTimeline: []
|
||||
timeline: [status2, rebloggedStatus]
|
||||
}
|
||||
})
|
||||
it('should be deleted', () => {
|
||||
|
@ -169,14 +167,12 @@ describe('TimelineSpace/Contents/Local', () => {
|
|||
state = {
|
||||
lazyLoading: false,
|
||||
heading: true,
|
||||
timeline: [status2, status1],
|
||||
unreadTimeline: []
|
||||
timeline: [status2, status1]
|
||||
}
|
||||
})
|
||||
it('should be updated timeline', () => {
|
||||
Public.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, rebloggedStatus)
|
||||
expect(state.timeline).toEqual([rebloggedStatus, status2, status1])
|
||||
expect(state.unreadTimeline).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -185,14 +181,12 @@ describe('TimelineSpace/Contents/Local', () => {
|
|||
state = {
|
||||
lazyLoading: false,
|
||||
heading: true,
|
||||
timeline: [rebloggedStatus, status2, status1],
|
||||
unreadTimeline: []
|
||||
timeline: [rebloggedStatus, status2, status1]
|
||||
}
|
||||
})
|
||||
it('should not be updated timeline', () => {
|
||||
Public.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, rebloggedStatus)
|
||||
expect(state.timeline).toEqual([rebloggedStatus, status2, status1])
|
||||
expect(state.unreadTimeline).toEqual([])
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -203,14 +197,12 @@ describe('TimelineSpace/Contents/Local', () => {
|
|||
state = {
|
||||
lazyLoading: false,
|
||||
heading: false,
|
||||
timeline: [status2, status1],
|
||||
unreadTimeline: []
|
||||
timeline: [status2, status1]
|
||||
}
|
||||
})
|
||||
it('should be updated timeline', () => {
|
||||
Public.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, rebloggedStatus)
|
||||
expect(state.timeline).toEqual([status2, status1])
|
||||
expect(state.unreadTimeline).toEqual([rebloggedStatus])
|
||||
expect(state.timeline).toEqual([rebloggedStatus, status2, status1])
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -219,14 +211,12 @@ describe('TimelineSpace/Contents/Local', () => {
|
|||
state = {
|
||||
lazyLoading: false,
|
||||
heading: false,
|
||||
timeline: [rebloggedStatus, status2, status1],
|
||||
unreadTimeline: []
|
||||
timeline: [rebloggedStatus, status2, status1]
|
||||
}
|
||||
})
|
||||
it('should not be updated timeline', () => {
|
||||
Public.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, rebloggedStatus)
|
||||
expect(state.timeline).toEqual([rebloggedStatus, status2, status1])
|
||||
expect(state.unreadTimeline).toEqual([])
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
<template>
|
||||
<div id="public" v-shortkey="shortcutEnabled ? { next: ['j'] } : {}" @shortkey="handleKey">
|
||||
<div class="unread">{{ unread.length > 0 ? unread.length : '' }}</div>
|
||||
<div v-shortkey="{ linux: ['ctrl', 'r'], mac: ['meta', 'r'] }" @shortkey="reload()"></div>
|
||||
<DynamicScroller :items="timeline" :min-item-size="60" id="scroller" class="scroller" ref="scroller">
|
||||
<DynamicScroller :items="timeline" :min-item-size="86" id="scroller" class="scroller" ref="scroller">
|
||||
<template v-slot="{ item, index, active }">
|
||||
<DynamicScrollerItem :item="item" :active="active" :size-dependencies="[item.uri]" :data-index="index" :watchData="true">
|
||||
<toot
|
||||
|
@ -32,6 +31,7 @@ import { mapState, mapGetters } from 'vuex'
|
|||
import Toot from '~/src/renderer/components/organisms/Toot'
|
||||
import reloadable from '~/src/renderer/components/mixins/reloadable'
|
||||
import { Event } from '~/src/renderer/components/event'
|
||||
import { ScrollPosition } from '~/src/renderer/components/utils/scroll'
|
||||
|
||||
export default {
|
||||
name: 'public',
|
||||
|
@ -39,15 +39,15 @@ export default {
|
|||
mixins: [reloadable],
|
||||
data() {
|
||||
return {
|
||||
focusedId: null
|
||||
focusedId: null,
|
||||
scroll: null
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
...mapState('TimelineSpace/Contents/Public', {
|
||||
timeline: state => state.timeline,
|
||||
lazyLoading: state => state.lazyLoading,
|
||||
heading: state => state.heading,
|
||||
unread: state => state.unreadTimeline
|
||||
heading: state => state.heading
|
||||
}),
|
||||
...mapState({
|
||||
openSideBar: state => state.TimelineSpace.Contents.SideBar.openSideBar,
|
||||
|
@ -87,11 +87,24 @@ export default {
|
|||
this.focusedId = previousFocusedId
|
||||
})
|
||||
})
|
||||
const el = document.getElementById('scroller')
|
||||
this.scroll = new ScrollPosition(el)
|
||||
this.scroll.prepare()
|
||||
},
|
||||
beforeUpdate() {
|
||||
if (this.$store.state.TimelineSpace.SideMenu.unreadPublicTimeline && this.heading) {
|
||||
this.$store.commit('TimelineSpace/SideMenu/changeUnreadPublicTimeline', false)
|
||||
}
|
||||
if (!this.heading) {
|
||||
const el = document.getElementById('scroller')
|
||||
this.scroll = new ScrollPosition(el)
|
||||
this.scroll.prepare()
|
||||
}
|
||||
},
|
||||
updated() {
|
||||
if (this.scroll && !this.heading) {
|
||||
this.scroll.restore()
|
||||
}
|
||||
},
|
||||
beforeDestroy() {
|
||||
if (!this.unreadNotification.public) {
|
||||
|
@ -102,7 +115,6 @@ export default {
|
|||
},
|
||||
destroyed() {
|
||||
this.$store.commit('TimelineSpace/Contents/Public/changeHeading', true)
|
||||
this.$store.commit('TimelineSpace/Contents/Public/mergeTimeline')
|
||||
this.$store.commit('TimelineSpace/Contents/Public/archiveTimeline')
|
||||
if (!this.unreadNotification.public) {
|
||||
this.$store.commit('TimelineSpace/Contents/Public/clearTimeline')
|
||||
|
@ -125,7 +137,6 @@ export default {
|
|||
this.$store.commit('TimelineSpace/Contents/Public/changeHeading', false)
|
||||
} else if (newState === null && !this.heading) {
|
||||
this.$store.commit('TimelineSpace/Contents/Public/changeHeading', true)
|
||||
this.$store.commit('TimelineSpace/Contents/Public/mergeTimeline')
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -158,17 +169,12 @@ export default {
|
|||
})
|
||||
})
|
||||
}
|
||||
// for unread control
|
||||
if (event.target.scrollTop > 5 && this.heading) {
|
||||
|
||||
if (event.target.scrollTop > 10 && this.heading) {
|
||||
this.$store.commit('TimelineSpace/Contents/Public/changeHeading', false)
|
||||
} else if (event.target.scrollTop <= 5 && !this.heading) {
|
||||
const currentPos = this.unread.length
|
||||
if (currentPos === 0) {
|
||||
} else if (event.target.scrollTop <= 10 && !this.heading) {
|
||||
this.$store.commit('TimelineSpace/Contents/Public/changeHeading', true)
|
||||
}
|
||||
this.$store.commit('TimelineSpace/Contents/Public/mergeTimeline')
|
||||
this.$refs.scroller.scrollToItem(currentPos)
|
||||
}
|
||||
},
|
||||
async reload() {
|
||||
this.$store.commit('TimelineSpace/changeLoading', true)
|
||||
|
@ -225,21 +231,6 @@ export default {
|
|||
height: 100%;
|
||||
}
|
||||
|
||||
.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;
|
||||
z-index: 1;
|
||||
|
||||
&:empty {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.loading-card {
|
||||
height: 60px;
|
||||
}
|
||||
|
|
|
@ -35,3 +35,21 @@ export default function scrollTop (element, point = 0) {
|
|||
const easeOut = function (p) {
|
||||
return p * (2 - p)
|
||||
}
|
||||
|
||||
export class ScrollPosition {
|
||||
node = null
|
||||
previousScrollHeightMinusTop = 0
|
||||
|
||||
constructor(node) {
|
||||
this.node = node
|
||||
this.previousScrollHeightMinusTop = 0
|
||||
}
|
||||
|
||||
prepare() {
|
||||
this.previousScrollHeightMinusTop = this.node.scrollHeight - this.node.scrollTop
|
||||
}
|
||||
|
||||
restore() {
|
||||
this.node.scrollTop = this.node.scrollHeight - this.previousScrollHeightMinusTop
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,14 +4,12 @@ import { RootState } from '@/store'
|
|||
|
||||
export type PublicState = {
|
||||
timeline: Array<Entity.Status>
|
||||
unreadTimeline: Array<Entity.Status>
|
||||
lazyLoading: boolean
|
||||
heading: boolean
|
||||
}
|
||||
|
||||
const state = (): PublicState => ({
|
||||
timeline: [],
|
||||
unreadTimeline: [],
|
||||
lazyLoading: false,
|
||||
heading: true
|
||||
})
|
||||
|
@ -20,7 +18,6 @@ export const MUTATION_TYPES = {
|
|||
CHANGE_HEADING: 'changeHeading',
|
||||
APPEND_TIMELINE: 'appendTimeline',
|
||||
UPDATE_TIMELINE: 'updateTimeline',
|
||||
MERGE_TIMELINE: 'mergeTimeline',
|
||||
INSERT_TIMELINE: 'insertTimeline',
|
||||
ARCHIVE_TIMELINE: 'archiveTimeline',
|
||||
CLEAR_TIMELINE: 'clearTimeline',
|
||||
|
@ -35,21 +32,13 @@ const mutations: MutationTree<PublicState> = {
|
|||
},
|
||||
[MUTATION_TYPES.APPEND_TIMELINE]: (state, update: Entity.Status) => {
|
||||
// Reject duplicated status in timeline
|
||||
if (!state.timeline.find(item => item.id === update.id) && !state.unreadTimeline.find(item => item.id === update.id)) {
|
||||
if (state.heading) {
|
||||
if (!state.timeline.find(item => item.id === update.id)) {
|
||||
state.timeline = [update].concat(state.timeline)
|
||||
} else {
|
||||
state.unreadTimeline = [update].concat(state.unreadTimeline)
|
||||
}
|
||||
}
|
||||
},
|
||||
[MUTATION_TYPES.UPDATE_TIMELINE]: (state, messages: Array<Entity.Status>) => {
|
||||
state.timeline = messages
|
||||
},
|
||||
[MUTATION_TYPES.MERGE_TIMELINE]: state => {
|
||||
state.timeline = state.unreadTimeline.slice(0, 80).concat(state.timeline)
|
||||
state.unreadTimeline = []
|
||||
},
|
||||
[MUTATION_TYPES.INSERT_TIMELINE]: (state, messages: Array<Entity.Status>) => {
|
||||
state.timeline = state.timeline.concat(messages)
|
||||
},
|
||||
|
@ -58,7 +47,6 @@ const mutations: MutationTree<PublicState> = {
|
|||
},
|
||||
[MUTATION_TYPES.CLEAR_TIMELINE]: state => {
|
||||
state.timeline = []
|
||||
state.unreadTimeline = []
|
||||
},
|
||||
[MUTATION_TYPES.UPDATE_TOOT]: (state, message: Entity.Status) => {
|
||||
state.timeline = state.timeline.map(toot => {
|
||||
|
|
Loading…
Reference in New Issue