rm unused urlparam
This commit is contained in:
@@ -39,6 +39,30 @@ export function syncSearchParams(url: URL, updates: Record<string, string | null
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The value to mirror, or null when it is the view's default. Defaults belong
|
||||||
|
* in the code, not the query string: a shared link should carry only what the
|
||||||
|
* visitor actually changed, and going back to the default has to clear the
|
||||||
|
* parameter again rather than pin the default in place.
|
||||||
|
*/
|
||||||
|
export function unlessDefault(value: string | null | undefined, fallback: string): string | null {
|
||||||
|
return value && value !== fallback ? value : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Same, for the comma-separated list parameters. Order counts - the models are
|
||||||
|
* plotted, coloured and legended in the order they are listed, so a reordered
|
||||||
|
* line-up is a different view even when it holds the same entries.
|
||||||
|
*/
|
||||||
|
export function listUnlessDefault(
|
||||||
|
values: string[] | null | undefined,
|
||||||
|
fallback: string[]
|
||||||
|
): string | null {
|
||||||
|
if (!values?.length) return null;
|
||||||
|
const joined = values.join(',');
|
||||||
|
return joined === fallback.join(',') ? null : joined;
|
||||||
|
}
|
||||||
|
|
||||||
/** Reads a comma-separated list, dropping empties. */
|
/** Reads a comma-separated list, dropping empties. */
|
||||||
export function readList(url: URL, key: string): string[] | null {
|
export function readList(url: URL, key: string): string[] | null {
|
||||||
const raw = url.searchParams.get(key);
|
const raw = url.searchParams.get(key);
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
import { reportPageReady } from '$lib/stores/page-transition.svelte';
|
import { reportPageReady } from '$lib/stores/page-transition.svelte';
|
||||||
import { storedEnsembleModel, storedLocation, storedUnits } from '$lib/stores/settings';
|
import { storedEnsembleModel, storedLocation, storedUnits } from '$lib/stores/settings';
|
||||||
|
|
||||||
import { syncSearchParams } from '$lib/utils/url-state';
|
import { syncSearchParams, unlessDefault } from '$lib/utils/url-state';
|
||||||
|
|
||||||
import { ChartContainer, ChartToolbar } from '$lib/components/charts';
|
import { ChartContainer, ChartToolbar } from '$lib/components/charts';
|
||||||
import { Label } from '$lib/components/ui/label';
|
import { Label } from '$lib/components/ui/label';
|
||||||
@@ -56,10 +56,12 @@
|
|||||||
storedLocation.set(data.location);
|
storedLocation.set(data.location);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const DEFAULT_MODEL = 'ncep_gefs_seamless';
|
||||||
|
|
||||||
let params = $state({
|
let params = $state({
|
||||||
...defaultParameters,
|
...defaultParameters,
|
||||||
hourly: ['temperature_2m', 'precipitation', 'wind_speed_10m', 'cloud_cover', 'pressure_msl'],
|
hourly: ['temperature_2m', 'precipitation', 'wind_speed_10m', 'cloud_cover', 'pressure_msl'],
|
||||||
models: ['ncep_gefs_seamless']
|
models: [DEFAULT_MODEL]
|
||||||
});
|
});
|
||||||
|
|
||||||
// units live in a persisted store; mirror them into params so a change
|
// units live in a persisted store; mirror them into params so a change
|
||||||
@@ -94,7 +96,7 @@
|
|||||||
$effect(() => {
|
$effect(() => {
|
||||||
const model = params.models?.[0];
|
const model = params.models?.[0];
|
||||||
if (!mounted || !model) return;
|
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
|
// components persist across refetches; entries are null while unmounted
|
||||||
@@ -296,7 +298,7 @@
|
|||||||
{#snippet heroActions()}
|
{#snippet heroActions()}
|
||||||
<div class="lg:absolute lg:right-0 lg:top-0 flex w-full items-center gap-3 sm:w-auto">
|
<div class="lg:absolute lg:right-0 lg:top-0 flex w-full items-center gap-3 sm:w-auto">
|
||||||
<ModelSelector
|
<ModelSelector
|
||||||
selectedModel={params.models?.[0] ?? 'ncep_gefs_seamless'}
|
selectedModel={params.models?.[0] ?? DEFAULT_MODEL}
|
||||||
groups={ensembleModelGroups}
|
groups={ensembleModelGroups}
|
||||||
label={m.model_ensemble()}
|
label={m.model_ensemble()}
|
||||||
onModelChange={(model) => {
|
onModelChange={(model) => {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
import { storedLocation, storedModel, storedUnits } from '$lib/stores/settings';
|
import { storedLocation, storedModel, storedUnits } from '$lib/stores/settings';
|
||||||
|
|
||||||
import { formatZoned } from '$lib/utils/date';
|
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 { ChartContainer, ChartToolbar } from '$lib/components/charts';
|
||||||
import { Checkbox } from '$lib/components/ui/checkbox';
|
import { Checkbox } from '$lib/components/ui/checkbox';
|
||||||
@@ -71,10 +71,19 @@
|
|||||||
storedLocation.set(data.location);
|
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({
|
let params = $state({
|
||||||
...defaultParameters,
|
...defaultParameters,
|
||||||
hourly: ['temperature_2m', 'rain', 'wind_speed_10m'],
|
hourly: [...DEFAULT_VARS],
|
||||||
models: ['ecmwf_ifs', 'meteofrance_seamless', 'ukmo_seamless', 'icon_seamless', 'gfs_seamless']
|
models: [...DEFAULT_MODELS]
|
||||||
});
|
});
|
||||||
|
|
||||||
// units live in a persisted store; mirror them into params so a change
|
// units live in a persisted store; mirror them into params so a change
|
||||||
@@ -125,8 +134,8 @@
|
|||||||
const vars = params.hourly;
|
const vars = params.hourly;
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
syncSearchParams(get(page).url, {
|
syncSearchParams(get(page).url, {
|
||||||
models: models?.length ? models.join(',') : null,
|
models: listUnlessDefault(models, DEFAULT_MODELS),
|
||||||
vars: vars?.length ? vars.join(',') : null
|
vars: listUnlessDefault(vars, DEFAULT_VARS)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
import { formatZoned } from '$lib/utils/date';
|
import { formatZoned } from '$lib/utils/date';
|
||||||
import { daySwap, runDayTransition } from '$lib/utils/day-swap';
|
import { daySwap, runDayTransition } from '$lib/utils/day-swap';
|
||||||
import { buildLocationRoute } from '$lib/utils/location';
|
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';
|
import { ChartContainer } from '$lib/components/charts';
|
||||||
|
|
||||||
@@ -269,7 +269,7 @@
|
|||||||
: false;
|
: false;
|
||||||
syncSearchParams(get(page).url, {
|
syncSearchParams(get(page).url, {
|
||||||
day: isToday ? null : dayKey,
|
day: isToday ? null : dayKey,
|
||||||
model: model && model !== 'best_match' ? model : null
|
model: unlessDefault(model, 'best_match')
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user