Skip to content

Commit 0ef5524

Browse files
msujawsclaude
andcommitted
feat(ux): warn user before leaving with unsaved changes
Add beforeunload event listener to show browser confirmation dialog when user tries to navigate away with staged changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 5c95a80 commit 0ef5524

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/App.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback, useState } from 'react'
1+
import { useCallback, useEffect, useState } from 'react'
22
import { ToastContainer } from './components/Notifications/ToastContainer'
33
import { ApiKeyInput } from './components/Auth/ApiKeyInput'
44
import { ApiKeyStatus } from './components/Auth/ApiKeyStatus'
@@ -36,6 +36,20 @@ function App() {
3636
const removeToast = useStore((state) => state.removeToast)
3737
const addToast = useStore((state) => state.addToast)
3838

39+
// Warn user before leaving page with unsaved staged changes
40+
useEffect(() => {
41+
const handleBeforeUnload = (event: BeforeUnloadEvent) => {
42+
if (changes.size > 0) {
43+
event.preventDefault()
44+
}
45+
}
46+
47+
window.addEventListener('beforeunload', handleBeforeUnload)
48+
return () => {
49+
window.removeEventListener('beforeunload', handleBeforeUnload)
50+
}
51+
}, [changes.size])
52+
3953
// Handle close modal
4054
const handleCloseModal = useCallback(() => {
4155
setShowApiKeyModal(false)

0 commit comments

Comments
 (0)