frontend/app/components/timelines/timeline-scroller.vue
Jesse Wierzbinski 7f7cf20311
Some checks failed
CodeQL / Analyze (javascript) (push) Failing after 1s
Deploy to GitHub Pages / build (push) Failing after 1s
Deploy to GitHub Pages / deploy (push) Has been skipped
Docker / build (push) Failing after 1s
Mirror to Codeberg / Mirror (push) Failing after 1s
chore: ⬆️ Upgrade to Nuxt 4
2025-07-16 07:48:39 +02:00

26 lines
702 B
Vue

<template>
<slot />
</template>
<script lang="ts" setup>
const root = useParentElement(useParentElement());
// Store and keep y to restore it on page change
const route = useRoute();
const yStored = useLocalStorage("versia:scroll", {
[route.fullPath]: 0,
});
const { y } = useScroll(root);
useEventListener("popstate", async () => {
if (yStored.value[route.fullPath] !== undefined) {
// Wait for the Vue component to load
await new Promise((resolve) => setTimeout(resolve, 100));
y.value = yStored.value[route.fullPath] ?? 0;
}
});
onBeforeRouteLeave(() => {
yStored.value[route.fullPath] = y.value;
yStored.value = { ...yStored.value };
});
</script>