Every filter, the days and title included, is stored under job_search.filters when it changes and read back when the page loads. A stored field that isn't valid (missing, from an older version or edited by hand) falls back to its default, keeping the rest. Clear filters still goes back to the defaults.
28 lines
803 B
TypeScript
28 lines
803 B
TypeScript
// localStorage can throw (privacy modes, storage disabled, quota), so every
|
|
// access is guarded and falls back to "nothing stored".
|
|
|
|
/** The stored value of key, or null if there is none or storage is unavailable. */
|
|
export function readStored(key: string): string | null {
|
|
try {
|
|
return window.localStorage.getItem(key);
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/** Stores value under key, if storage is available. */
|
|
export function writeStored(key: string, value: string): void {
|
|
try {
|
|
window.localStorage.setItem(key, value);
|
|
} catch {
|
|
/* preference just won't persist */
|
|
}
|
|
}
|
|
|
|
// index.html reads the theme key too, before the app loads.
|
|
export const STORAGE_KEYS = {
|
|
theme: 'job_search.theme',
|
|
filtersOpen: 'job_search.filtersOpen',
|
|
filters: 'job_search.filters',
|
|
} as const;
|