Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Form Drafts to expire after 24 hours #7125

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/Utils/AutoSave.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 && (
Expand Down
Loading