Files
nimbus/resources/js/utils/stores/uniquePersistenceKey.ts
Mazen Touati 8780a79557 feat: persist UI state (#32)
* feat: persist UI state

* test: fix var declaration

* test: increate e2e timeout

sometimes there might be a network latency to load CDN assets like the fonts. Let's give the tests a maximum of 1 minute to fully run.
2026-01-11 01:32:57 +01:00

24 lines
546 B
TypeScript

const keys: string[] = [];
const render = (key: string) => `nimbus:${key}`;
export const uniquePersistenceKey = (key: string): string => {
if (keys.includes(key)) {
const newKey = key + '-duplicate';
console.warn(`Key ${key} must be unique. '${newKey}' will be used instead.`);
return uniquePersistenceKey(newKey);
}
keys.push(key);
return render(key);
};
export const clearPersistentKeys = () => {
keys.forEach((key: string) => {
window.localStorage.removeItem(render(key));
});
};