mirror of
https://github.com/elk-zone/elk.git
synced 2024-12-05 03:59:59 +03:00
chore: use scroll y position on restore (page with tabs not working properly)
This commit is contained in:
parent
674adb48ba
commit
2531bd8f45
1 changed files with 11 additions and 5 deletions
|
@ -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 }
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue