From 2531bd8f45ef84164b9d1257176f15b8a0b62122 Mon Sep 17 00:00:00 2001 From: userquin Date: Sun, 8 Jan 2023 18:43:33 +0100 Subject: [PATCH] chore: use scroll y position on restore (page with tabs not working properly) --- plugins/remember-scroll-position.client.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/plugins/remember-scroll-position.client.ts b/plugins/remember-scroll-position.client.ts index 91173bc6..ef361465 100644 --- a/plugins/remember-scroll-position.client.ts +++ b/plugins/remember-scroll-position.client.ts @@ -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 } }, }, }