From 4fdc2f90de9f9f5ba1ad12eb99c6de7465251ccb Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Sun, 25 Jul 2021 21:16:28 +0900
Subject: [PATCH] Remove unread timeline and fix scroll position in local
---
.../TimelineSpace/Contents/Local.spec.ts | 3 +-
.../TimelineSpace/Contents/Local.spec.ts | 24 +++------
.../TimelineSpace/Contents/Local.vue | 52 ++++++++-----------
.../store/TimelineSpace/Contents/Local.ts | 16 +-----
4 files changed, 31 insertions(+), 64 deletions(-)
diff --git a/spec/renderer/integration/store/TimelineSpace/Contents/Local.spec.ts b/spec/renderer/integration/store/TimelineSpace/Contents/Local.spec.ts
index 7ab103ea..b2dc2cc8 100644
--- a/spec/renderer/integration/store/TimelineSpace/Contents/Local.spec.ts
+++ b/spec/renderer/integration/store/TimelineSpace/Contents/Local.spec.ts
@@ -117,8 +117,7 @@ let state = (): LocalState => {
return {
lazyLoading: false,
heading: true,
- timeline: [],
- unreadTimeline: []
+ timeline: []
}
}
diff --git a/spec/renderer/unit/store/TimelineSpace/Contents/Local.spec.ts b/spec/renderer/unit/store/TimelineSpace/Contents/Local.spec.ts
index 18d54fc9..f80b1aef 100644
--- a/spec/renderer/unit/store/TimelineSpace/Contents/Local.spec.ts
+++ b/spec/renderer/unit/store/TimelineSpace/Contents/Local.spec.ts
@@ -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', () => {
@@ -168,14 +166,12 @@ describe('TimelineSpace/Contents/Local', () => {
state = {
lazyLoading: false,
heading: true,
- timeline: [status2, status1],
- unreadTimeline: []
+ timeline: [status2, status1]
}
})
it('should be updated timeline', () => {
Local.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, rebloggedStatus)
expect(state.timeline).toEqual([rebloggedStatus, status2, status1])
- expect(state.unreadTimeline).toEqual([])
})
})
@@ -184,14 +180,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', () => {
Local.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, rebloggedStatus)
expect(state.timeline).toEqual([rebloggedStatus, status2, status1])
- expect(state.unreadTimeline).toEqual([])
})
})
})
@@ -202,14 +196,12 @@ describe('TimelineSpace/Contents/Local', () => {
state = {
lazyLoading: false,
heading: false,
- timeline: [status2, status1],
- unreadTimeline: []
+ timeline: [status2, status1]
}
})
it('should be updated timeline', () => {
Local.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])
})
})
@@ -218,14 +210,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', () => {
Local.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, rebloggedStatus)
expect(state.timeline).toEqual([rebloggedStatus, status2, status1])
- expect(state.unreadTimeline).toEqual([])
})
})
})
diff --git a/src/renderer/components/TimelineSpace/Contents/Local.vue b/src/renderer/components/TimelineSpace/Contents/Local.vue
index 1c76fbda..7fe8b575 100644
--- a/src/renderer/components/TimelineSpace/Contents/Local.vue
+++ b/src/renderer/components/TimelineSpace/Contents/Local.vue
@@ -1,8 +1,7 @@
-
{{ unread.length > 0 ? unread.length : '' }}
-
+
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,
@@ -86,11 +86,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.unreadLocalTimeline && this.heading) {
this.$store.commit('TimelineSpace/SideMenu/changeUnreadLocalTimeline', 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.local) {
@@ -101,7 +114,6 @@ export default {
},
destroyed() {
this.$store.commit('TimelineSpace/Contents/Local/changeHeading', true)
- this.$store.commit('TimelineSpace/Contents/Local/mergeTimeline')
this.$store.commit('TimelineSpace/Contents/Local/archiveTimeline')
if (!this.unreadNotification.local) {
this.$store.commit('TimelineSpace/Contents/Local/clearTimeline')
@@ -124,7 +136,6 @@ export default {
this.$store.commit('TimelineSpace/Contents/Local/changeHeading', false)
} else if (newState === null && !this.heading) {
this.$store.commit('TimelineSpace/Contents/Local/changeHeading', true)
- this.$store.commit('TimelineSpace/Contents/Local/mergeTimeline')
}
}
},
@@ -157,16 +168,10 @@ export default {
})
})
}
- // for unread control
- if (event.target.scrollTop > 5 && this.heading) {
+ if (event.target.scrollTop > 10 && this.heading) {
this.$store.commit('TimelineSpace/Contents/Local/changeHeading', false)
- } else if (event.target.scrollTop <= 5 && !this.heading) {
- const currentPos = this.unread.length
- if (currentPos === 0) {
- this.$store.commit('TimelineSpace/Contents/Local/changeHeading', true)
- }
- this.$store.commit('TimelineSpace/Contents/Local/mergeTimeline')
- this.$refs.scroller.scrollToItem(currentPos)
+ } else if (event.target.scrollTop <= 10 && !this.heading) {
+ this.$store.commit('TimelineSpace/Contents/Local/changeHeading', true)
}
},
async reload() {
@@ -224,21 +229,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;
}
diff --git a/src/renderer/store/TimelineSpace/Contents/Local.ts b/src/renderer/store/TimelineSpace/Contents/Local.ts
index 0102139b..ced86ea2 100644
--- a/src/renderer/store/TimelineSpace/Contents/Local.ts
+++ b/src/renderer/store/TimelineSpace/Contents/Local.ts
@@ -4,14 +4,12 @@ import { RootState } from '@/store'
export type LocalState = {
timeline: Array
- unreadTimeline: Array
lazyLoading: boolean
heading: boolean
}
const state = (): LocalState => ({
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 = {
},
[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) {
- state.timeline = [update].concat(state.timeline)
- } else {
- state.unreadTimeline = [update].concat(state.unreadTimeline)
- }
+ if (!state.timeline.find(item => item.id === update.id)) {
+ state.timeline = [update].concat(state.timeline)
}
},
[MUTATION_TYPES.UPDATE_TIMELINE]: (state, messages: Array) => {
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) => {
state.timeline = state.timeline.concat(messages)
},
@@ -58,7 +47,6 @@ const mutations: MutationTree = {
},
[MUTATION_TYPES.CLEAR_TIMELINE]: state => {
state.timeline = []
- state.unreadTimeline = []
},
[MUTATION_TYPES.UPDATE_TOOT]: (state, message: Entity.Status) => {
state.timeline = state.timeline.map(toot => {