Revert modifying scroll position in DM
This commit is contained in:
parent
ae6d8d6c13
commit
04084ca549
|
@ -13,7 +13,6 @@
|
|||
v-on:delete="deleteToot"
|
||||
@focusRight="focusSidebar"
|
||||
@selectToot="focusToot(item)"
|
||||
@sizeChanged="sizeChanged"
|
||||
>
|
||||
</toot>
|
||||
</DynamicScrollerItem>
|
||||
|
@ -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<string | null>(null)
|
||||
const scrollPosition = ref<ScrollPosition | null>(null)
|
||||
const observer = ref<ResizeObserver | null>(null)
|
||||
const resizeTime = ref<moment.Moment | null>(null)
|
||||
const scrollTime = ref<moment.Moment | null>(null)
|
||||
const scroller = ref<any>()
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
@ -5,14 +5,12 @@ import { RootState } from '@/store'
|
|||
export type DirectMessagesState = {
|
||||
lazyLoading: boolean
|
||||
heading: boolean
|
||||
scrolling: boolean
|
||||
timeline: Array<Entity.Status>
|
||||
}
|
||||
|
||||
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<DirectMessagesState> = {
|
||||
|
@ -79,9 +76,6 @@ const mutations: MutationTree<DirectMessagesState> = {
|
|||
return toot.id !== id
|
||||
}
|
||||
})
|
||||
},
|
||||
[MUTATION_TYPES.CHANGE_SCROLLING]: (state, value: boolean) => {
|
||||
state.scrolling = value
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue