From cadebaaa0ea66936281530d2bc1beaa17908c925 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 22 Sep 2025 02:31:59 -0500 Subject: [PATCH] Move Delete Project into ProjectInfoDialog --- src/components/ActionsMenu.tsx | 90 +--------------------------- src/components/ProjectInfoDialog.tsx | 90 +++++++++++++++++++++++++++- src/pages/ProjectView.tsx | 6 +- 3 files changed, 91 insertions(+), 95 deletions(-) diff --git a/src/components/ActionsMenu.tsx b/src/components/ActionsMenu.tsx index 6f9eadad..a580c18c 100644 --- a/src/components/ActionsMenu.tsx +++ b/src/components/ActionsMenu.tsx @@ -4,20 +4,8 @@ import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, - DropdownMenuSeparator, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; -import { - AlertDialog, - AlertDialogAction, - AlertDialogCancel, - AlertDialogContent, - AlertDialogDescription, - AlertDialogFooter, - AlertDialogHeader, - AlertDialogTitle, - AlertDialogTrigger, -} from '@/components/ui/alert-dialog'; import { GitBranch, MoreHorizontal, @@ -25,17 +13,12 @@ import { CloudUpload, Loader2, History, - Trash2, } from 'lucide-react'; import { GitHistoryDialog } from '@/components/ai/GitHistoryDialog'; import { GitDialog } from '@/components/GitDialog'; -import { useNavigate } from 'react-router-dom'; -import { useProjectsManager } from '@/hooks/useProjectsManager'; -import { useToast } from '@/hooks/useToast'; interface ActionsMenuProps { projectId: string; - projectName: string; onNewChat: () => void; onDeploy: () => void; isLoading?: boolean; @@ -43,12 +26,10 @@ interface ActionsMenuProps { isDeployLoading?: boolean; disabled?: boolean; onFirstInteraction?: () => void; - onProjectDeleted?: () => void; } export function ActionsMenu({ projectId, - projectName, onNewChat, onDeploy, isLoading = false, @@ -56,43 +37,13 @@ export function ActionsMenu({ isDeployLoading = false, disabled = false, onFirstInteraction, - onProjectDeleted }: ActionsMenuProps) { const [gitHistoryOpen, setGitHistoryOpen] = useState(false); const [gitDialogOpen, setGitDialogOpen] = useState(false); - const [isDeleting, setIsDeleting] = useState(false); - const navigate = useNavigate(); - const projectsManager = useProjectsManager(); - const { toast } = useToast(); + const isAnyLoading = isLoading || isBuildLoading || isDeployLoading; - const isAnyLoading = isLoading || isBuildLoading || isDeployLoading || isDeleting; - const handleDeleteProject = async () => { - setIsDeleting(true); - try { - await projectsManager.deleteProject(projectId); - - toast({ - title: "Project deleted", - description: `"${projectName}" has been permanently deleted.`, - }); - - // Navigate back to home and notify parent - navigate('/'); - if (onProjectDeleted) { - onProjectDeleted(); - } - } catch (error) { - toast({ - title: "Failed to delete project", - description: error instanceof Error ? error.message : "An unexpected error occurred", - variant: "destructive", - }); - } finally { - setIsDeleting(false); - } - }; return ( <> @@ -151,45 +102,6 @@ export function ActionsMenu({ )} {isDeployLoading ? 'Deploying...' : 'Deploy'} - - - - - - e.preventDefault()} - > - - Delete Project - - - - - Delete Project - - Are you sure you want to delete "{projectName}"? This action cannot be undone and will permanently delete all project data including files. - - - - Cancel - - {isDeleting ? ( - <> - - Deleting... - - ) : ( - 'Delete Project' - )} - - - - diff --git a/src/components/ProjectInfoDialog.tsx b/src/components/ProjectInfoDialog.tsx index 0c4bb8cd..8460951a 100644 --- a/src/components/ProjectInfoDialog.tsx +++ b/src/components/ProjectInfoDialog.tsx @@ -6,14 +6,28 @@ import { DialogHeader, DialogTitle, } from '@/components/ui/dialog'; +import { + AlertDialog, + AlertDialogAction, + AlertDialogCancel, + AlertDialogContent, + AlertDialogDescription, + AlertDialogFooter, + AlertDialogHeader, + AlertDialogTitle, + AlertDialogTrigger, +} from '@/components/ui/alert-dialog'; import { Button } from '@/components/ui/button'; import { useToast } from '@/hooks/useToast'; import { useFS } from '@/hooks/useFS'; +import { useProjectsManager } from '@/hooks/useProjectsManager'; +import { useNavigate } from 'react-router-dom'; import { Calendar, Folder, Download, Loader2, + Trash2, } from 'lucide-react'; import JSZip from 'jszip'; @@ -21,12 +35,16 @@ interface ProjectInfoDialogProps { project: Project; open: boolean; onOpenChange: (open: boolean) => void; + onProjectDeleted?: () => void; } -export function ProjectInfoDialog({ project, open, onOpenChange }: ProjectInfoDialogProps) { +export function ProjectInfoDialog({ project, open, onOpenChange, onProjectDeleted }: ProjectInfoDialogProps) { const [isExporting, setIsExporting] = useState(false); + const [isDeleting, setIsDeleting] = useState(false); const { toast } = useToast(); const { fs } = useFS(); + const projectsManager = useProjectsManager(); + const navigate = useNavigate(); const formatDistanceToNow = (date: Date) => { const now = new Date(); @@ -40,6 +58,35 @@ export function ProjectInfoDialog({ project, open, onOpenChange }: ProjectInfoDi return `${Math.floor(diffInSeconds / 31536000)} years ago`; }; + const handleDeleteProject = async () => { + setIsDeleting(true); + try { + await projectsManager.deleteProject(project.id); + + toast({ + title: "Project deleted", + description: `"${project.name}" has been permanently deleted.`, + }); + + // Close the dialog first + onOpenChange(false); + + // Navigate back to home and notify parent + navigate('/'); + if (onProjectDeleted) { + onProjectDeleted(); + } + } catch (error) { + toast({ + title: "Failed to delete project", + description: error instanceof Error ? error.message : "An unexpected error occurred", + variant: "destructive", + }); + } finally { + setIsDeleting(false); + } + }; + const handleExportProject = async () => { setIsExporting(true); try { @@ -128,7 +175,7 @@ export function ProjectInfoDialog({ project, open, onOpenChange }: ProjectInfoDi {/* Export Project Button */} + + {/* Delete Project Button */} + + + + + + + Delete Project + + Are you sure you want to delete "{project.name}"? This action cannot be undone and will permanently delete all project data including files. + + + + Cancel + + {isDeleting ? ( + <> + + Deleting... + + ) : ( + 'Delete Project' + )} + + + + diff --git a/src/pages/ProjectView.tsx b/src/pages/ProjectView.tsx index d2c709d8..e289dbf3 100644 --- a/src/pages/ProjectView.tsx +++ b/src/pages/ProjectView.tsx @@ -200,14 +200,12 @@ export function ProjectView() { /> ) : ( @@ -330,6 +328,7 @@ export function ProjectView() { project={project} open={isProjectInfoOpen} onOpenChange={setIsProjectInfoOpen} + onProjectDeleted={handleProjectDeleted} /> )} @@ -406,14 +405,12 @@ export function ProjectView() { /> ) : ( @@ -513,6 +510,7 @@ export function ProjectView() { project={project} open={isProjectInfoOpen} onOpenChange={setIsProjectInfoOpen} + onProjectDeleted={handleProjectDeleted} /> )}