Revert modifying scroll position in Home
This commit is contained in:
parent
279d06e4de
commit
fe9898c25d
|
@ -19,7 +19,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>
|
||||||
|
@ -47,7 +46,6 @@ import { useStore } from '@/store'
|
||||||
import Toot from '@/components/organisms/Toot.vue'
|
import Toot from '@/components/organisms/Toot.vue'
|
||||||
import StatusLoading from '@/components/organisms/StatusLoading.vue'
|
import StatusLoading from '@/components/organisms/StatusLoading.vue'
|
||||||
import { EventEmitter } from '@/components/event'
|
import { EventEmitter } from '@/components/event'
|
||||||
import { ScrollPosition } from '@/components/utils/scroll'
|
|
||||||
import { ACTION_TYPES, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/Home'
|
import { ACTION_TYPES, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/Home'
|
||||||
import { MUTATION_TYPES as SIDE_MENU_MUTATION } from '@/store/TimelineSpace/SideMenu'
|
import { MUTATION_TYPES as SIDE_MENU_MUTATION } from '@/store/TimelineSpace/SideMenu'
|
||||||
import { MUTATION_TYPES as TIMELINE_MUTATION } from '@/store/TimelineSpace'
|
import { MUTATION_TYPES as TIMELINE_MUTATION } from '@/store/TimelineSpace'
|
||||||
|
@ -66,10 +64,6 @@ export default defineComponent({
|
||||||
const { j, k, Ctrl_r } = useMagicKeys()
|
const { j, k, Ctrl_r } = useMagicKeys()
|
||||||
|
|
||||||
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 loadingMore = ref(false)
|
const loadingMore = ref(false)
|
||||||
const scroller = ref<any>()
|
const scroller = ref<any>()
|
||||||
|
|
||||||
|
@ -108,30 +102,11 @@ export default defineComponent({
|
||||||
if (heading.value && timeline.value.length > 0) {
|
if (heading.value && timeline.value.length > 0) {
|
||||||
store.dispatch(`${space}/${ACTION_TYPES.SAVE_MARKER}`)
|
store.dispatch(`${space}/${ACTION_TYPES.SAVE_MARKER}`)
|
||||||
}
|
}
|
||||||
const el = document.getElementById('scroller')
|
|
||||||
if (el) {
|
|
||||||
scrollPosition.value = new ScrollPosition(el)
|
|
||||||
scrollPosition.value.prepare()
|
|
||||||
observer.value = new ResizeObserver(() => {
|
|
||||||
if (loadingMore.value || (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(() => {
|
onBeforeUpdate(() => {
|
||||||
if (store.state.TimelineSpace.SideMenu.unreadHomeTimeline && heading.value) {
|
if (store.state.TimelineSpace.SideMenu.unreadHomeTimeline && heading.value) {
|
||||||
store.commit(`TimelineSpace/SideMenu/${SIDE_MENU_MUTATION.CHANGE_UNREAD_HOME_TIMELINE}`, false)
|
store.commit(`TimelineSpace/SideMenu/${SIDE_MENU_MUTATION.CHANGE_UNREAD_HOME_TIMELINE}`, false)
|
||||||
}
|
}
|
||||||
if (scrollPosition.value) {
|
|
||||||
scrollPosition.value.prepare()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
onBeforeUnmount(() => {
|
|
||||||
observer.value?.disconnect()
|
|
||||||
})
|
})
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
store.commit(`${space}/${MUTATION_TYPES.CHANGE_HEADING}`, true)
|
store.commit(`${space}/${MUTATION_TYPES.CHANGE_HEADING}`, true)
|
||||||
|
@ -180,39 +155,18 @@ export default defineComponent({
|
||||||
})
|
})
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
// for lazyLoading
|
// for lazyLoading
|
||||||
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 &&
|
||||||
!lazyLoading.value
|
!lazyLoading.value
|
||||||
) {
|
) {
|
||||||
store
|
store.dispatch(`${space}/${ACTION_TYPES.LAZY_FETCH_TIMELINE}`, timeline.value[timeline.value.length - 1]).catch(() => {
|
||||||
.dispatch(`${space}/${ACTION_TYPES.LAZY_FETCH_TIMELINE}`, timeline.value[timeline.value.length - 1])
|
ElMessage({
|
||||||
.then(statuses => {
|
message: i18n.t('message.timeline_fetch_error'),
|
||||||
if (statuses === null) {
|
type: 'error'
|
||||||
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'
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((event.target as HTMLElement)!.scrollTop > 10 && heading.value) {
|
if ((event.target as HTMLElement)!.scrollTop > 10 && heading.value) {
|
||||||
|
@ -220,14 +174,6 @@ export default defineComponent({
|
||||||
} else if ((event.target as HTMLElement)!.scrollTop <= 5 && !heading.value) {
|
} else if ((event.target as HTMLElement)!.scrollTop <= 5 && !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 updateToot = (message: Entity.Status) => {
|
const updateToot = (message: Entity.Status) => {
|
||||||
store.commit(`${space}/${MUTATION_TYPES.UPDATE_TOOT}`, message)
|
store.commit(`${space}/${MUTATION_TYPES.UPDATE_TOOT}`, message)
|
||||||
|
@ -275,12 +221,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 {
|
||||||
filteredTimeline,
|
filteredTimeline,
|
||||||
|
@ -296,7 +236,6 @@ export default defineComponent({
|
||||||
focusPrev,
|
focusPrev,
|
||||||
focusSidebar,
|
focusSidebar,
|
||||||
focusToot,
|
focusToot,
|
||||||
sizeChanged,
|
|
||||||
openSideBar,
|
openSideBar,
|
||||||
heading,
|
heading,
|
||||||
upper
|
upper
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { LocalMarker } from '~/src/types/localMarker'
|
||||||
import { MyWindow } from '~/src/types/global'
|
import { MyWindow } from '~/src/types/global'
|
||||||
import { LoadingCard } from '@/types/loading-card'
|
import { LoadingCard } from '@/types/loading-card'
|
||||||
|
|
||||||
const win = window as any as MyWindow
|
const win = (window as any) as MyWindow
|
||||||
|
|
||||||
export type HomeState = {
|
export type HomeState = {
|
||||||
lazyLoading: boolean
|
lazyLoading: boolean
|
||||||
|
@ -13,7 +13,6 @@ export type HomeState = {
|
||||||
showReblogs: boolean
|
showReblogs: boolean
|
||||||
showReplies: boolean
|
showReplies: boolean
|
||||||
timeline: Array<Entity.Status | LoadingCard>
|
timeline: Array<Entity.Status | LoadingCard>
|
||||||
scrolling: boolean
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const state = (): HomeState => ({
|
const state = (): HomeState => ({
|
||||||
|
@ -21,8 +20,7 @@ const state = (): HomeState => ({
|
||||||
heading: true,
|
heading: true,
|
||||||
timeline: [],
|
timeline: [],
|
||||||
showReblogs: true,
|
showReblogs: true,
|
||||||
showReplies: true,
|
showReplies: true
|
||||||
scrolling: false
|
|
||||||
})
|
})
|
||||||
|
|
||||||
export const MUTATION_TYPES = {
|
export const MUTATION_TYPES = {
|
||||||
|
@ -37,7 +35,6 @@ export const MUTATION_TYPES = {
|
||||||
DELETE_TOOT: 'deleteToot',
|
DELETE_TOOT: 'deleteToot',
|
||||||
SHOW_REBLOGS: 'showReblogs',
|
SHOW_REBLOGS: 'showReblogs',
|
||||||
SHOW_REPLIES: 'showReplies',
|
SHOW_REPLIES: 'showReplies',
|
||||||
CHANGE_SCROLLING: 'changeScrolling',
|
|
||||||
APPEND_TIMELINE_AFTER_LOADING_CARD: 'appendTimelineAfterLoadingCard'
|
APPEND_TIMELINE_AFTER_LOADING_CARD: 'appendTimelineAfterLoadingCard'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,9 +103,6 @@ const mutations: MutationTree<HomeState> = {
|
||||||
[MUTATION_TYPES.SHOW_REPLIES]: (state, visible: boolean) => {
|
[MUTATION_TYPES.SHOW_REPLIES]: (state, visible: boolean) => {
|
||||||
state.showReplies = visible
|
state.showReplies = visible
|
||||||
},
|
},
|
||||||
[MUTATION_TYPES.CHANGE_SCROLLING]: (state, value: boolean) => {
|
|
||||||
state.scrolling = value
|
|
||||||
},
|
|
||||||
[MUTATION_TYPES.APPEND_TIMELINE_AFTER_LOADING_CARD]: (state, timeline: Array<Entity.Status | LoadingCard>) => {
|
[MUTATION_TYPES.APPEND_TIMELINE_AFTER_LOADING_CARD]: (state, timeline: Array<Entity.Status | LoadingCard>) => {
|
||||||
const tl = state.timeline.flatMap(status => {
|
const tl = state.timeline.flatMap(status => {
|
||||||
if (status.id !== 'loading-card') {
|
if (status.id !== 'loading-card') {
|
||||||
|
|
Loading…
Reference in New Issue