From 5d7bc9f9ddb9021c2dfeb15d4a300ac213c23936 Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Sun, 25 Jul 2021 21:01:12 +0900
Subject: [PATCH] Remove unread timeline and fix scroll position in public
---
.../TimelineSpace/Contents/Public.spec.ts | 4 +-
.../TimelineSpace/Contents/Public.spec.ts | 24 +++------
.../TimelineSpace/Contents/Public.vue | 53 ++++++++-----------
src/renderer/components/utils/scroll.js | 20 ++++++-
.../store/TimelineSpace/Contents/Public.ts | 16 +-----
5 files changed, 51 insertions(+), 66 deletions(-)
diff --git a/spec/renderer/integration/store/TimelineSpace/Contents/Public.spec.ts b/spec/renderer/integration/store/TimelineSpace/Contents/Public.spec.ts
index 67836cf8..13735fae 100644
--- a/spec/renderer/integration/store/TimelineSpace/Contents/Public.spec.ts
+++ b/spec/renderer/integration/store/TimelineSpace/Contents/Public.spec.ts
@@ -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
}
diff --git a/spec/renderer/unit/store/TimelineSpace/Contents/Public.spec.ts b/spec/renderer/unit/store/TimelineSpace/Contents/Public.spec.ts
index 7aea60c0..3b1b096c 100644
--- a/spec/renderer/unit/store/TimelineSpace/Contents/Public.spec.ts
+++ b/spec/renderer/unit/store/TimelineSpace/Contents/Public.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', () => {
@@ -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([])
})
})
})
diff --git a/src/renderer/components/TimelineSpace/Contents/Public.vue b/src/renderer/components/TimelineSpace/Contents/Public.vue
index 3c34417b..7be5890d 100644
--- a/src/renderer/components/TimelineSpace/Contents/Public.vue
+++ b/src/renderer/components/TimelineSpace/Contents/Public.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,
@@ -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,16 +169,11 @@ 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) {
- this.$store.commit('TimelineSpace/Contents/Public/changeHeading', true)
- }
- this.$store.commit('TimelineSpace/Contents/Public/mergeTimeline')
- this.$refs.scroller.scrollToItem(currentPos)
+ } else if (event.target.scrollTop <= 10 && !this.heading) {
+ this.$store.commit('TimelineSpace/Contents/Public/changeHeading', true)
}
},
async reload() {
@@ -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;
}
diff --git a/src/renderer/components/utils/scroll.js b/src/renderer/components/utils/scroll.js
index b2c2591e..f6aa26ae 100644
--- a/src/renderer/components/utils/scroll.js
+++ b/src/renderer/components/utils/scroll.js
@@ -3,7 +3,7 @@
* @param element a target dom element
* @param point scroll target point of the element
**/
-export default function scrollTop (element, point = 0) {
+export default function scrollTop(element, point = 0) {
const start = element.scrollTop
const range = start - point
// Progress of scroll: 0 ~ 100
@@ -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
+ }
+}
diff --git a/src/renderer/store/TimelineSpace/Contents/Public.ts b/src/renderer/store/TimelineSpace/Contents/Public.ts
index eccb001c..2db11703 100644
--- a/src/renderer/store/TimelineSpace/Contents/Public.ts
+++ b/src/renderer/store/TimelineSpace/Contents/Public.ts
@@ -4,14 +4,12 @@ import { RootState } from '@/store'
export type PublicState = {
timeline: Array
- unreadTimeline: Array
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 = {
},
[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 => {