Skip to content

armgit / VERT

Public Imported from GitHub
0

The next-generation file converter. Open source, fully local* and free forever.

fix: save scroll position on mobile while switching pages

JovannMCd013fb008443
diff --git a/src/lib/components/layout/Gradients.svelte b/src/lib/components/layout/Gradients.svelte
index 2adefcf..6a9c9e4 100644
--- a/src/lib/components/layout/Gradients.svelte
+++ b/src/lib/components/layout/Gradients.svelte
@@ -2,7 +2,11 @@
import { page } from "$app/state";
import { duration } from "$lib/animation";
import VertVBig from "$lib/assets/vert-bg.svg?component";
- import { files, gradientColor, showGradient } from "$lib/store/index.svelte";
+ import {
+ files,
+ gradientColor,
+ showGradient,
+ } from "$lib/store/index.svelte";
import { quintOut } from "svelte/easing";
import { fade } from "$lib/animation";
</script>
@@ -90,4 +94,4 @@
easing: quintOut,
}}
></div>
-{/if}
\ No newline at end of file
+{/if}
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte
index a793d0f..c8af493 100644
--- a/src/routes/+layout.svelte
+++ b/src/routes/+layout.svelte
@@ -1,6 +1,6 @@
<script lang="ts">
import { onMount } from "svelte";
- import { goto } from "$app/navigation";
+ import { goto, beforeNavigate, afterNavigate } from "$app/navigation";
import { PUB_PLAUSIBLE_URL, PUB_HOSTNAME } from "$env/static/public";
import { VERT_NAME } from "$lib/consts";
@@ -20,6 +20,21 @@
let { children } = $props();
let enablePlausible = $state(false);
+ let scrollPositions = new Map<string, number>();
+
+ beforeNavigate((nav) => {
+ if (!nav.from || !$isMobile) return;
+ scrollPositions.set(nav.from.url.pathname, window.scrollY);
+ });
+
+ afterNavigate((nav) => {
+ if (!$isMobile) return;
+ const scrollY = nav.to
+ ? scrollPositions.get(nav.to.url.pathname) || 0
+ : 0;
+ window.scrollTo(0, scrollY);
+ });
+
const dropFiles = (e: DragEvent) => {
e.preventDefault();
dropping.set(false);
@@ -49,7 +64,8 @@
$effect(() => {
// Enable plausible if enabled
- enablePlausible = !!PUB_PLAUSIBLE_URL && Settings.instance.settings.plausible;
+ enablePlausible =
+ !!PUB_PLAUSIBLE_URL && Settings.instance.settings.plausible;
});
</script>