Adds first version of the app. Local storage only.
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import type { Project } from '../domain/types'
|
||||
import { normalizeProject } from './exportImport'
|
||||
import type { ProjectRepository } from './ProjectRepository'
|
||||
|
||||
const STORAGE_KEY = 'av-planner:project:v1'
|
||||
|
||||
export class LocalStorageProjectRepository implements ProjectRepository {
|
||||
async load(): Promise<Project | null> {
|
||||
try {
|
||||
const raw = window.localStorage.getItem(STORAGE_KEY)
|
||||
if (!raw) return null
|
||||
return normalizeProject(JSON.parse(raw) as Project)
|
||||
} catch (err) {
|
||||
console.error('Failed to load project from localStorage', err)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
async save(project: Project): Promise<void> {
|
||||
window.localStorage.setItem(STORAGE_KEY, JSON.stringify(project))
|
||||
}
|
||||
|
||||
async clear(): Promise<void> {
|
||||
window.localStorage.removeItem(STORAGE_KEY)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user