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 {
id: string
type: 'status' | 'follow'
position: number
}
export default defineNuxtPlugin(() => {
@ -20,17 +21,22 @@ export default defineNuxtPlugin(() => {
const el = restore.type === 'status'
? document.getElementById(`status-${restore.id}`)
: document.querySelector(`a[href="${restore.id}"]`)
if (el)
el.scrollIntoView()
else
if (el) {
if (typeof restore.position === 'undefined')
el.scrollIntoView()
else
window.scrollTo(0, restore.position)
}
else {
delete lastStatus.value[useRoute().fullPath]
}
}
},
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) => {
lastStatus.value[useRoute().fullPath] = { id: status.id, type: 'status' }
lastStatus.value[useRoute().fullPath] = { id: status.id, type: 'status', position: window.scrollY }
},
},
}