mirror of
https://github.com/ergosteur/instaarchive-viewer.git
synced 2026-07-04 11:07:15 -04:00
feat: add explicit confirmation for back button and refresh in archives
This commit is contained in:
21
src/App.tsx
21
src/App.tsx
@@ -635,20 +635,25 @@ export default function App() {
|
|||||||
|
|
||||||
const handleBeforeUnload = (e: BeforeUnloadEvent) => {
|
const handleBeforeUnload = (e: BeforeUnloadEvent) => {
|
||||||
if (inArchive) {
|
if (inArchive) {
|
||||||
|
const message = 'Are you sure you want to leave? Your current archive session will be cleared.';
|
||||||
e.preventDefault();
|
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) => {
|
const handlePopState = (e: PopStateEvent) => {
|
||||||
if (inArchive) {
|
if (inArchive) {
|
||||||
// Instead of going back, just exit the archive
|
if (window.confirm('Exit current archive and return to explorer?')) {
|
||||||
setAllPosts([]);
|
// Exit the archive
|
||||||
setAllStories([]);
|
setAllPosts([]);
|
||||||
setCurrentArchive(null);
|
setAllStories([]);
|
||||||
resetProfileState();
|
setCurrentArchive(null);
|
||||||
// Stay on the same page
|
resetProfileState();
|
||||||
window.history.pushState(null, '');
|
} else {
|
||||||
|
// Push the state back so the URL stays the same and we can intercept again
|
||||||
|
window.history.pushState(null, '');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user