feat(store): mirror current report to sessionStorage

This commit is contained in:
Bastien Chanot committed 2026-05-18 21:05:42 +02:00
1 parent 1b87c1f89f
commit 1c51c672e8
2 files changed
+57

No files matched your search

+22
View File
@@ -116,3 +116,25 @@ export const useReportStore = create<ReportStore>((set) => ({
reset: () => set({ report: null, activeObservationIndex: 0 }),
}))
const DRAFT_KEY = 'osteo:draft'
useReportStore.subscribe((state) => {
if (typeof sessionStorage === 'undefined') return
if (state.report) {
sessionStorage.setItem(DRAFT_KEY, JSON.stringify(state.report))
} else {
sessionStorage.removeItem(DRAFT_KEY)
}
})
export function readPersistedDraft(): Report | null {
if (typeof sessionStorage === 'undefined') return null
const raw = sessionStorage.getItem(DRAFT_KEY)
if (!raw) return null
try {
return JSON.parse(raw) as Report
} catch {
return null
}
}