Sidebar
This commit is contained in:
@@ -90,8 +90,42 @@ export function loadWorkspaceFromLocalStorage(id: string): Workspace {
|
||||
export function saveWorkspaceToLocalStorage(workspace: Workspace): void {
|
||||
try {
|
||||
const serialized = JSON.stringify(workspace);
|
||||
// keep using raw id for backwards compatibility
|
||||
localStorage.setItem(workspace.id, serialized);
|
||||
} catch (err) {
|
||||
console.error("Failed to save workspace:", err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Scan localStorage and return all entries that appear to be workspaces.
|
||||
* We ignore keys starting with "route_" which are used for routing state.
|
||||
*/
|
||||
export function listWorkspaces(): Workspace[] {
|
||||
const workspaces: Workspace[] = [];
|
||||
for (let i = 0; i < localStorage.length; i++) {
|
||||
const key = localStorage.key(i);
|
||||
if (!key) continue;
|
||||
if (key.startsWith("route_")) continue;
|
||||
|
||||
const raw = localStorage.getItem(key);
|
||||
if (!raw) continue;
|
||||
|
||||
try {
|
||||
const parsed = JSON.parse(raw);
|
||||
if (
|
||||
parsed &&
|
||||
typeof parsed === "object" &&
|
||||
typeof parsed.id === "string" &&
|
||||
typeof parsed.name === "string" &&
|
||||
parsed.entities &&
|
||||
parsed.layout
|
||||
) {
|
||||
workspaces.push(parsed as Workspace);
|
||||
}
|
||||
} catch {
|
||||
// ignore non-json values
|
||||
}
|
||||
}
|
||||
return workspaces;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user