From ee14ba87a4efc5d986ad2c9d52ae124fc8aa59cb Mon Sep 17 00:00:00 2001 From: Christian Beutel <> Date: Sat, 22 Mar 2025 15:03:15 +0100 Subject: [PATCH] adds trail filter persistence --- web/src/routes/map/+page.svelte | 11 ++++++++++- web/src/routes/trails/+page.svelte | 9 +++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/web/src/routes/map/+page.svelte b/web/src/routes/map/+page.svelte index 27594a52..28bb4eeb 100644 --- a/web/src/routes/map/+page.svelte +++ b/web/src/routes/map/+page.svelte @@ -25,6 +25,7 @@ } from "$lib/stores/search_store"; import { trails_search_bounding_box } from "$lib/stores/trail_store"; import { getIconForLocation } from "$lib/util/icon_util"; + import type { Snapshot } from "@sveltejs/kit"; import * as M from "maplibre-gl"; import { onMount } from "svelte"; import { _ } from "svelte-i18n"; @@ -53,6 +54,14 @@ totalPages: 1, }; + export const snapshot: Snapshot = { + capture: () => filter, + restore: (value) => { + filter = value; + handleFilterUpdate(); + }, + }; + async function search(q: string) { const r = await searchMulti({ queries: [ @@ -136,7 +145,7 @@ mapWithElevation?.togglePopup(trail.id!, true); } - async function handleFilterUpdate(filter: TrailFilter) { + async function handleFilterUpdate() { if (!map) { return; } diff --git a/web/src/routes/trails/+page.svelte b/web/src/routes/trails/+page.svelte index 56f31c97..363309cd 100644 --- a/web/src/routes/trails/+page.svelte +++ b/web/src/routes/trails/+page.svelte @@ -5,6 +5,7 @@ import TrailList from "$lib/components/trail/trail_list.svelte"; import type { Trail, TrailFilter } from "$lib/models/trail"; import { trails_search_filter } from "$lib/stores/trail_store"; + import type { Snapshot } from "@sveltejs/kit"; import { onMount } from "svelte"; import { _ } from "svelte-i18n"; @@ -21,6 +22,14 @@ }); let trails: Trail[] = $state([]); + export const snapshot: Snapshot = { + capture: () => filter, + restore: (value) => { + filter = value; + handleFilterUpdate() + }, + }; + onMount(() => { if (window.innerWidth < 768) { filterExpanded = false;