From b2da08d52d65003697d88beca50dc9be88d9e868 Mon Sep 17 00:00:00 2001
From: ergosteur <1992147+ergosteur@users.noreply.github.com>
Date: Sat, 7 Mar 2026 02:37:17 -0500
Subject: [PATCH] feat: add navigation protection and refine cached badge
visibility
---
src/App.tsx | 38 +++++++++++++++++++++++++++++++++++++-
1 file changed, 37 insertions(+), 1 deletion(-)
diff --git a/src/App.tsx b/src/App.tsx
index ae03cf3..b73f6f8 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -174,7 +174,7 @@ const ArchiveDashboard = ({
{isCached && (
-
+
Cached
@@ -629,6 +629,42 @@ export default function App() {
refreshCachedArchives();
}, [refreshCachedArchives]);
+ // Intercept back button and page exit when in an archive
+ useEffect(() => {
+ const inArchive = allPosts.length > 0;
+
+ const handleBeforeUnload = (e: BeforeUnloadEvent) => {
+ if (inArchive) {
+ e.preventDefault();
+ e.returnValue = ''; // Trigger browser confirmation dialog
+ }
+ };
+
+ 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 (inArchive) {
+ window.addEventListener('beforeunload', handleBeforeUnload);
+ window.addEventListener('popstate', handlePopState);
+ // Add a history entry so the back button has something to pop
+ window.history.pushState(null, '');
+ }
+
+ return () => {
+ window.removeEventListener('beforeunload', handleBeforeUnload);
+ window.removeEventListener('popstate', handlePopState);
+ };
+ }, [allPosts.length, resetProfileState]);
+
const filteredPosts = useMemo(() => {
if (activeTab === 'reels') return allPosts.filter(p => p.media.length === 1 && p.media[0].type === 'video');
if (activeTab === 'posts') return allPosts.filter(p => !(p.media.length === 1 && p.media[0].type === 'video'));