From 5a36bf308fd03572e46d743e3b8f64fbed18e1cc Mon Sep 17 00:00:00 2001 From: yiling Date: Sun, 24 May 2026 09:59:35 +0800 Subject: [PATCH] feat(ui): add delete confirmation dialog for file list and cards --- .../components/file-browser/context-menu.tsx | 38 +------------------ .../components/file-browser/file-browser.tsx | 35 +++++++++++++++++ .../file-browser/use-file-actions.ts | 20 ++++++++-- 3 files changed, 53 insertions(+), 40 deletions(-) diff --git a/src/ui/components/file-browser/context-menu.tsx b/src/ui/components/file-browser/context-menu.tsx index 9911a25b..d7f6dba3 100644 --- a/src/ui/components/file-browser/context-menu.tsx +++ b/src/ui/components/file-browser/context-menu.tsx @@ -5,17 +5,6 @@ import { ContextMenuSeparator, } from '@/ui/components/ui/context-menu' import { Download, Edit, FolderPlus, Trash2, UploadCloud, History, FileText } from 'lucide-react' -import { useState } from 'react' -import { - AlertDialog, - AlertDialogAction, - AlertDialogCancel, - AlertDialogContent, - AlertDialogDescription, - AlertDialogFooter, - AlertDialogHeader, - AlertDialogTitle, -} from '../ui/alert-dialog' interface FileBrowserContextMenuProps { item: AssetInfo | null @@ -52,14 +41,11 @@ export function FileBrowserContextMenu({ isShareView, onRemoveFromShare, }: FileBrowserContextMenuProps) { - const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false) - const allItems = [...folders, ...files] const selectedItems = allItems.filter((i) => selectedIds.has(i.id!)) const isItemSelected = item && selectedIds.has(item.id!) const itemsToModify = isItemSelected ? selectedItems : item ? [item] : [] const itemsToDelete = itemsToModify - const deleteCount = itemsToDelete.length const itemsToRestore = itemsToModify const handleRename = () => { @@ -69,7 +55,7 @@ export function FileBrowserContextMenu({ } const handleDelete = () => { - setIsDeleteDialogOpen(true) + onDelete(itemsToDelete) } const handleDownload = () => { @@ -194,28 +180,6 @@ export function FileBrowserContextMenu({ return ( <> {contextMenuContent} - - - - Are you sure? - - You are about to delete {deleteCount} item(s). Deleted items can be recovered for 30 - days before being permanently deleted. - - - - Cancel - { - onDelete(itemsToDelete) - setIsDeleteDialogOpen(false) - }} - > - Delete - - - - ) } diff --git a/src/ui/components/file-browser/file-browser.tsx b/src/ui/components/file-browser/file-browser.tsx index 5bef2408..efd6c3fa 100644 --- a/src/ui/components/file-browser/file-browser.tsx +++ b/src/ui/components/file-browser/file-browser.tsx @@ -23,6 +23,16 @@ import { FileListItem } from './file-list-item' import { FolderCard } from './folder-card' import { Button } from '../ui/button' import { ContextMenu, ContextMenuTrigger } from '../ui/context-menu' +import { + AlertDialog, + AlertDialogAction, + AlertDialogCancel, + AlertDialogContent, + AlertDialogDescription, + AlertDialogFooter, + AlertDialogHeader, + AlertDialogTitle, +} from '../ui/alert-dialog' import { useFileActions } from './use-file-actions' interface FileBrowserProps { @@ -110,6 +120,9 @@ export function FileBrowser({ handleDownload, handleAction, onRenameSubmit, + isDeleteDialogOpen, + setIsDeleteDialogOpen, + confirmDelete, } = useFileActions({ teamId, projectId, @@ -680,6 +693,28 @@ export function FileBrowser({ onChange={handleFileChange} /> {renderContent()} + + + + + Delete Asset? + + Deleted items can be recovered for 30 days before being permanently deleted. + + + + Cancel + { + confirmDelete() + }} + className="bg-destructive text-destructive-foreground hover:bg-destructive/90" + > + Delete + + + + ) } diff --git a/src/ui/components/file-browser/use-file-actions.ts b/src/ui/components/file-browser/use-file-actions.ts index 99ed9f68..ad471cfa 100644 --- a/src/ui/components/file-browser/use-file-actions.ts +++ b/src/ui/components/file-browser/use-file-actions.ts @@ -24,6 +24,8 @@ export function useFileActions({ selectedIds, }: UseFileActionsProps) { const [editingItemId, setEditingItemId] = useState(null) + const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false) + const [itemsToDelete, setItemsToDelete] = useState([]) const queryClient = useQueryClient() const $createFolder = client.api.teams[':teamId'].folders.$post @@ -113,9 +115,9 @@ export function useFileActions({ setEditingItemId(item.id!) } - const handleDelete = (items: AssetInfo[]) => { - const fileIds = items.filter((i) => i.type === 'file').map((i) => i.id!) - const folderIds = items.filter((i) => i.type === 'folder').map((i) => i.id!) + const confirmDelete = () => { + const fileIds = itemsToDelete.filter((i) => i.type === 'file').map((i) => i.id!) + const folderIds = itemsToDelete.filter((i) => i.type === 'folder').map((i) => i.id!) if (fileIds.length > 0) { deleteFiles( @@ -142,6 +144,14 @@ export function useFileActions({ }, ) } + + setIsDeleteDialogOpen(false) + setItemsToDelete([]) + } + + const handleDelete = (items: AssetInfo[]) => { + setItemsToDelete(items) + setIsDeleteDialogOpen(true) } const handleRestore = (items: AssetInfo[]) => { @@ -269,5 +279,9 @@ export function useFileActions({ handleNewFolder, handleAction, onRenameSubmit, + isDeleteDialogOpen, + setIsDeleteDialogOpen, + itemsToDelete, + confirmDelete, } }