Reorganize menus somewhat

This commit is contained in:
Alex Gleason committed 2025-08-30 18:22:50 -05:00
1 parent e7f56aaa78
commit 2e0d97a8bf
4 files changed
+328 -267

No files matched your search

+205 -30
View File
@@ -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({
<MessageSquarePlus className="h-4 w-4" />
New Chat
</DropdownMenuItem>
<DropdownMenuItem
onClick={() => setGitHistoryOpen(true)}
disabled={isAnyLoading}
@@ -79,9 +219,20 @@ export function ActionsMenu({
<GitBranch className="h-4 w-4" />
Git History
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem
onClick={handleExportProject}
disabled={isAnyLoading}
className="gap-2"
>
{isExporting ? (
<Loader2 className="h-4 w-4 animate-spin" />
) : (
<Download className="h-4 w-4" />
)}
{isExporting ? 'Exporting...' : 'Export Project'}
</DropdownMenuItem>
<DropdownMenuItem
onClick={() => {
if (onFirstInteraction) onFirstInteraction();
@@ -97,7 +248,7 @@ export function ActionsMenu({
)}
{isBuildLoading ? 'Building...' : 'Build'}
</DropdownMenuItem>
<DropdownMenuItem
onClick={() => {
if (onFirstInteraction) onFirstInteraction();
@@ -113,16 +264,45 @@ export function ActionsMenu({
)}
{isDeployLoading ? 'Deploying...' : 'Deploy'}
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem
onClick={() => setAISettingsOpen(true)}
className="gap-2"
>
<Settings className="h-4 w-4" />
AI Settings
</DropdownMenuItem>
<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>
@@ -132,11 +312,6 @@ export function ActionsMenu({
open={gitHistoryOpen}
onOpenChange={setGitHistoryOpen}
/>
<AISettingsDialog
open={aiSettingsOpen}
onOpenChange={setAISettingsOpen}
/>
</>
);
}
+25 -226
View File
@@ -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<Project[]>([]);
const [isLoading, setIsLoading] = useState(true);
const [isDeleting, setIsDeleting] = useState(false);
const [isExporting, setIsExporting] = useState(false);
const [favorites, setFavorites] = useLocalStorage<string[]>('project-favorites', []);
const [aiSettingsOpen, setAISettingsOpen] = useState(false);
const [favorites] = useLocalStorage<string[]>('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({
<Download className="h-4 w-4" />
{isExporting ? 'Exporting...' : 'Export Files'}
</DropdownMenuItem>
<DropdownMenuItem asChild>
<a href="https://soapbox.pub/mkstack" target="_blank" rel="noopener noreferrer" className="flex items-center gap-2 w-full">
<Info className="h-4 w-4" />
About MKStack
</a>
</DropdownMenuItem>
<DropdownMenuItem asChild>
<a href="https://github.com/soapbox-pub/mkstack/issues" target="_blank" rel="noopener noreferrer" className="flex items-center gap-2 w-full">
<Bug className="h-4 w-4" />
Report an Issue
</a>
<DropdownMenuItem
onClick={() => setAISettingsOpen(true)}
className="flex items-center gap-2 w-full"
>
<Settings className="h-4 w-4" />
AI Settings
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
@@ -388,88 +252,17 @@ export function ProjectSidebar({
<h3 className="font-medium text-sm truncate">
{project.name}
</h3>
<div className="flex items-center gap-1 ml-auto">
{isFavorite(project.id) && (
<Star className="h-3 w-3 text-yellow-500 fill-current" />
)}
</div>
</div>
</div>
{/* Dropdown Menu */}
{/* Star Button */}
<div className="flex-shrink-0 -mt-1 -mr-1 relative">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="ghost"
size="sm"
className="h-6 w-6 p-0 hover:bg-primary/20"
onClick={(e) => e.stopPropagation()}
>
<MoreVertical className="h-3 w-3" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-48">
<DropdownMenuItem
onClick={() => handleToggleFavorite(project)}
>
<Star className={cn(
"h-4 w-4 mr-2",
isFavorite(project.id) ? "text-yellow-500 fill-current" : "text-muted-foreground"
)} />
{isFavorite(project.id) ? "Unfavorite" : "Favorite"}
</DropdownMenuItem>
<DropdownMenuItem
onClick={() => navigate(`/project/${project.id}`)}
>
<Eye className="h-4 w-4 mr-2" />
Open Project
</DropdownMenuItem>
<DropdownMenuItem
onClick={() => handleExportProject(project)}
disabled={isExporting}
>
<Download className="h-4 w-4 mr-2" />
{isExporting ? 'Exporting...' : 'Export Project'}
</DropdownMenuItem>
<AlertDialog>
<AlertDialogTrigger asChild>
<DropdownMenuItem
className="text-destructive focus:text-destructive cursor-pointer"
onSelect={(e) => e.preventDefault()}
>
<Trash2 className="h-4 w-4 mr-2" />
Delete Project
</DropdownMenuItem>
</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(project)}
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>
<StarButton
projectId={project.id}
projectName={project.name}
showToast={false}
className="h-6 w-6 hover:bg-primary/20"
/>
</div>
</div>
</div>
@@ -485,6 +278,12 @@ export function ProjectSidebar({
<div className="p-4 border-t border-sidebar-border bg-gradient-to-r from-primary/5 to-accent/5 mt-auto">
<LoginArea className="w-full" />
</div>
{/* AI Settings Dialog */}
<AISettingsDialog
open={aiSettingsOpen}
onOpenChange={setAISettingsOpen}
/>
</div>
);
}
+65
View File
@@ -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<string[]>('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 (
<Button
variant={variant}
size={size}
onClick={handleToggleFavorite}
className={cn(
"h-8 w-8 p-0",
className
)}
aria-label={isFavorite ? "Remove from favorites" : "Add to favorites"}
>
<Star
className={cn(
"h-4 w-4",
isFavorite ? "text-yellow-500 fill-current" : "text-muted-foreground hover:text-yellow-500"
)}
/>
</Button>
);
}
+33 -11
View File
@@ -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 (
<div className="min-h-screen bg-background flex items-center justify-center">
@@ -233,16 +239,25 @@ BASE_DOMAIN=nostrdeploy.com`);
</div>
</div>
<ActionsMenu
projectId={project.id}
onNewChat={handleNewChat}
onBuild={runBuild}
onDeploy={runDeploy}
isLoading={isAILoading}
isBuildLoading={isBuildLoading}
isDeployLoading={isDeployLoading}
onFirstInteraction={handleFirstInteraction}
/>
<div className="flex items-center gap-2">
<StarButton
projectId={project.id}
projectName={project.name}
className="h-8 w-8"
/>
<ActionsMenu
projectId={project.id}
projectName={project.name}
onNewChat={handleNewChat}
onBuild={runBuild}
onDeploy={runDeploy}
isLoading={isAILoading}
isBuildLoading={isBuildLoading}
isDeployLoading={isDeployLoading}
onFirstInteraction={handleFirstInteraction}
onProjectDeleted={handleProjectDeleted}
/>
</div>
</header>
{/* Mobile Sidebar Overlay */}
@@ -395,10 +410,16 @@ BASE_DOMAIN=nostrdeploy.com`);
</div>
</div>
{/* Right side - Actions Menu */}
{/* Right side - Star and Actions Menu */}
<div className="flex items-center gap-2">
<StarButton
projectId={project.id}
projectName={project.name}
className="h-8 w-8"
/>
<ActionsMenu
projectId={project.id}
projectName={project.name}
onNewChat={handleNewChat}
onBuild={runBuild}
onDeploy={runDeploy}
@@ -406,6 +427,7 @@ BASE_DOMAIN=nostrdeploy.com`);
isBuildLoading={isBuildLoading}
isDeployLoading={isDeployLoading}
onFirstInteraction={handleFirstInteraction}
onProjectDeleted={handleProjectDeleted}
/>
</div>
</div>