From 9e306eb85e92e9c93eada936859c462d34e70ef8 Mon Sep 17 00:00:00 2001 From: ergosteur <1992147+ergosteur@users.noreply.github.com> Date: Sat, 7 Mar 2026 02:39:39 -0500 Subject: [PATCH] feat: add explicit confirmation for back button and refresh in archives --- src/App.tsx | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index b73f6f8..149d2ff 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -635,20 +635,25 @@ export default function App() { const handleBeforeUnload = (e: BeforeUnloadEvent) => { if (inArchive) { + const message = 'Are you sure you want to leave? Your current archive session will be cleared.'; e.preventDefault(); - e.returnValue = ''; // Trigger browser confirmation dialog + e.returnValue = message; // Standard for most browsers + return message; // For some older browsers } }; const handlePopState = (e: PopStateEvent) => { if (inArchive) { - // Instead of going back, just exit the archive - setAllPosts([]); - setAllStories([]); - setCurrentArchive(null); - resetProfileState(); - // Stay on the same page - window.history.pushState(null, ''); + if (window.confirm('Exit current archive and return to explorer?')) { + // Exit the archive + setAllPosts([]); + setAllStories([]); + setCurrentArchive(null); + resetProfileState(); + } else { + // Push the state back so the URL stays the same and we can intercept again + window.history.pushState(null, ''); + } } };