Files
flights_web/src/shared/state/transientPrefill.ts
T
gnezim a982d9a669 Fix lint: route sessionStorage through shared storage module, drop dead imports
- storage.ts: add sessionStore wrapper (getRaw/setRaw/delete/clear) so
  transientPrefill + ScheduleStartPage tests don't trip the
  no-restricted-globals rule.
- transientPrefill.ts + ScheduleStartPage.test.tsx: use sessionStore.
- closestFlight.ts: hoist bracket-index key so no newline-before-[ ASI.
- Test files: hoist typeof import(...) into named type alias with
  type-only namespace import.
- Drop unused imports: FlightCard (Link, languageToLocale),
  OnlineBoardDetailsPage (operatingCarrier),
  ScheduleSearchPage (FlightList, inline import() types),
  PageLayout (FeedbackButton).
- Drop react-hooks/exhaustive-deps disable comments for a rule not
  registered in eslint.config.js.
2026-04-20 08:15:21 +03:00

36 lines
1.2 KiB
TypeScript

/**
* Cross-page transient prefill store.
*
* Mirrors Angular's `OnlineBoardFiltersStateService` /
* `ScheduleFiltersStateService` — singleton state used to hand
* popular-request data from one page to another without polluting the
* URL with query strings. Reload clears it (matches Angular's behavior:
* a fresh navigation to the page bypasses the service-held state).
*
* sessionStorage is the host: same-tab persistence, gone on tab close,
* works around react-router v6's same-path navigation collapsing
* `state` updates without re-rendering useLocation consumers. Access
* goes through `sessionStore` so the no-restricted-globals rule stays
* unviolated.
*/
import { sessionStore } from "@/shared/storage.js";
const KEY_PREFIX = "afl-prefill:";
export function writeTransientPrefill<T>(slot: string, value: T): void {
sessionStore.setRaw(KEY_PREFIX + slot, JSON.stringify(value));
}
export function readAndClearTransientPrefill<T>(slot: string): T | null {
const key = KEY_PREFIX + slot;
const raw = sessionStore.getRaw(key);
if (raw === null) return null;
sessionStore.delete(key);
try {
return JSON.parse(raw) as T;
} catch {
return null;
}
}