From 04084ca549c1714ae1f8f71fc3bc2d21efb90d64 Mon Sep 17 00:00:00 2001 From: AkiraFukushima Date: Sun, 11 Dec 2022 19:43:37 +0900 Subject: [PATCH] Revert modifying scroll position in DM --- .../TimelineSpace/Contents/DirectMessages.vue | 69 ++----------------- .../TimelineSpace/Contents/DirectMessages.ts | 8 +-- 2 files changed, 7 insertions(+), 70 deletions(-) diff --git a/src/renderer/components/TimelineSpace/Contents/DirectMessages.vue b/src/renderer/components/TimelineSpace/Contents/DirectMessages.vue index 83df5647..a4a83517 100644 --- a/src/renderer/components/TimelineSpace/Contents/DirectMessages.vue +++ b/src/renderer/components/TimelineSpace/Contents/DirectMessages.vue @@ -13,7 +13,6 @@ v-on:delete="deleteToot" @focusRight="focusSidebar" @selectToot="focusToot(item)" - @sizeChanged="sizeChanged" > @@ -39,7 +38,6 @@ import { Entity } from 'megalodon' import useReloadable from '@/components/utils/reloadable' import Toot from '@/components/organisms/Toot.vue' import { EventEmitter } from '@/components/event' -import { ScrollPosition } from '@/components/utils/scroll' import { ACTION_TYPES, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/DirectMessages' import { MUTATION_TYPES as SIDE_MENU_MUTATION } from '@/store/TimelineSpace/SideMenu' import { MUTATION_TYPES as TIMELINE_MUTATION, ACTION_TYPES as TIMELINE_ACTION } from '@/store/TimelineSpace' @@ -58,10 +56,6 @@ export default defineComponent({ const { j, k, Ctrl_r } = useMagicKeys() const focusedId = ref(null) - const scrollPosition = ref(null) - const observer = ref(null) - const resizeTime = ref(null) - const scrollTime = ref(null) const scroller = ref() const timeline = computed(() => store.state.TimelineSpace.Contents.DirectMessages.timeline) @@ -84,27 +78,11 @@ export default defineComponent({ store.commit(`TimelineSpace/Contents/${CONTENTS_ACTION.CHANGE_LOADING}`, false) }) } - const el = document.getElementById('scroller') - if (el) { - scrollPosition.value = new ScrollPosition(el) - scrollPosition.value.prepare() - observer.value = new ResizeObserver(() => { - if (scrollPosition.value && !heading.value && !lazyLoading.value && !scrolling.value) { - resizeTime.value = moment() - scrollPosition.value?.restore() - } - }) - const scrollWrapper = el.getElementsByClassName('vue-recycle-scroller__item-wrapper')[0] - observer.value.observe(scrollWrapper) - } }) onBeforeUpdate(() => { if (store.state.TimelineSpace.SideMenu.unreadDirectMessagesTimeline && heading.value) { store.commit(`TimelineSpace/SideMenu/${SIDE_MENU_MUTATION.CHANGE_UNREAD_DIRECT_MESSAGES_TIMELINE}`, false) } - if (scrollPosition.value) { - scrollPosition.value.prepare() - } }) onBeforeUnmount(() => { if (!unreadNotification.value.direct) { @@ -158,38 +136,18 @@ export default defineComponent({ store.dispatch(`TimelineSpace/${TIMELINE_ACTION.START_DIRECT_MESSAGES_STREAMING}`) } const onScroll = (event: Event) => { - if (moment().diff(resizeTime.value) < 500) { - return - } - scrollTime.value = moment() - if (!scrolling.value) { - store.commit(`${space}/${MUTATION_TYPES.CHANGE_SCROLLING}`, true) - } // for lazyLoading if ( (event.target as HTMLElement)!.clientHeight + (event.target as HTMLElement)!.scrollTop >= document.getElementById('scroller')!.scrollHeight - 10 && !lazyLoading.value ) { - store - .dispatch(`${space}/${ACTION_TYPES.LAZY_FETCH_TIMELINE}`, timeline.value[timeline.value.length - 1]) - .then(statuses => { - if (statuses === null) { - return - } - if (statuses.length > 0) { - store.commit(`${space}/${MUTATION_TYPES.CHANGE_SCROLLING}`, true) - setTimeout(() => { - store.commit(`${space}/${MUTATION_TYPES.CHANGE_SCROLLING}`, false) - }, 500) - } - }) - .catch(() => { - ElMessage({ - message: i18n.t('message.timeline_fetch_error'), - type: 'error' - }) + store.dispatch(`${space}/${ACTION_TYPES.LAZY_FETCH_TIMELINE}`, timeline.value[timeline.value.length - 1]).catch(() => { + ElMessage({ + message: i18n.t('message.timeline_fetch_error'), + type: 'error' }) + }) } if ((event.target as HTMLElement)!.scrollTop > 10 && heading.value) { @@ -197,14 +155,6 @@ export default defineComponent({ } else if ((event.target as HTMLElement)!.scrollTop <= 10 && !heading.value) { store.commit(`${space}/${MUTATION_TYPES.CHANGE_HEADING}`, true) } - - setTimeout(() => { - const now = moment() - if (now.diff(scrollTime.value) >= 150) { - scrollTime.value = null - store.commit(`${space}/${MUTATION_TYPES.CHANGE_SCROLLING}`, false) - } - }, 150) } const updateToot = (message: Entity.Status) => { store.commit(`${space}/${MUTATION_TYPES.UPDATE_TOOT}`, message) @@ -244,12 +194,6 @@ export default defineComponent({ const focusSidebar = () => { EventEmitter.emit('focus-sidebar') } - const sizeChanged = () => { - store.commit(`${space}/${MUTATION_TYPES.CHANGE_SCROLLING}`, true) - setTimeout(() => { - store.commit(`${space}/${MUTATION_TYPES.CHANGE_SCROLLING}`, false) - }, 500) - } return { timeline, @@ -262,8 +206,7 @@ export default defineComponent({ focusToot, openSideBar, heading, - upper, - sizeChanged + upper } } }) diff --git a/src/renderer/store/TimelineSpace/Contents/DirectMessages.ts b/src/renderer/store/TimelineSpace/Contents/DirectMessages.ts index ff9b684d..3a8185d6 100644 --- a/src/renderer/store/TimelineSpace/Contents/DirectMessages.ts +++ b/src/renderer/store/TimelineSpace/Contents/DirectMessages.ts @@ -5,14 +5,12 @@ import { RootState } from '@/store' export type DirectMessagesState = { lazyLoading: boolean heading: boolean - scrolling: boolean timeline: Array } const state = (): DirectMessagesState => ({ lazyLoading: false, heading: true, - scrolling: false, timeline: [] }) @@ -25,8 +23,7 @@ export const MUTATION_TYPES = { ARCHIVE_TIMELINE: 'archiveTimeline', CLEAR_TIMELINE: 'clearTimeline', UPDATE_TOOT: 'updateToot', - DELETE_TOOT: 'deleteToot', - CHANGE_SCROLLING: 'changeScrolling' + DELETE_TOOT: 'deleteToot' } const mutations: MutationTree = { @@ -79,9 +76,6 @@ const mutations: MutationTree = { return toot.id !== id } }) - }, - [MUTATION_TYPES.CHANGE_SCROLLING]: (state, value: boolean) => { - state.scrolling = value } }