diff --git a/src/Utils/AutoSave.tsx b/src/Utils/AutoSave.tsx index 5cdf118650f..0c929f371e5 100644 --- a/src/Utils/AutoSave.tsx +++ b/src/Utils/AutoSave.tsx @@ -104,6 +104,23 @@ export function DraftSection(props: { }; }, []); + // Remove drafts older than 24 hours + useEffect(() => { + const keys = Object.keys(localStorage); + const now = Date.now(); + keys.forEach((key) => { + if (key.startsWith("form_draft_")) { + const savedDrafts = localStorage.getItem(key); + const drafts = savedDrafts ? JSON.parse(savedDrafts) : []; + const newDrafts = drafts.filter( + (draft: Draft) => now - draft.timestamp < 24 * 60 * 60 * 1000 + ); + localStorage.setItem(key, JSON.stringify(newDrafts)); + if (newDrafts.length === 0) localStorage.removeItem(key); + } + }); + }, []); + return ( <> {drafts && (