mirror of
https://github.com/h3poteto/whalebird-desktop
synced 2024-12-12 08:46:34 +01:00
Revert modifying scroll position in Tags
This commit is contained in:
parent
a82c5950a4
commit
279d06e4de
@ -12,7 +12,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 { useRoute } from 'vue-router'
|
|||||||
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 useReloadable from '@/components/utils/reloadable'
|
import useReloadable from '@/components/utils/reloadable'
|
||||||
import { MUTATION_TYPES as TIMELINE_MUTATION } from '@/store/TimelineSpace'
|
import { MUTATION_TYPES as TIMELINE_MUTATION } from '@/store/TimelineSpace'
|
||||||
import { MUTATION_TYPES as HEADER_MUTATION } from '@/store/TimelineSpace/HeaderMenu'
|
import { MUTATION_TYPES as HEADER_MUTATION } from '@/store/TimelineSpace/HeaderMenu'
|
||||||
@ -58,10 +56,6 @@ export default defineComponent({
|
|||||||
|
|
||||||
const { tag } = toRefs(props)
|
const { tag } = 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.Hashtag.Tag.timeline)
|
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)
|
store.commit(`TimelineSpace/Contents/${CONTENTS_MUTATION.CHANGE_LOADING}`, false)
|
||||||
})
|
})
|
||||||
document.getElementById('scroller')?.addEventListener('scroll', onScroll)
|
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) => {
|
watch(tag, (newTag, _oldTag) => {
|
||||||
store.commit(`TimelineSpace/Contents/${CONTENTS_MUTATION.CHANGE_LOADING}`, true)
|
store.commit(`TimelineSpace/Contents/${CONTENTS_MUTATION.CHANGE_LOADING}`, true)
|
||||||
@ -141,7 +114,6 @@ export default defineComponent({
|
|||||||
store.dispatch(`${space}/${ACTION_TYPES.STOP_STREAMING}`)
|
store.dispatch(`${space}/${ACTION_TYPES.STOP_STREAMING}`)
|
||||||
reset()
|
reset()
|
||||||
EventEmitter.off('focus-timeline')
|
EventEmitter.off('focus-timeline')
|
||||||
observer.value?.disconnect()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const load = async (tag: string) => {
|
const load = async (tag: string) => {
|
||||||
@ -170,14 +142,6 @@ 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)
|
|
||||||
}
|
|
||||||
|
|
||||||
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 &&
|
||||||
@ -188,17 +152,6 @@ export default defineComponent({
|
|||||||
tag: tag.value,
|
tag: tag.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'),
|
||||||
@ -212,14 +165,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 updateToot = (toot: Entity.Status) => {
|
const updateToot = (toot: Entity.Status) => {
|
||||||
store.commit(`${space}/${MUTATION_TYPES.UPDATE_TOOT}`, toot)
|
store.commit(`${space}/${MUTATION_TYPES.UPDATE_TOOT}`, toot)
|
||||||
@ -272,12 +217,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 {
|
||||||
timeline,
|
timeline,
|
||||||
@ -288,7 +227,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 { LoadPositionWithTag } from '@/types/loadPosition'
|
import { LoadPositionWithTag } 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 TagState = {
|
export type TagState = {
|
||||||
timeline: Array<Entity.Status>
|
timeline: Array<Entity.Status>
|
||||||
lazyLoading: boolean
|
lazyLoading: boolean
|
||||||
heading: boolean
|
heading: boolean
|
||||||
scrolling: boolean
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const state = (): TagState => ({
|
const state = (): TagState => ({
|
||||||
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<TagState> = {
|
const mutations: MutationTree<TagState> = {
|
||||||
@ -82,9 +79,6 @@ const mutations: MutationTree<TagState> = {
|
|||||||
},
|
},
|
||||||
[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
Block a user