mirror of
https://github.com/versia-pub/frontend.git
synced 2025-12-06 08:28:20 +01:00
refactor: ♻️ Only use a single localStorage key for scroll position
This commit is contained in:
parent
bba222a2fc
commit
e74dbe3d59
|
|
@ -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>
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
<script setup lang="ts">
|
||||
import type { Account } from "@lysand-org/client/types";
|
||||
import ErrorBoundary from "~/components/errors/ErrorBoundary.vue";
|
||||
import AccountProfile from "~/components/timelines/account.vue";
|
||||
import AccountProfile from "~/components/social-elements/users/Account.vue";
|
||||
import AccountTimeline from "~/components/timelines/account.vue";
|
||||
import TimelineScroller from "~/components/timelines/timeline-scroller.vue";
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue