chore: use scroll y position on restore (page with tabs not working properly)

This commit is contained in:
userquin 2023-01-08 18:43:33 +01:00
parent 674adb48ba
commit 2531bd8f45

View file

@ -5,6 +5,7 @@ import { STORAGE_KEY_LAST_SCROLL_POSITION } from '~/constants'
interface RestoreScroll { interface RestoreScroll {
id: string id: string
type: 'status' | 'follow' type: 'status' | 'follow'
position: number
} }
export default defineNuxtPlugin(() => { export default defineNuxtPlugin(() => {
@ -20,17 +21,22 @@ export default defineNuxtPlugin(() => {
const el = restore.type === 'status' const el = restore.type === 'status'
? document.getElementById(`status-${restore.id}`) ? document.getElementById(`status-${restore.id}`)
: document.querySelector(`a[href="${restore.id}"]`) : document.querySelector(`a[href="${restore.id}"]`)
if (el) if (el) {
el.scrollIntoView() if (typeof restore.position === 'undefined')
else el.scrollIntoView()
else
window.scrollTo(0, restore.position)
}
else {
delete lastStatus.value[useRoute().fullPath] delete lastStatus.value[useRoute().fullPath]
}
} }
}, },
rememberAccountPosition: (account: string) => { rememberAccountPosition: (account: string) => {
lastStatus.value[useRoute().fullPath] = { id: account, type: 'follow' } lastStatus.value[useRoute().fullPath] = { id: account, type: 'follow', position: window.scrollY }
}, },
rememberStatusPosition: (status: mastodon.v1.Status) => { rememberStatusPosition: (status: mastodon.v1.Status) => {
lastStatus.value[useRoute().fullPath] = { id: status.id, type: 'status' } lastStatus.value[useRoute().fullPath] = { id: status.id, type: 'status', position: window.scrollY }
}, },
}, },
} }