Revert modifying scroll position in Lists
This commit is contained in:
parent
04084ca549
commit
a82c5950a4
|
@ -13,7 +13,6 @@
|
|||
v-on:delete="deleteToot"
|
||||
@focusRight="focusSidebar"
|
||||
@selectToot="focusToot(item)"
|
||||
@sizeChanged="sizeChanged"
|
||||
>
|
||||
</toot>
|
||||
</DynamicScrollerItem>
|
||||
|
@ -37,7 +36,6 @@ import { Entity } from 'megalodon'
|
|||
import { useStore } from '@/store'
|
||||
import Toot from '@/components/organisms/Toot.vue'
|
||||
import { EventEmitter } from '@/components/event'
|
||||
import { ScrollPosition } from '@/components/utils/scroll'
|
||||
import { MUTATION_TYPES as CONTENTS_MUTATION } from '@/store/TimelineSpace/Contents'
|
||||
import { MUTATION_TYPES as HEADER_MUTATION } from '@/store/TimelineSpace/HeaderMenu'
|
||||
import { ACTION_TYPES, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/Lists/Show'
|
||||
|
@ -55,10 +53,6 @@ export default defineComponent({
|
|||
|
||||
const { list_id } = 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.Lists.Show.timeline)
|
||||
|
@ -77,27 +71,6 @@ export default defineComponent({
|
|||
load().finally(() => {
|
||||
store.commit(`TimelineSpace/Contents/${CONTENTS_MUTATION.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 (scrollPosition.value) {
|
||||
scrollPosition.value.prepare()
|
||||
}
|
||||
})
|
||||
watch(list_id, () => {
|
||||
store.commit(`TimelineSpace/Contents/${CONTENTS_MUTATION.CHANGE_LOADING}`, true)
|
||||
|
@ -135,7 +108,6 @@ export default defineComponent({
|
|||
|
||||
onBeforeUnmount(() => {
|
||||
store.dispatch(`${space}/${ACTION_TYPES.STOP_STREAMING}`)
|
||||
observer.value?.disconnect()
|
||||
})
|
||||
onUnmounted(() => {
|
||||
store.commit(`${space}/${MUTATION_TYPES.CHANGE_HEADING}`, true)
|
||||
|
@ -167,14 +139,6 @@ export default defineComponent({
|
|||
return 'started'
|
||||
}
|
||||
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 &&
|
||||
|
@ -185,17 +149,6 @@ export default defineComponent({
|
|||
list_id: list_id.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'),
|
||||
|
@ -209,14 +162,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 reload = async () => {
|
||||
store.commit(`TimelineSpace/${TIMELINE_MUTATION.CHANGE_LOADING}`, true)
|
||||
|
@ -268,12 +213,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 {
|
||||
scroller,
|
||||
|
@ -284,7 +223,6 @@ export default defineComponent({
|
|||
deleteToot,
|
||||
focusSidebar,
|
||||
focusToot,
|
||||
sizeChanged,
|
||||
openSideBar,
|
||||
heading,
|
||||
upper
|
||||
|
|
|
@ -4,20 +4,18 @@ import { RootState } from '@/store'
|
|||
import { LoadPositionWithList } 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 ShowState = {
|
||||
timeline: Array<Entity.Status>
|
||||
lazyLoading: boolean
|
||||
heading: boolean
|
||||
scrolling: boolean
|
||||
}
|
||||
|
||||
const state = (): ShowState => ({
|
||||
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<ShowState> = {
|
||||
|
@ -82,9 +79,6 @@ const mutations: MutationTree<ShowState> = {
|
|||
},
|
||||
[MUTATION_TYPES.CHANGE_LAZY_LOADING]: (state, value: boolean) => {
|
||||
state.lazyLoading = value
|
||||
},
|
||||
[MUTATION_TYPES.CHANGE_SCROLLING]: (state, value: boolean) => {
|
||||
state.scrolling = value
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue