46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
export type NavigationFocus = {
|
|
case_id: string;
|
|
step_code: string | null;
|
|
version: number;
|
|
};
|
|
const key = (actor: number) => `investmoz-navigation-focus:${actor}`;
|
|
/** A per-tab hint, never authority to access a dossier. Recheck the server listing. */
|
|
export function readNavigationFocus(
|
|
actor: number,
|
|
allowed: string[],
|
|
): NavigationFocus | null {
|
|
try {
|
|
const value = JSON.parse(sessionStorage.getItem(key(actor)) ?? 'null');
|
|
if (
|
|
!value ||
|
|
!allowed.includes(value.case_id) ||
|
|
!Number.isSafeInteger(value.version) ||
|
|
value.version < 0
|
|
)
|
|
return null;
|
|
if (
|
|
value.step_code !== null &&
|
|
!/^S(0[1-9]|1[0-9])$/.test(value.step_code)
|
|
)
|
|
return null;
|
|
return {
|
|
case_id: value.case_id,
|
|
step_code: value.step_code,
|
|
version: value.version,
|
|
};
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
export function rememberNavigationFocus(
|
|
actor: number,
|
|
focus: NavigationFocus | null,
|
|
): void {
|
|
try {
|
|
if (focus) sessionStorage.setItem(key(actor), JSON.stringify(focus));
|
|
else sessionStorage.removeItem(key(actor));
|
|
} catch {
|
|
// The current consultation remains usable when browser storage is blocked.
|
|
}
|
|
}
|