11import { useState , useMemo , useEffect , useCallback , useRef } from 'react'
2- import { useYjs } from '../../hooks/useYjs'
2+ import { useYjs , undo , redo } from '../../hooks/useYjs'
33import { useSearch , useDebounce } from '../../hooks/useSearch'
44import { useHotkeys } from '../../hooks/useHotkeys'
5+ import { useToast } from '../../hooks/useToast'
56import { BookmarkItem } from './BookmarkItem'
67import { BookmarkInlineCard } from './BookmarkInlineCard'
78import { InboxView } from './InboxView'
@@ -11,6 +12,7 @@ import { SettingsView } from '../ui/SettingsView'
1112import { HelpModal } from '../ui/HelpModal'
1213import { Modal } from '../ui/Modal'
1314import { Button } from '../ui/Button'
15+ import { ToastContainer } from '../ui/Toast'
1416import { PackageOpen } from '../ui/Icons'
1517import {
1618 getAllBookmarks ,
@@ -20,6 +22,7 @@ import {
2022export function BookmarkList ( ) {
2123 const { bookmarks : bookmarksMap , synced } = useYjs ( )
2224 const [ bookmarks , setBookmarks ] = useState ( [ ] )
25+ const { toasts, addToast, removeToast } = useToast ( )
2326 const [ currentView , setCurrentView ] = useState ( 'bookmarks' )
2427
2528 useEffect ( ( ) => {
@@ -189,14 +192,35 @@ export function BookmarkList() {
189192
190193 const confirmDelete = useCallback ( ( ) => {
191194 if ( deleteConfirmBookmark ) {
195+ const bookmarkTitle = deleteConfirmBookmark . title
192196 try {
193197 deleteBookmark ( deleteConfirmBookmark . _id )
198+ addToast ( {
199+ message : `Deleted "${ bookmarkTitle } "` ,
200+ action : ( ) => {
201+ undo ( )
202+ } ,
203+ actionLabel : 'Undo' ,
204+ duration : 5000 ,
205+ } )
194206 } catch ( error ) {
195207 console . error ( 'Failed to delete bookmark:' , error )
196208 }
197209 setDeleteConfirmBookmark ( null )
198210 }
199- } , [ deleteConfirmBookmark ] )
211+ } , [ deleteConfirmBookmark , addToast ] )
212+
213+ const handleUndo = useCallback ( ( ) => {
214+ if ( undo ( ) ) {
215+ addToast ( { message : 'Undone' , duration : 2000 } )
216+ }
217+ } , [ addToast ] )
218+
219+ const handleRedo = useCallback ( ( ) => {
220+ if ( redo ( ) ) {
221+ addToast ( { message : 'Redone' , duration : 2000 } )
222+ }
223+ } , [ addToast ] )
200224
201225 useEffect ( ( ) => {
202226 setSelectedIndex ( - 1 )
@@ -228,6 +252,8 @@ export function BookmarkList() {
228252 'd' : promptDeleteSelected ,
229253 'mod+k' : focusSearch ,
230254 'q' : exitInbox ,
255+ 'mod+z' : handleUndo ,
256+ 'mod+shift+z' : handleRedo ,
231257 } )
232258
233259 const handleAddNew = openNewBookmarkForm
@@ -241,14 +267,24 @@ export function BookmarkList() {
241267 setEditingBookmarkId ( null )
242268 } , [ ] )
243269
244- const handleDelete = ( bookmarkId ) => {
270+ const handleDelete = useCallback ( ( bookmarkId ) => {
271+ const bookmark = bookmarks . find ( b => b . _id === bookmarkId )
272+ const bookmarkTitle = bookmark ?. title || 'Bookmark'
245273 try {
246274 deleteBookmark ( bookmarkId )
275+ addToast ( {
276+ message : `Deleted "${ bookmarkTitle } "` ,
277+ action : ( ) => {
278+ undo ( )
279+ } ,
280+ actionLabel : 'Undo' ,
281+ duration : 5000 ,
282+ } )
247283 } catch ( error ) {
248284 console . error ( 'Failed to delete bookmark:' , error )
249- alert ( 'Failed to delete bookmark: ' + error . message )
285+ addToast ( { message : 'Failed to delete bookmark' , duration : 3000 } )
250286 }
251- }
287+ } , [ bookmarks , addToast ] )
252288
253289 const handleTagClick = ( tag ) => {
254290 setFilterView ( 'tag' )
@@ -393,7 +429,7 @@ export function BookmarkList() {
393429 title = "Delete bookmark?"
394430 >
395431 < p className = "text-sm text-muted-foreground mb-4" >
396- This will permanently delete "{ deleteConfirmBookmark ?. title } ".
432+ Delete "{ deleteConfirmBookmark ?. title } "? You can undo this action .
397433 </ p >
398434 < div className = "flex justify-end gap-2" >
399435 < Button variant = "ghost" onClick = { ( ) => setDeleteConfirmBookmark ( null ) } >
@@ -404,6 +440,8 @@ export function BookmarkList() {
404440 </ Button >
405441 </ div >
406442 </ Modal >
443+
444+ < ToastContainer toasts = { toasts } onRemove = { removeToast } />
407445 </ div >
408446 )
409447}
0 commit comments