mirror of
https://github.com/versia-pub/frontend.git
synced 2026-03-13 03:29:16 +01:00
refactor: ♻️ Only use a single localStorage key for scroll position
This commit is contained in:
parent
bba222a2fc
commit
e74dbe3d59
3 changed files with 10 additions and 7 deletions
|
|
@ -13,7 +13,7 @@ const client = useClient();
|
|||
const timelineParameters = ref({});
|
||||
const { timeline, loadNext, loadPrev } = useAccountTimeline(
|
||||
client.value,
|
||||
props.id ?? null,
|
||||
props.id || null,
|
||||
timelineParameters,
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -3,21 +3,24 @@
|
|||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
const root = useParentElement();
|
||||
const root = useParentElement(useParentElement());
|
||||
// Store and keep y to restore it on page change
|
||||
const route = useRoute();
|
||||
const yStored = useLocalStorage(`lysand:scroll-${route.fullPath}`, 0);
|
||||
const yStored = useLocalStorage("lysand:scroll", {
|
||||
[route.fullPath]: 0,
|
||||
});
|
||||
const { y } = useScroll(root);
|
||||
|
||||
useEventListener("popstate", async (event) => {
|
||||
if (yStored.value !== null) {
|
||||
if (yStored.value[route.fullPath] !== undefined) {
|
||||
// Wait for the Vue component to load
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
y.value = yStored.value;
|
||||
y.value = yStored.value[route.fullPath] ?? 0;
|
||||
}
|
||||
});
|
||||
|
||||
onBeforeRouteLeave(() => {
|
||||
yStored.value = y.value;
|
||||
yStored.value[route.fullPath] = y.value;
|
||||
yStored.value = { ...yStored.value };
|
||||
});
|
||||
</script>
|
||||
Loading…
Add table
Add a link
Reference in a new issue