diff --git a/src/lib/utils/url-state.ts b/src/lib/utils/url-state.ts index 52397be..09ecd1f 100644 --- a/src/lib/utils/url-state.ts +++ b/src/lib/utils/url-state.ts @@ -39,6 +39,30 @@ export function syncSearchParams(url: URL, updates: Record { const model = params.models?.[0]; if (!mounted || !model) return; - syncSearchParams(get(page).url, { model }); + syncSearchParams(get(page).url, { model: unlessDefault(model, DEFAULT_MODEL) }); }); // components persist across refetches; entries are null while unmounted @@ -296,7 +298,7 @@ {#snippet heroActions()}
{ diff --git a/src/routes/weather/compare/[location]/+page.svelte b/src/routes/weather/compare/[location]/+page.svelte index bf115ec..e6cf6f7 100644 --- a/src/routes/weather/compare/[location]/+page.svelte +++ b/src/routes/weather/compare/[location]/+page.svelte @@ -9,7 +9,7 @@ import { storedLocation, storedModel, storedUnits } from '$lib/stores/settings'; import { formatZoned } from '$lib/utils/date'; - import { readList, syncSearchParams } from '$lib/utils/url-state'; + import { listUnlessDefault, readList, syncSearchParams } from '$lib/utils/url-state'; import { ChartContainer, ChartToolbar } from '$lib/components/charts'; import { Checkbox } from '$lib/components/ui/checkbox'; @@ -71,10 +71,19 @@ storedLocation.set(data.location); }); + const DEFAULT_VARS = ['temperature_2m', 'rain', 'wind_speed_10m']; + const DEFAULT_MODELS = [ + 'ecmwf_ifs', + 'meteofrance_seamless', + 'ukmo_seamless', + 'icon_seamless', + 'gfs_seamless' + ]; + let params = $state({ ...defaultParameters, - hourly: ['temperature_2m', 'rain', 'wind_speed_10m'], - models: ['ecmwf_ifs', 'meteofrance_seamless', 'ukmo_seamless', 'icon_seamless', 'gfs_seamless'] + hourly: [...DEFAULT_VARS], + models: [...DEFAULT_MODELS] }); // units live in a persisted store; mirror them into params so a change @@ -125,8 +134,8 @@ const vars = params.hourly; if (!mounted) return; syncSearchParams(get(page).url, { - models: models?.length ? models.join(',') : null, - vars: vars?.length ? vars.join(',') : null + models: listUnlessDefault(models, DEFAULT_MODELS), + vars: listUnlessDefault(vars, DEFAULT_VARS) }); }); diff --git a/src/routes/weather/week/[location]/+page.svelte b/src/routes/weather/week/[location]/+page.svelte index 06573f8..352fbbd 100644 --- a/src/routes/weather/week/[location]/+page.svelte +++ b/src/routes/weather/week/[location]/+page.svelte @@ -18,7 +18,7 @@ import { formatZoned } from '$lib/utils/date'; import { daySwap, runDayTransition } from '$lib/utils/day-swap'; import { buildLocationRoute } from '$lib/utils/location'; - import { syncSearchParams } from '$lib/utils/url-state'; + import { syncSearchParams, unlessDefault } from '$lib/utils/url-state'; import { ChartContainer } from '$lib/components/charts'; @@ -269,7 +269,7 @@ : false; syncSearchParams(get(page).url, { day: isToday ? null : dayKey, - model: model && model !== 'best_match' ? model : null + model: unlessDefault(model, 'best_match') }); });