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. */
|
||||
export function readList(url: URL, key: string): string[] | null {
|
||||
const raw = url.searchParams.get(key);
|
||||
|
||||
Reference in New Issue
Block a user