Files
Investidor-V2/resources/js/lib/opportunity-selection.ts
T
2026-11-02 20:31:15 +02:00

33 lines
999 B
TypeScript

/** Browser persistence is optional; the current selection remains usable without it. */
const selectionKey = 'investment-opportunity-selection';
export function readOpportunitySelection(): number[] {
try {
const value: unknown = JSON.parse(
sessionStorage.getItem(selectionKey) ?? '[]',
);
if (!Array.isArray(value)) return [];
return [
...new Set(
value.filter(
(id): id is number =>
typeof id === 'number' &&
Number.isSafeInteger(id) &&
id > 0,
),
),
];
} catch {
return [];
}
}
export function persistOpportunitySelection(ids: number[]): boolean {
try {
if (ids.length)
sessionStorage.setItem(selectionKey, JSON.stringify(ids));
else sessionStorage.removeItem(selectionKey);
return true;
} catch {
return false;
}
}