mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 08:23:34 +00:00
Move Delete Project into ProjectInfoDialog
This commit is contained in:
3 files changed
+91
-95
No files matched your search
@@ -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'}
|
||||
</DropdownMenuItem>
|
||||
|
||||
<DropdownMenuSeparator />
|
||||
|
||||
<AlertDialog>
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem
|
||||
className="text-destructive focus:text-destructive cursor-pointer gap-2"
|
||||
onSelect={(e) => e.preventDefault()}
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
Delete Project
|
||||
</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Delete Project</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
Are you sure you want to delete "{projectName}"? This action cannot be undone and will permanently delete all project data including files.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={handleDeleteProject}
|
||||
disabled={isDeleting}
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
>
|
||||
{isDeleting ? (
|
||||
<>
|
||||
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
|
||||
Deleting...
|
||||
</>
|
||||
) : (
|
||||
'Delete Project'
|
||||
)}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
|
||||
|
||||
@@ -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 */}
|
||||
<Button
|
||||
onClick={handleExportProject}
|
||||
disabled={isExporting}
|
||||
disabled={isExporting || isDeleting}
|
||||
className="w-full gap-2"
|
||||
variant="outline"
|
||||
>
|
||||
@@ -139,6 +186,45 @@ export function ProjectInfoDialog({ project, open, onOpenChange }: ProjectInfoDi
|
||||
)}
|
||||
{isExporting ? 'Exporting...' : 'Export Project'}
|
||||
</Button>
|
||||
|
||||
{/* Delete Project Button */}
|
||||
<AlertDialog>
|
||||
<AlertDialogTrigger asChild>
|
||||
<Button
|
||||
variant="destructive"
|
||||
className="w-full gap-2"
|
||||
disabled={isExporting || isDeleting}
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
Delete Project
|
||||
</Button>
|
||||
</AlertDialogTrigger>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Delete Project</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
Are you sure you want to delete "{project.name}"? This action cannot be undone and will permanently delete all project data including files.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={handleDeleteProject}
|
||||
disabled={isDeleting}
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
>
|
||||
{isDeleting ? (
|
||||
<>
|
||||
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
|
||||
Deleting...
|
||||
</>
|
||||
) : (
|
||||
'Delete Project'
|
||||
)}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
@@ -200,14 +200,12 @@ export function ProjectView() {
|
||||
/>
|
||||
<ActionsMenu
|
||||
projectId={project.id}
|
||||
projectName={project.name}
|
||||
onNewChat={handleNewChat}
|
||||
onDeploy={runDeploy}
|
||||
isLoading={isAILoading}
|
||||
isBuildLoading={build.isPending}
|
||||
isDeployLoading={deploy.isPending}
|
||||
onFirstInteraction={handleFirstInteraction}
|
||||
onProjectDeleted={handleProjectDeleted}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
@@ -330,6 +328,7 @@ export function ProjectView() {
|
||||
project={project}
|
||||
open={isProjectInfoOpen}
|
||||
onOpenChange={setIsProjectInfoOpen}
|
||||
onProjectDeleted={handleProjectDeleted}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
@@ -406,14 +405,12 @@ export function ProjectView() {
|
||||
/>
|
||||
<ActionsMenu
|
||||
projectId={project.id}
|
||||
projectName={project.name}
|
||||
onNewChat={handleNewChat}
|
||||
onDeploy={runDeploy}
|
||||
isLoading={isAILoading}
|
||||
isBuildLoading={build.isPending}
|
||||
isDeployLoading={deploy.isPending}
|
||||
onFirstInteraction={handleFirstInteraction}
|
||||
onProjectDeleted={handleProjectDeleted}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
@@ -513,6 +510,7 @@ export function ProjectView() {
|
||||
project={project}
|
||||
open={isProjectInfoOpen}
|
||||
onOpenChange={setIsProjectInfoOpen}
|
||||
onProjectDeleted={handleProjectDeleted}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user