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 {
|
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) {
|
||||||
|
if (typeof restore.position === 'undefined')
|
||||||
el.scrollIntoView()
|
el.scrollIntoView()
|
||||||
else
|
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 }
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue