This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
export const selectedAppStorageKey = 'studio-admin:selected-app-id';
|
||||
export const selectedComponentByAppStorageKey = 'studio-admin:selected-component-by-app-id';
|
||||
const legacySelectedAppStorageKey = 'studio-selected-app-id';
|
||||
|
||||
export function getStoredSelectedAppId() {
|
||||
@@ -19,3 +20,32 @@ export function setStoredSelectedAppId(appId: string) {
|
||||
if (!appId) return;
|
||||
window.localStorage.setItem(selectedAppStorageKey, appId);
|
||||
}
|
||||
|
||||
function readSelectedComponentMap(): Record<string, string> {
|
||||
const raw = window.localStorage.getItem(selectedComponentByAppStorageKey);
|
||||
if (!raw) return {};
|
||||
|
||||
try {
|
||||
const parsed = JSON.parse(raw) as unknown;
|
||||
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return {};
|
||||
return Object.fromEntries(
|
||||
Object.entries(parsed)
|
||||
.filter((entry): entry is [string, string] => typeof entry[0] === 'string' && typeof entry[1] === 'string')
|
||||
);
|
||||
} catch {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
export function getStoredSelectedComponentId(appId: string) {
|
||||
if (!appId) return '';
|
||||
return readSelectedComponentMap()[appId] ?? '';
|
||||
}
|
||||
|
||||
export function setStoredSelectedComponentId(appId: string, componentId: string) {
|
||||
if (!appId || !componentId) return;
|
||||
window.localStorage.setItem(selectedComponentByAppStorageKey, JSON.stringify({
|
||||
...readSelectedComponentMap(),
|
||||
[appId]: componentId,
|
||||
}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user