Spaces:
Sleeping
Sleeping
File size: 1,388 Bytes
cecc383 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
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);
};
|