From 2e0d97a8bfa0101b491dd46521c9f9714d2fe9cf Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 30 Aug 2025 18:18:54 -0500 Subject: [PATCH] Reorganize menus somewhat --- src/components/ActionsMenu.tsx | 235 ++++++++++++++++++++++++---- src/components/ProjectSidebar.tsx | 251 +++--------------------------- src/components/StarButton.tsx | 65 ++++++++ src/pages/ProjectView.tsx | 44 ++++-- 4 files changed, 328 insertions(+), 267 deletions(-) create mode 100644 src/components/StarButton.tsx diff --git a/src/components/ActionsMenu.tsx b/src/components/ActionsMenu.tsx index cd432975..ff65fa57 100644 --- a/src/components/ActionsMenu.tsx +++ b/src/components/ActionsMenu.tsx @@ -7,20 +7,38 @@ import { DropdownMenuSeparator, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; -import { - MoreHorizontal, - MessageSquarePlus, - Play, - CloudUpload, - Settings, +import { + AlertDialog, + AlertDialogAction, + AlertDialogCancel, + AlertDialogContent, + AlertDialogDescription, + AlertDialogFooter, + AlertDialogHeader, + AlertDialogTitle, + AlertDialogTrigger, +} from '@/components/ui/alert-dialog'; +import { + MoreHorizontal, + MessageSquarePlus, + Play, + CloudUpload, Loader2, - GitBranch + GitBranch, + Download, + Trash2, } from 'lucide-react'; import { GitHistoryDialog } from '@/components/ai/GitHistoryDialog'; -import { AISettingsDialog } from '@/components/ai/AISettingsDialog'; +import { useNavigate } from 'react-router-dom'; +import { useProjectsManager } from '@/hooks/useProjectsManager'; +import { useToast } from '@/hooks/useToast'; +import { useFS } from '@/hooks/useFS'; +import JSZip from 'jszip'; +import git from 'isomorphic-git'; interface ActionsMenuProps { projectId: string; + projectName: string; onNewChat: () => void; onBuild: () => void; onDeploy: () => void; @@ -29,10 +47,12 @@ interface ActionsMenuProps { isDeployLoading?: boolean; disabled?: boolean; onFirstInteraction?: () => void; + onProjectDeleted?: () => void; } export function ActionsMenu({ projectId, + projectName, onNewChat, onBuild, onDeploy, @@ -40,12 +60,132 @@ export function ActionsMenu({ isBuildLoading = false, isDeployLoading = false, disabled = false, - onFirstInteraction + onFirstInteraction, + onProjectDeleted }: ActionsMenuProps) { const [gitHistoryOpen, setGitHistoryOpen] = useState(false); - const [aiSettingsOpen, setAISettingsOpen] = useState(false); + const [isDeleting, setIsDeleting] = useState(false); + const [isExporting, setIsExporting] = useState(false); - const isAnyLoading = isLoading || isBuildLoading || isDeployLoading; + const navigate = useNavigate(); + const projectsManager = useProjectsManager(); + const { toast } = useToast(); + const { fs } = useFS(); + + const isAnyLoading = isLoading || isBuildLoading || isDeployLoading || isDeleting || isExporting; + + 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); + } + }; + + 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({ + fs, + 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 ( <> @@ -70,7 +210,7 @@ export function ActionsMenu({ New Chat - + setGitHistoryOpen(true)} disabled={isAnyLoading} @@ -79,9 +219,20 @@ export function ActionsMenu({ Git History - - - + + + {isExporting ? ( + + ) : ( + + )} + {isExporting ? 'Exporting...' : 'Export Project'} + + { if (onFirstInteraction) onFirstInteraction(); @@ -97,7 +248,7 @@ export function ActionsMenu({ )} {isBuildLoading ? 'Building...' : 'Build'} - + { if (onFirstInteraction) onFirstInteraction(); @@ -113,16 +264,45 @@ export function ActionsMenu({ )} {isDeployLoading ? 'Deploying...' : 'Deploy'} - + - - setAISettingsOpen(true)} - className="gap-2" - > - - AI Settings - + + + + 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' + )} + + + + @@ -132,11 +312,6 @@ export function ActionsMenu({ open={gitHistoryOpen} onOpenChange={setGitHistoryOpen} /> - - ); } \ No newline at end of file diff --git a/src/components/ProjectSidebar.tsx b/src/components/ProjectSidebar.tsx index b5a527d4..08b68c5b 100644 --- a/src/components/ProjectSidebar.tsx +++ b/src/components/ProjectSidebar.tsx @@ -1,13 +1,12 @@ import React, { useState } from 'react'; import { useNavigate } from 'react-router-dom'; -import { Plus, Loader2, Info, MoreVertical, Trash2, Eye, Star, Bug, Folder, Download, GitBranch } from 'lucide-react'; +import { Plus, Folder, Download, GitBranch, MoreVertical, Settings } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Skeleton } from '@/components/ui/skeleton'; - - import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu'; -import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from '@/components/ui/alert-dialog'; import { LoginArea } from '@/components/auth/LoginArea'; +import { StarButton } from '@/components/StarButton'; +import { AISettingsDialog } from '@/components/ai/AISettingsDialog'; import { useProjectsManager } from '@/hooks/useProjectsManager'; import { useLocalStorage } from '@/hooks/useLocalStorage'; import { useToast } from '@/hooks/useToast'; @@ -15,7 +14,6 @@ import { useFS } from '@/hooks/useFS'; import type { Project } from '@/lib/ProjectsManager'; import { cn } from '@/lib/utils'; import JSZip from 'jszip'; -import git from 'isomorphic-git'; interface ProjectSidebarProps { selectedProject: Project | null; @@ -30,9 +28,9 @@ export function ProjectSidebar({ }: ProjectSidebarProps) { const [projects, setProjects] = useState([]); const [isLoading, setIsLoading] = useState(true); - const [isDeleting, setIsDeleting] = useState(false); const [isExporting, setIsExporting] = useState(false); - const [favorites, setFavorites] = useLocalStorage('project-favorites', []); + const [aiSettingsOpen, setAISettingsOpen] = useState(false); + const [favorites] = useLocalStorage('project-favorites', []); const projectsManager = useProjectsManager(); const navigate = useNavigate(); const { toast } = useToast(); @@ -60,49 +58,6 @@ export function ProjectSidebar({ navigate('/'); }; - const handleDeleteProject = async (project: Project) => { - setIsDeleting(true); - try { - await projectsManager.deleteProject(project.id); - - // Remove from local state - setProjects(prev => prev.filter(p => p.id !== project.id)); - - // If the deleted project was selected, deselect it - if (selectedProject?.id === project.id) { - onSelectProject(null); - navigate('/'); - } - - toast({ - title: "Project deleted", - description: `"${project.name}" has been permanently deleted.`, - }); - } catch (error) { - toast({ - title: "Failed to delete project", - description: error instanceof Error ? error.message : "An unexpected error occurred", - variant: "destructive", - }); - } finally { - setIsDeleting(false); - } - }; - - const handleToggleFavorite = (project: Project) => { - const wasFavorite = favorites.includes(project.id); - const newFavorites = wasFavorite - ? favorites.filter(id => id !== project.id) - : [...favorites, project.id]; - - setFavorites(newFavorites); - - toast({ - title: wasFavorite ? "Project Unfavorited" : "Project Favorited", - description: `"${project.name}" has been ${wasFavorite ? 'removed from' : 'added to'} your favorites.`, - }); - }; - const isFavorite = (projectId: string) => favorites.includes(projectId); const exportFilesAsZip = async (projectName: string) => { @@ -181,93 +136,6 @@ export function ProjectSidebar({ } }; - const handleExportProject = async (project: Project) => { - 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 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 = `${project.name}.zip`; - try { - // Get the current commit hash - const commits = await git.log({ - fs, - dir: projectPath, - depth: 1, - }); - - if (commits.length > 0) { - const commitHash = commits[0].oid.substring(0, 7); // Truncate to 7 characters - filename = `${project.name}-${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: `"${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); - } - }; - // Sort projects: favorites first, then by lastModified (newest first) const sortedProjects = projects.sort((a, b) => { const aIsFavorite = isFavorite(a.id); @@ -315,17 +183,13 @@ export function ProjectSidebar({ {isExporting ? 'Exporting...' : 'Export Files'} - - - - About MKStack - - - - - - Report an Issue - + + setAISettingsOpen(true)} + className="flex items-center gap-2 w-full" + > + + AI Settings @@ -388,88 +252,17 @@ export function ProjectSidebar({

{project.name}

-
- {isFavorite(project.id) && ( - - )} -
- {/* Dropdown Menu */} + {/* Star Button */}
- - - - - - handleToggleFavorite(project)} - > - - {isFavorite(project.id) ? "Unfavorite" : "Favorite"} - - navigate(`/project/${project.id}`)} - > - - Open Project - - handleExportProject(project)} - disabled={isExporting} - > - - {isExporting ? 'Exporting...' : 'Export Project'} - - - - e.preventDefault()} - > - - Delete Project - - - - - 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 - handleDeleteProject(project)} - disabled={isDeleting} - className="bg-destructive text-destructive-foreground hover:bg-destructive/90" - > - {isDeleting ? ( - <> - - Deleting... - - ) : ( - 'Delete Project' - )} - - - - - - +
@@ -485,6 +278,12 @@ export function ProjectSidebar({
+ + {/* AI Settings Dialog */} + ); } \ No newline at end of file diff --git a/src/components/StarButton.tsx b/src/components/StarButton.tsx new file mode 100644 index 00000000..19c76beb --- /dev/null +++ b/src/components/StarButton.tsx @@ -0,0 +1,65 @@ +import { Button } from '@/components/ui/button'; +import { Star } from 'lucide-react'; +import { useLocalStorage } from '@/hooks/useLocalStorage'; +import { useToast } from '@/hooks/useToast'; +import { cn } from '@/lib/utils'; + +interface StarButtonProps { + projectId: string; + projectName: string; + className?: string; + size?: 'sm' | 'default' | 'lg'; + variant?: 'ghost' | 'outline' | 'default'; + showToast?: boolean; +} + +export function StarButton({ + projectId, + projectName, + className, + size = 'sm', + variant = 'ghost', + showToast = true +}: StarButtonProps) { + const [favorites, setFavorites] = useLocalStorage('project-favorites', []); + const { toast } = useToast(); + + const isFavorite = favorites.includes(projectId); + + const handleToggleFavorite = (e: React.MouseEvent) => { + e.stopPropagation(); // Prevent triggering parent click events + + const newFavorites = isFavorite + ? favorites.filter(id => id !== projectId) + : [...favorites, projectId]; + + setFavorites(newFavorites); + + if (showToast) { + toast({ + title: isFavorite ? "Project Unfavorited" : "Project Favorited", + description: `"${projectName}" has been ${isFavorite ? 'removed from' : 'added to'} your favorites.`, + }); + } + }; + + return ( + + ); +} \ No newline at end of file diff --git a/src/pages/ProjectView.tsx b/src/pages/ProjectView.tsx index f584769d..20ac0bf4 100644 --- a/src/pages/ProjectView.tsx +++ b/src/pages/ProjectView.tsx @@ -17,6 +17,7 @@ import { useFS } from '@/hooks/useFS'; import { useJSRuntime } from '@/hooks/useJSRuntime'; import { useKeepAlive } from '@/hooks/useKeepAlive'; import { GitStatusIndicator } from '@/components/GitStatusIndicator'; +import { StarButton } from '@/components/StarButton'; import { generateSecretKey, getPublicKey, nip19 } from 'nostr-tools'; import { bytesToHex } from 'nostr-tools/utils'; import { buildProject } from "@/lib/build"; @@ -188,6 +189,11 @@ BASE_DOMAIN=nostrdeploy.com`); // when isAILoading becomes true after user interaction }; + const handleProjectDeleted = () => { + setProject(null); + navigate('/'); + }; + if (isLoading) { return (
@@ -233,16 +239,25 @@ BASE_DOMAIN=nostrdeploy.com`);
- +
+ + +
{/* Mobile Sidebar Overlay */} @@ -395,10 +410,16 @@ BASE_DOMAIN=nostrdeploy.com`); - {/* Right side - Actions Menu */} + {/* Right side - Star and Actions Menu */}
+