From afa35fb41d7950de2ccbdc81d5043f25d26504a6 Mon Sep 17 00:00:00 2001 From: Pavel Rybalko Date: Sun, 12 Oct 2025 10:57:26 +0300 Subject: [PATCH] Add Storage API persistence to protect calendar data --- src/contexts/CalendarContext.tsx | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/contexts/CalendarContext.tsx b/src/contexts/CalendarContext.tsx index 90d325a..cb7f254 100644 --- a/src/contexts/CalendarContext.tsx +++ b/src/contexts/CalendarContext.tsx @@ -70,6 +70,32 @@ export const CalendarProvider: React.FC = ({ children }) } }, [currentYear]) + useEffect(() => { + const requestPersistentStorage = async () => { + if (navigator.storage && navigator.storage.persist) { + try { + const isPersisted = await navigator.storage.persisted() + if (isPersisted) { + console.log("Storage is already persistent") + } else { + const granted = await navigator.storage.persist() + if (granted) { + console.log("Persistent storage granted") + } else { + console.log("Persistent storage denied") + } + } + } catch (error) { + console.error("Error requesting persistent storage:", error) + } + } else { + console.log("Storage API not supported in this browser") + } + } + + void requestPersistentStorage() + }, []) + const saveToLocalStorage = (data: StoredData) => { try { localStorage.setItem(STORAGE_KEY, JSON.stringify(data))