Revert modifying scroll position in Lists
This commit is contained in:
parent
04084ca549
commit
a82c5950a4
|
@ -13,7 +13,6 @@
|
||||||
v-on:delete="deleteToot"
|
v-on:delete="deleteToot"
|
||||||
@focusRight="focusSidebar"
|
@focusRight="focusSidebar"
|
||||||
@selectToot="focusToot(item)"
|
@selectToot="focusToot(item)"
|
||||||
@sizeChanged="sizeChanged"
|
|
||||||
>
|
>
|
||||||
</toot>
|
</toot>
|
||||||
</DynamicScrollerItem>
|
</DynamicScrollerItem>
|
||||||
|
@ -37,7 +36,6 @@ import { Entity } from 'megalodon'
|
||||||
import { useStore } from '@/store'
|
import { useStore } from '@/store'
|
||||||
import Toot from '@/components/organisms/Toot.vue'
|
import Toot from '@/components/organisms/Toot.vue'
|
||||||
import { EventEmitter } from '@/components/event'
|
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 CONTENTS_MUTATION } from '@/store/TimelineSpace/Contents'
|
||||||
import { MUTATION_TYPES as HEADER_MUTATION } from '@/store/TimelineSpace/HeaderMenu'
|
import { MUTATION_TYPES as HEADER_MUTATION } from '@/store/TimelineSpace/HeaderMenu'
|
||||||
import { ACTION_TYPES, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/Lists/Show'
|
import { ACTION_TYPES, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/Lists/Show'
|
||||||
|
@ -55,10 +53,6 @@ export default defineComponent({
|
||||||
|
|
||||||
const { list_id } = toRefs(props)
|
const { list_id } = toRefs(props)
|
||||||
const focusedId = ref<string | null>(null)
|
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 scroller = ref<any>(null)
|
||||||
|
|
||||||
const timeline = computed(() => store.state.TimelineSpace.Contents.Lists.Show.timeline)
|
const timeline = computed(() => store.state.TimelineSpace.Contents.Lists.Show.timeline)
|
||||||
|
@ -77,27 +71,6 @@ export default defineComponent({
|
||||||
load().finally(() => {
|
load().finally(() => {
|
||||||
store.commit(`TimelineSpace/Contents/${CONTENTS_MUTATION.CHANGE_LOADING}`, false)
|
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, () => {
|
watch(list_id, () => {
|
||||||
store.commit(`TimelineSpace/Contents/${CONTENTS_MUTATION.CHANGE_LOADING}`, true)
|
store.commit(`TimelineSpace/Contents/${CONTENTS_MUTATION.CHANGE_LOADING}`, true)
|
||||||
|
@ -135,7 +108,6 @@ export default defineComponent({
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
store.dispatch(`${space}/${ACTION_TYPES.STOP_STREAMING}`)
|
store.dispatch(`${space}/${ACTION_TYPES.STOP_STREAMING}`)
|
||||||
observer.value?.disconnect()
|
|
||||||
})
|
})
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
store.commit(`${space}/${MUTATION_TYPES.CHANGE_HEADING}`, true)
|
store.commit(`${space}/${MUTATION_TYPES.CHANGE_HEADING}`, true)
|
||||||
|
@ -167,14 +139,6 @@ export default defineComponent({
|
||||||
return 'started'
|
return 'started'
|
||||||
}
|
}
|
||||||
const onScroll = (event: Event) => {
|
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 (
|
if (
|
||||||
(event.target as HTMLElement)!.clientHeight + (event.target as HTMLElement)!.scrollTop >=
|
(event.target as HTMLElement)!.clientHeight + (event.target as HTMLElement)!.scrollTop >=
|
||||||
document.getElementById('scroller')!.scrollHeight - 10 &&
|
document.getElementById('scroller')!.scrollHeight - 10 &&
|
||||||
|
@ -185,17 +149,6 @@ export default defineComponent({
|
||||||
list_id: list_id.value,
|
list_id: list_id.value,
|
||||||
status: timeline.value[timeline.value.length - 1]
|
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(() => {
|
.catch(() => {
|
||||||
ElMessage({
|
ElMessage({
|
||||||
message: i18n.t('message.timeline_fetch_error'),
|
message: i18n.t('message.timeline_fetch_error'),
|
||||||
|
@ -209,14 +162,6 @@ export default defineComponent({
|
||||||
} else if ((event.target as HTMLElement)!.scrollTop <= 10 && !heading.value) {
|
} else if ((event.target as HTMLElement)!.scrollTop <= 10 && !heading.value) {
|
||||||
store.commit(`${space}/${MUTATION_TYPES.CHANGE_HEADING}`, true)
|
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 () => {
|
const reload = async () => {
|
||||||
store.commit(`TimelineSpace/${TIMELINE_MUTATION.CHANGE_LOADING}`, true)
|
store.commit(`TimelineSpace/${TIMELINE_MUTATION.CHANGE_LOADING}`, true)
|
||||||
|
@ -268,12 +213,6 @@ export default defineComponent({
|
||||||
const focusSidebar = () => {
|
const focusSidebar = () => {
|
||||||
EventEmitter.emit('focus-sidebar')
|
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 {
|
return {
|
||||||
scroller,
|
scroller,
|
||||||
|
@ -284,7 +223,6 @@ export default defineComponent({
|
||||||
deleteToot,
|
deleteToot,
|
||||||
focusSidebar,
|
focusSidebar,
|
||||||
focusToot,
|
focusToot,
|
||||||
sizeChanged,
|
|
||||||
openSideBar,
|
openSideBar,
|
||||||
heading,
|
heading,
|
||||||
upper
|
upper
|
||||||
|
|
|
@ -4,20 +4,18 @@ import { RootState } from '@/store'
|
||||||
import { LoadPositionWithList } from '@/types/loadPosition'
|
import { LoadPositionWithList } from '@/types/loadPosition'
|
||||||
import { MyWindow } from '~/src/types/global'
|
import { MyWindow } from '~/src/types/global'
|
||||||
|
|
||||||
const win = window as any as MyWindow
|
const win = (window as any) as MyWindow
|
||||||
|
|
||||||
export type ShowState = {
|
export type ShowState = {
|
||||||
timeline: Array<Entity.Status>
|
timeline: Array<Entity.Status>
|
||||||
lazyLoading: boolean
|
lazyLoading: boolean
|
||||||
heading: boolean
|
heading: boolean
|
||||||
scrolling: boolean
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const state = (): ShowState => ({
|
const state = (): ShowState => ({
|
||||||
timeline: [],
|
timeline: [],
|
||||||
lazyLoading: false,
|
lazyLoading: false,
|
||||||
heading: true,
|
heading: true
|
||||||
scrolling: false
|
|
||||||
})
|
})
|
||||||
|
|
||||||
export const MUTATION_TYPES = {
|
export const MUTATION_TYPES = {
|
||||||
|
@ -29,8 +27,7 @@ export const MUTATION_TYPES = {
|
||||||
CLEAR_TIMELINE: 'clearTimeline',
|
CLEAR_TIMELINE: 'clearTimeline',
|
||||||
UPDATE_TOOT: 'updateToot',
|
UPDATE_TOOT: 'updateToot',
|
||||||
DELETE_TOOT: 'deleteToot',
|
DELETE_TOOT: 'deleteToot',
|
||||||
CHANGE_LAZY_LOADING: 'changeLazyLoading',
|
CHANGE_LAZY_LOADING: 'changeLazyLoading'
|
||||||
CHANGE_SCROLLING: 'changeScrolling'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const mutations: MutationTree<ShowState> = {
|
const mutations: MutationTree<ShowState> = {
|
||||||
|
@ -82,9 +79,6 @@ const mutations: MutationTree<ShowState> = {
|
||||||
},
|
},
|
||||||
[MUTATION_TYPES.CHANGE_LAZY_LOADING]: (state, value: boolean) => {
|
[MUTATION_TYPES.CHANGE_LAZY_LOADING]: (state, value: boolean) => {
|
||||||
state.lazyLoading = value
|
state.lazyLoading = value
|
||||||
},
|
|
||||||
[MUTATION_TYPES.CHANGE_SCROLLING]: (state, value: boolean) => {
|
|
||||||
state.scrolling = value
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue