@@ -8,6 +8,14 @@ import { useHotkeys } from 'react-hotkeys-hook'
88import { useTranslation } from 'react-i18next'
99
1010import { PageManagerDialog } from '@/components/PageManagerDialog'
11+ import {
12+ AlertDialog ,
13+ AlertDialogAction ,
14+ AlertDialogCancel ,
15+ AlertDialogContent ,
16+ AlertDialogDescription ,
17+ AlertDialogTitle ,
18+ } from '@/components/ui/alert-dialog'
1119import { Button } from '@/components/ui/button'
1220import { ScrollArea } from '@/components/ui/scroll-area'
1321import { useScene } from '@/hooks/useScene'
@@ -36,6 +44,12 @@ export function Navigator() {
3644 const viewportRef = useRef < HTMLDivElement | null > ( null )
3745 const { t } = useTranslation ( )
3846 const [ pageManagerOpen , setPageManagerOpen ] = useState ( false )
47+ const [ pageToDeleteId , setPageToDeleteId ] = useState < string | null > ( null )
48+
49+ const pageToDeleteIndex = useMemo ( ( ) => {
50+ if ( ! pageToDeleteId ) return - 1
51+ return pages . findIndex ( ( p ) => p . id === pageToDeleteId )
52+ } , [ pageToDeleteId , pages ] )
3953
4054 const handleSelect = useCallback (
4155 ( id : string , event : React . MouseEvent | React . KeyboardEvent ) => {
@@ -122,12 +136,9 @@ export function Navigator() {
122136 [ pages , pagesMap , pageId , setPage , totalPages , t , setSelectedPageIds ] ,
123137 )
124138
125- const handleDeletePage = useCallback (
126- ( id : string ) => {
127- void handleDeletePages ( new Set ( [ id ] ) )
128- } ,
129- [ handleDeletePages ] ,
130- )
139+ const handleDeletePage = useCallback ( ( id : string ) => {
140+ setPageToDeleteId ( id )
141+ } , [ ] )
131142
132143 const handleBatchDelete = useCallback ( ( ) => {
133144 void handleDeletePages ( selectedPageIds )
@@ -221,6 +232,36 @@ export function Navigator() {
221232 </ ScrollArea >
222233
223234 < PageManagerDialog open = { pageManagerOpen } onOpenChange = { setPageManagerOpen } />
235+
236+ < AlertDialog
237+ open = { ! ! pageToDeleteId }
238+ onOpenChange = { ( open ) => ! open && setPageToDeleteId ( null ) }
239+ >
240+ < AlertDialogContent >
241+ < div className = 'flex flex-col gap-1.5 text-center sm:text-left' >
242+ < AlertDialogTitle > { t ( 'navigator.deleteConfirmTitle' ) } </ AlertDialogTitle >
243+ < AlertDialogDescription >
244+ { t ( 'navigator.deleteConfirmDescription' , {
245+ index : pageToDeleteIndex + 1 ,
246+ } ) }
247+ </ AlertDialogDescription >
248+ </ div >
249+ < div className = 'flex flex-col-reverse gap-2 sm:flex-row sm:justify-end' >
250+ < AlertDialogCancel > { t ( 'common.cancel' , 'Cancel' ) } </ AlertDialogCancel >
251+ < AlertDialogAction
252+ onClick = { ( ) => {
253+ if ( pageToDeleteId ) {
254+ void handleDeletePages ( new Set ( [ pageToDeleteId ] ) )
255+ setPageToDeleteId ( null )
256+ }
257+ } }
258+ className = 'text-destructive-foreground bg-destructive hover:bg-destructive/90'
259+ >
260+ { t ( 'common.delete' , 'Delete' ) }
261+ </ AlertDialogAction >
262+ </ div >
263+ </ AlertDialogContent >
264+ </ AlertDialog >
224265 </ div >
225266 )
226267}
0 commit comments