feat: refactor names
This commit is contained in:
36
frontend/src/app/pleroma/projectGraphStorage.ts
Normal file
36
frontend/src/app/pleroma/projectGraphStorage.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Per-project graph persistence (localStorage).
|
||||
* Used by CanvasPage to load/save and by ProjectsTablePage for export.
|
||||
*/
|
||||
|
||||
export const PROJECT_FILE_EXT = '.zui.json'
|
||||
export const PROJECT_VERSION = 1
|
||||
|
||||
const GRAPH_KEY_PREFIX = 'zui_graph_'
|
||||
|
||||
export function getGraphStorageKey(projectId: string): string {
|
||||
return `${GRAPH_KEY_PREFIX}${projectId}`
|
||||
}
|
||||
|
||||
export type GraphState = { version: number; nodes: unknown[]; edges: unknown[] }
|
||||
|
||||
export function loadGraphFromStorage(projectId: string): GraphState | null {
|
||||
try {
|
||||
const raw = localStorage.getItem(getGraphStorageKey(projectId))
|
||||
if (!raw) return null
|
||||
const data = JSON.parse(raw) as unknown
|
||||
if (!data || typeof data !== 'object' || !Array.isArray((data as GraphState).nodes) || !Array.isArray((data as GraphState).edges))
|
||||
return null
|
||||
return data as GraphState
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export function saveGraphToStorage(projectId: string, state: GraphState): void {
|
||||
localStorage.setItem(getGraphStorageKey(projectId), JSON.stringify(state))
|
||||
}
|
||||
|
||||
export function removeGraphFromStorage(projectId: string): void {
|
||||
localStorage.removeItem(getGraphStorageKey(projectId))
|
||||
}
|
||||
Reference in New Issue
Block a user