From 668a6c79d9d5921da3b4ef4c6030af24626f2696 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 22 Sep 2025 01:08:05 -0500 Subject: [PATCH] Greatly simplify ProjectInfoDialog, move Export Project into there --- src/components/ActionsMenu.tsx | 108 +------ src/components/ProjectInfoDialog.tsx | 409 +++++++-------------------- 2 files changed, 99 insertions(+), 418 deletions(-) diff --git a/src/components/ActionsMenu.tsx b/src/components/ActionsMenu.tsx index 1d18e4bd..3a861ec1 100644 --- a/src/components/ActionsMenu.tsx +++ b/src/components/ActionsMenu.tsx @@ -26,7 +26,6 @@ import { CloudUpload, Loader2, History, - Download, Trash2, } from 'lucide-react'; import { GitHistoryDialog } from '@/components/ai/GitHistoryDialog'; @@ -34,9 +33,6 @@ import { GitDialog } from '@/components/GitDialog'; import { useNavigate } from 'react-router-dom'; import { useProjectsManager } from '@/hooks/useProjectsManager'; import { useToast } from '@/hooks/useToast'; -import { useGit } from '@/hooks/useGit'; -import { useFS } from '@/hooks/useFS'; -import JSZip from 'jszip'; interface ActionsMenuProps { projectId: string; @@ -68,15 +64,12 @@ export function ActionsMenu({ const [gitHistoryOpen, setGitHistoryOpen] = useState(false); const [gitDialogOpen, setGitDialogOpen] = useState(false); const [isDeleting, setIsDeleting] = useState(false); - const [isExporting, setIsExporting] = useState(false); const navigate = useNavigate(); const projectsManager = useProjectsManager(); const { toast } = useToast(); - const { fs } = useFS(); - const { git } = useGit(); - const isAnyLoading = isLoading || isBuildLoading || isDeployLoading || isDeleting || isExporting; + const isAnyLoading = isLoading || isBuildLoading || isDeployLoading || isDeleting; const handleDeleteProject = async () => { setIsDeleting(true); @@ -104,92 +97,6 @@ export function ActionsMenu({ } }; - const handleExportProject = async () => { - setIsExporting(true); - try { - const zip = new JSZip(); - const projectPath = `/projects/${projectId}`; - - // Recursive function to add files and directories to zip from a specific project - const addProjectToZip = async (dirPath: string, zipFolder: JSZip) => { - try { - const entries = await fs.readdir(dirPath, { withFileTypes: true }); - - for (const entry of entries) { - const fullPath = `${dirPath}/${entry.name}`; - - if (entry.isDirectory()) { - // Create folder in zip and recursively add its contents - const folder = zipFolder.folder(entry.name); - if (folder) { - await addProjectToZip(fullPath, folder); - } - } else if (entry.isFile()) { - // Add file to zip - try { - const fileContent = await fs.readFile(fullPath); - zipFolder.file(entry.name, fileContent); - } catch (error) { - console.warn(`Failed to read file ${fullPath}:`, error); - } - } - } - } catch (error) { - console.warn(`Failed to read directory ${dirPath}:`, error); - } - }; - - // Start from the project directory - await addProjectToZip(projectPath, zip); - - // Generate zip file - const content = await zip.generateAsync({ type: 'blob' }); - - // Create download link - const url = URL.createObjectURL(content); - const link = document.createElement('a'); - link.href = url; - - // Generate filename with commit hash - let filename = `${projectName}.zip`; - try { - // Get the current commit hash - const commits = await git.log({ - dir: projectPath, - depth: 1, - }); - - if (commits.length > 0) { - const commitHash = commits[0].oid.substring(0, 7); // Truncate to 7 characters - filename = `${projectName}-${commitHash}.zip`; - } - } catch (error) { - console.warn('Failed to get commit hash, using project name only:', error); - } - - link.download = filename; - - document.body.appendChild(link); - link.click(); - document.body.removeChild(link); - URL.revokeObjectURL(url); - - toast({ - title: "Project exported successfully", - description: `"${projectName}" has been downloaded as a zip file.`, - }); - } catch (error) { - console.error('Failed to export project:', error); - toast({ - title: "Failed to export project", - description: error instanceof Error ? error.message : "An unexpected error occurred", - variant: "destructive", - }); - } finally { - setIsExporting(false); - } - }; - return ( <> @@ -232,19 +139,6 @@ export function ActionsMenu({ Rollback - - {isExporting ? ( - - ) : ( - - )} - {isExporting ? 'Exporting...' : 'Export Project'} - - { if (onFirstInteraction) onFirstInteraction(); diff --git a/src/components/ProjectInfoDialog.tsx b/src/components/ProjectInfoDialog.tsx index 33fdf923..0c4bb8cd 100644 --- a/src/components/ProjectInfoDialog.tsx +++ b/src/components/ProjectInfoDialog.tsx @@ -1,36 +1,21 @@ -import { useState, useEffect } from 'react'; +import { useState } from 'react'; import { type Project } from '@/lib/ProjectsManager'; -import { useProjectsManager } from '@/hooks/useProjectsManager'; -import { useGitStatus } from '@/hooks/useGitStatus'; import { Dialog, DialogContent, - DialogDescription, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; -import { Badge } from '@/components/ui/badge'; -import { Separator } from '@/components/ui/separator'; -import { Skeleton } from '@/components/ui/skeleton'; +import { Button } from '@/components/ui/button'; +import { useToast } from '@/hooks/useToast'; +import { useFS } from '@/hooks/useFS'; import { Calendar, Folder, - GitBranch, - Package, - FileText, - GitCommit, - GitMerge, - Globe, - Clock, - User, - Hash, - AlertCircle, - CheckCircle, - Plus, - Minus, - Edit, - Eye + Download, + Loader2, } from 'lucide-react'; +import JSZip from 'jszip'; interface ProjectInfoDialogProps { project: Project; @@ -38,75 +23,10 @@ interface ProjectInfoDialogProps { onOpenChange: (open: boolean) => void; } -interface ProjectMetadata { - description?: string; - version?: string; - nostrRepoAddress?: string; - fileCount?: number; -} - export function ProjectInfoDialog({ project, open, onOpenChange }: ProjectInfoDialogProps) { - const [metadata, setMetadata] = useState({}); - const [isLoading, setIsLoading] = useState(false); - const projectsManager = useProjectsManager(); - const gitStatus = useGitStatus(project.id); - - useEffect(() => { - if (!open) return; - - const loadProjectMetadata = async () => { - setIsLoading(true); - try { - const meta: ProjectMetadata = {}; - - // Try to read package.json - try { - const packageJsonContent = await projectsManager.readFile(project.id, 'package.json'); - const packageJson = JSON.parse(packageJsonContent); - meta.description = packageJson.description; - meta.version = packageJson.version; - } catch { - // package.json doesn't exist or is invalid - } - - // Get Nostr repo address - try { - const repoAddress = await projectsManager.getNostrRepoAddress(project.id); - if (repoAddress) { - meta.nostrRepoAddress = repoAddress; - } - } catch { - // No Nostr repo configured - } - - // Calculate file count and size (simplified) - try { - const files = await projectsManager.listFiles(project.id); - meta.fileCount = files.length; - } catch { - // Can't read directory - } - - setMetadata(meta); - } catch (error) { - console.error('Failed to load project metadata:', error); - } finally { - setIsLoading(false); - } - }; - - loadProjectMetadata(); - }, [open, project.id, projectsManager]); - - const formatDate = (date: Date) => { - return new Intl.DateTimeFormat('en-US', { - year: 'numeric', - month: 'long', - day: 'numeric', - hour: '2-digit', - minute: '2-digit', - }).format(date); - }; + const [isExporting, setIsExporting] = useState(false); + const { toast } = useToast(); + const { fs } = useFS(); const formatDistanceToNow = (date: Date) => { const now = new Date(); @@ -120,239 +40,106 @@ export function ProjectInfoDialog({ project, open, onOpenChange }: ProjectInfoDi return `${Math.floor(diffInSeconds / 31536000)} years ago`; }; + const handleExportProject = async () => { + setIsExporting(true); + try { + const zip = new JSZip(); + const projectPath = `/projects/${project.id}`; + + // Recursive function to add files and directories to zip from a specific project + const addFolderToZip = async (dirPath: string, zipFolder: JSZip) => { + try { + const entries = await fs.readdir(dirPath, { withFileTypes: true }); + + for (const entry of entries) { + const fullPath = `${dirPath}/${entry.name}`; + + if (entry.isDirectory()) { + // Create folder in zip and recursively add its contents + const folder = zipFolder.folder(entry.name); + if (folder) { + await addFolderToZip(fullPath, folder); + } + } else if (entry.isFile()) { + // Add file to zip + try { + const fileContent = await fs.readFile(fullPath); + zipFolder.file(entry.name, fileContent); + } catch (error) { + console.warn(`Failed to read file ${fullPath}:`, error); + } + } + } + } catch (error) { + console.warn(`Failed to read directory ${dirPath}:`, error); + } + }; + + // Start from the project directory + await addFolderToZip(projectPath, zip); + + // Generate zip file + const content = await zip.generateAsync({ type: 'blob' }); + + // Create download link + const url = URL.createObjectURL(content); + const link = document.createElement('a'); + link.href = url; + link.download = `${project.id}.zip`; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + URL.revokeObjectURL(url); + + toast({ + title: "Project exported successfully", + description: `"${project.name}" has been downloaded as a zip file.`, + }); + } catch (error) { + console.error('Failed to export project:', error); + toast({ + title: "Failed to export project", + description: error instanceof Error ? error.message : "An unexpected error occurred", + variant: "destructive", + }); + } finally { + setIsExporting(false); + } + }; + return ( - + {project.name} - - Project information and metadata - - {isLoading ? ( -
-
-
-
-
+
+ {/* Last Modified */} +
+ + Last Modified: + {formatDistanceToNow(project.lastModified)}
- ) : ( -
- {/* Basic Information */} -
-

- Basic Information -

-
-
- - Project ID: - {project.id} -
-
- - Last Modified: - {formatDistanceToNow(project.lastModified)} -
- {metadata.version && ( -
- - Version: - {metadata.version} -
- )} - {metadata.fileCount !== undefined && ( -
- - Files: - {metadata.fileCount} -
- )} -
-
- Created: - {formatDate(project.lastModified)} -
- {metadata.description && ( -
- Description: -

{metadata.description}

-
- )} -
- {/* Nostr Information */} - {metadata.nostrRepoAddress && ( - <> - -
-

- - Nostr Repository -

-
- Repository Address: - - {metadata.nostrRepoAddress} - -
-
- + {/* Export Project Button */} +
- )} + {isExporting ? 'Exporting...' : 'Export Project'} + +
);