Revert modifying scroll position in Tags

This commit is contained in:
AkiraFukushima 2022-12-11 19:48:06 +09:00
parent a82c5950a4
commit 279d06e4de
No known key found for this signature in database
GPG Key ID: B6E51BAC4DE1A957
2 changed files with 3 additions and 71 deletions

View File

@ -12,7 +12,6 @@
v-on:delete="deleteToot"
@focusRight="focusSidebar"
@selectToot="focusToot(item)"
@sizeChanged="sizeChanged"
>
</toot>
</DynamicScrollerItem>
@ -37,7 +36,6 @@ import { useRoute } from 'vue-router'
import { useStore } from '@/store'
import Toot from '@/components/organisms/Toot.vue'
import { EventEmitter } from '@/components/event'
import { ScrollPosition } from '@/components/utils/scroll'
import useReloadable from '@/components/utils/reloadable'
import { MUTATION_TYPES as TIMELINE_MUTATION } from '@/store/TimelineSpace'
import { MUTATION_TYPES as HEADER_MUTATION } from '@/store/TimelineSpace/HeaderMenu'
@ -58,10 +56,6 @@ export default defineComponent({
const { tag } = toRefs(props)
const focusedId = ref<string | null>(null)
const scrollPosition = ref<ScrollPosition | null>(null)
const observer = ref<ResizeObserver | null>(null)
const scrollTime = ref<moment.Moment | null>(null)
const resizeTime = ref<moment.Moment | null>(null)
const scroller = ref<any>(null)
const timeline = computed(() => store.state.TimelineSpace.Contents.Hashtag.Tag.timeline)
@ -80,27 +74,6 @@ export default defineComponent({
store.commit(`TimelineSpace/Contents/${CONTENTS_MUTATION.CHANGE_LOADING}`, false)
})
document.getElementById('scroller')?.addEventListener('scroll', onScroll)
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 (scrollPosition.value) {
scrollPosition.value?.prepare()
}
})
watch(tag, (newTag, _oldTag) => {
store.commit(`TimelineSpace/Contents/${CONTENTS_MUTATION.CHANGE_LOADING}`, true)
@ -141,7 +114,6 @@ export default defineComponent({
store.dispatch(`${space}/${ACTION_TYPES.STOP_STREAMING}`)
reset()
EventEmitter.off('focus-timeline')
observer.value?.disconnect()
})
const load = async (tag: string) => {
@ -170,14 +142,6 @@ export default defineComponent({
}
}
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)
}
if (
(event.target as HTMLElement)!.clientHeight + (event.target as HTMLElement)!.scrollTop >=
document.getElementById('scroller')!.scrollHeight - 10 &&
@ -188,17 +152,6 @@ export default defineComponent({
tag: tag.value,
status: 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'),
@ -212,14 +165,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 = (toot: Entity.Status) => {
store.commit(`${space}/${MUTATION_TYPES.UPDATE_TOOT}`, toot)
@ -272,12 +217,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,
@ -288,7 +227,6 @@ export default defineComponent({
deleteToot,
focusSidebar,
focusToot,
sizeChanged,
openSideBar,
heading,
upper

View File

@ -4,20 +4,18 @@ import { RootState } from '@/store'
import { LoadPositionWithTag } from '@/types/loadPosition'
import { MyWindow } from '~/src/types/global'
const win = window as any as MyWindow
const win = (window as any) as MyWindow
export type TagState = {
timeline: Array<Entity.Status>
lazyLoading: boolean
heading: boolean
scrolling: boolean
}
const state = (): TagState => ({
timeline: [],
lazyLoading: false,
heading: true,
scrolling: false
heading: true
})
export const MUTATION_TYPES = {
@ -29,8 +27,7 @@ export const MUTATION_TYPES = {
CLEAR_TIMELINE: 'clearTimeline',
UPDATE_TOOT: 'updateToot',
DELETE_TOOT: 'deleteToot',
CHANGE_LAZY_LOADING: 'changeLazyLoading',
CHANGE_SCROLLING: 'changeScrolling'
CHANGE_LAZY_LOADING: 'changeLazyLoading'
}
const mutations: MutationTree<TagState> = {
@ -82,9 +79,6 @@ const mutations: MutationTree<TagState> = {
},
[MUTATION_TYPES.CHANGE_LAZY_LOADING]: (state, value: boolean) => {
state.lazyLoading = value
},
[MUTATION_TYPES.CHANGE_SCROLLING]: (state, value: boolean) => {
state.scrolling = value
}
}