diff --git a/apps/stage-tamagotchi/src/renderer/composables/use-restore-scroll.ts b/apps/stage-tamagotchi/src/renderer/composables/use-restore-scroll.ts new file mode 100644 index 000000000..7bf929bbc --- /dev/null +++ b/apps/stage-tamagotchi/src/renderer/composables/use-restore-scroll.ts @@ -0,0 +1,36 @@ +import { nextTick, ref, watch } from 'vue' +import { useRoute } from 'vue-router' + +const scrollPositions = new Map() + +export function useRestoreScroll() { + const route = useRoute() + + const scrollContainer = ref(null) + + watch( + () => route.fullPath, + async (newPath, oldPath) => { + if (!scrollContainer.value) { + return + } + + if (oldPath) { + scrollPositions.set(oldPath, scrollContainer.value.scrollTop) + } + + await nextTick() + + if (!scrollContainer.value) { + return + } + + const savedPosition = scrollPositions.get(newPath) || 0 + scrollContainer.value.scrollTop = savedPosition + }, + ) + + return { + scrollContainer, + } +} diff --git a/apps/stage-tamagotchi/src/renderer/index.html b/apps/stage-tamagotchi/src/renderer/index.html index 65c64030d..6d87e754c 100644 --- a/apps/stage-tamagotchi/src/renderer/index.html +++ b/apps/stage-tamagotchi/src/renderer/index.html @@ -3,7 +3,7 @@ AIRI - +