commit16
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
/** 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user