Spaces:
Runtime error
Runtime error
| export type ConferenceProgress = { | |
| paper: boolean; | |
| poster: boolean; | |
| notification: boolean; | |
| }; | |
| const STORAGE_KEY = "ai-deadlines-progress-v1"; | |
| const emptyProgress: ConferenceProgress = { | |
| paper: false, | |
| poster: false, | |
| notification: false, | |
| }; | |
| const readAllProgress = (): Record<string, ConferenceProgress> => { | |
| if (typeof window === "undefined") return {}; | |
| try { | |
| const raw = window.localStorage.getItem(STORAGE_KEY); | |
| if (!raw) return {}; | |
| const parsed = JSON.parse(raw) as Record<string, ConferenceProgress>; | |
| if (!parsed || typeof parsed !== "object") return {}; | |
| return parsed; | |
| } catch (error) { | |
| console.error("Error reading progress from localStorage:", error); | |
| return {}; | |
| } | |
| }; | |
| const writeAllProgress = (progressMap: Record<string, ConferenceProgress>) => { | |
| if (typeof window === "undefined") return; | |
| try { | |
| window.localStorage.setItem(STORAGE_KEY, JSON.stringify(progressMap)); | |
| } catch (error) { | |
| console.error("Error writing progress to localStorage:", error); | |
| } | |
| }; | |
| export const getProgress = (confKey: string): ConferenceProgress => { | |
| const progressMap = readAllProgress(); | |
| return progressMap[confKey] ?? emptyProgress; | |
| }; | |
| export const setProgress = (confKey: string, progress: ConferenceProgress) => { | |
| const progressMap = readAllProgress(); | |
| progressMap[confKey] = progress; | |
| writeAllProgress(progressMap); | |
| }; | |