project-ux: archive/rename/Open-in-Gitea sidebar context menu, archived projects landing, create-project bootstrap with Gitea remote
Server:
- projects.status + projects.gitea_remote (additive) with CHECK ('open','archived')
- GET /api/projects?status=archived; PATCH /api/projects/:id (rename);
POST /api/projects/:id/archive | unarchive; POST /api/projects/create
- POST /api/projects ON CONFLICT (path) DO UPDATE SET status='open': re-add
of archived path restores existing row (preserves id + FKs); already-open
path returns 409. Detected-repos picker now excludes only status='open'.
- New gitea.ts (createGiteaRepo + GiteaRepoExistsError) and
project_bootstrap.ts (sanitize name, mkdir under PROJECT_ROOT_WHITELIST,
git init -b main + first commit with -c user.name/email per-command, optional
Gitea repo create + remote add + push; all via execFile, no shell).
- 3 new user-stream frames: project_archived, project_unarchived, project_updated.
- sidebar.ts now selects path + gitea_remote and filters status='open'.
- Gitea env added to config.ts (GITEA_BASE_URL, GITEA_USER, GITEA_TOKEN,
GITEA_SSH_HOST).
- docker-compose.yml /opt mount flipped to rw so create-project can mkdir.
- auto_name.ts gate relaxed from `!== 1` to `< 1` (fires on every turn while
chat name is empty, not only the first).
Web:
- ProjectSidebar: project rows use proper Radix ContextMenu; items Rename /
Archive / Open in Gitea. Inline rename, archive confirm dialog.
Removed obsolete handleRemove + DropdownMenu hack.
- Home: Add-existing + Create-new buttons; collapsible Archived Projects
section with Restore.
- New CreateProjectModal: name + live folder preview, commit msg, Private/
Public radio, create-Gitea-remote checkbox, toast on success/warnings.
- New projectUrls.ts giteaUrlFor() — uses gitea_remote when present,
falls back to convention URL.
- 3 new event types in sessionEvents.ts with idempotent useSidebar handlers.
- SidebarProject extended with path + gitea_remote so Open-in-Gitea can
resolve without a separate fetch.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
171
apps/web/src/components/CreateProjectModal.tsx
Normal file
171
apps/web/src/components/CreateProjectModal.tsx
Normal file
@@ -0,0 +1,171 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { toast } from 'sonner';
|
||||
import { api } from '@/api/client';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
|
||||
interface Props {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
}
|
||||
|
||||
function previewFolderName(raw: string): string {
|
||||
return raw
|
||||
.toLowerCase()
|
||||
.trim()
|
||||
.replace(/\s+/g, '-')
|
||||
.replace(/[^a-z0-9-]/g, '')
|
||||
.replace(/-+/g, '-')
|
||||
.replace(/^-+|-+$/g, '')
|
||||
.slice(0, 64);
|
||||
}
|
||||
|
||||
export function CreateProjectModal({ open, onOpenChange }: Props) {
|
||||
const navigate = useNavigate();
|
||||
const [name, setName] = useState('');
|
||||
const [commitMessage, setCommitMessage] = useState('Initial commit');
|
||||
const [visibility, setVisibility] = useState<'private' | 'public'>('private');
|
||||
const [createRemote, setCreateRemote] = useState(true);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
setName('');
|
||||
setCommitMessage('Initial commit');
|
||||
setVisibility('private');
|
||||
setCreateRemote(true);
|
||||
setBusy(false);
|
||||
setError(null);
|
||||
}, [open]);
|
||||
|
||||
const folderPreview = previewFolderName(name);
|
||||
|
||||
async function submit() {
|
||||
if (!folderPreview) {
|
||||
setError('Project name must contain at least one letter or digit.');
|
||||
return;
|
||||
}
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
const result = await api.projects.create({
|
||||
name: name.trim(),
|
||||
commit_message: commitMessage.trim() || 'Initial commit',
|
||||
visibility,
|
||||
create_gitea_remote: createRemote,
|
||||
});
|
||||
const warnings = result.bootstrap.warnings;
|
||||
if (warnings.length > 0) {
|
||||
toast.warning(`Project created with warnings: ${warnings.join('; ')}`);
|
||||
} else {
|
||||
toast.success(`Project "${result.project.name}" created`);
|
||||
}
|
||||
onOpenChange(false);
|
||||
navigate(`/project/${result.project.id}`);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'failed to create project');
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Create New Project</DialogTitle>
|
||||
<DialogDescription>
|
||||
Creates a folder under /opt with a git repo, .gitignore, and optionally a Gitea remote.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="space-y-3">
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="proj-name">Project name</Label>
|
||||
<Input
|
||||
id="proj-name"
|
||||
placeholder="My new project"
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
disabled={busy}
|
||||
autoFocus
|
||||
/>
|
||||
{name && (
|
||||
<div className="text-xs text-muted-foreground font-mono">
|
||||
Folder: /opt/{folderPreview || <span className="text-destructive">(empty after sanitization)</span>}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="commit-msg">Initial commit message</Label>
|
||||
<Input
|
||||
id="commit-msg"
|
||||
value={commitMessage}
|
||||
onChange={(e) => setCommitMessage(e.target.value)}
|
||||
disabled={busy}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-1.5">
|
||||
<Label>Visibility</Label>
|
||||
<div className="flex gap-4 text-sm">
|
||||
<label className="flex items-center gap-1.5">
|
||||
<input
|
||||
type="radio"
|
||||
checked={visibility === 'private'}
|
||||
onChange={() => setVisibility('private')}
|
||||
disabled={busy}
|
||||
/>
|
||||
Private
|
||||
</label>
|
||||
<label className="flex items-center gap-1.5">
|
||||
<input
|
||||
type="radio"
|
||||
checked={visibility === 'public'}
|
||||
onChange={() => setVisibility('public')}
|
||||
disabled={busy}
|
||||
/>
|
||||
Public
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label className="flex items-center gap-2 text-sm">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={createRemote}
|
||||
onChange={(e) => setCreateRemote(e.target.checked)}
|
||||
disabled={busy}
|
||||
/>
|
||||
Create Gitea remote and push
|
||||
</label>
|
||||
|
||||
{error && (
|
||||
<div className="text-sm text-destructive">{error}</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={() => onOpenChange(false)} disabled={busy}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button onClick={() => void submit()} disabled={busy || !folderPreview}>
|
||||
{busy ? 'Creating…' : 'Create'}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -1,14 +1,8 @@
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { NavLink, useLocation, useNavigate } from 'react-router-dom';
|
||||
import { ChevronRight, Folder, MessageSquare, Plus } from 'lucide-react';
|
||||
import { ChevronRight, ExternalLink, Folder, MessageSquare, Plus } from 'lucide-react';
|
||||
import { toast } from 'sonner';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import {
|
||||
ContextMenu,
|
||||
ContextMenuContent,
|
||||
@@ -28,6 +22,7 @@ import { api } from '@/api/client';
|
||||
import { sessionEvents } from '@/hooks/sessionEvents';
|
||||
import { useSidebar } from '@/hooks/useSidebar';
|
||||
import type { SidebarProject } from '@/api/types';
|
||||
import { giteaUrlFor } from '@/lib/projectUrls';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
const EXPANDED_KEY = 'boocode.sidebar.expanded';
|
||||
@@ -108,6 +103,9 @@ export function ProjectSidebar() {
|
||||
const [renamingSession, setRenamingSession] = useState<string | null>(null);
|
||||
const [renameValue, setRenameValue] = useState('');
|
||||
const [deleteConfirm, setDeleteConfirm] = useState<{ id: string; name: string } | null>(null);
|
||||
const [renamingProject, setRenamingProject] = useState<string | null>(null);
|
||||
const [renameProjectValue, setRenameProjectValue] = useState('');
|
||||
const [archiveProjectConfirm, setArchiveProjectConfirm] = useState<{ id: string; name: string } | null>(null);
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const lastToastedError = useRef<string | null>(null);
|
||||
@@ -140,13 +138,25 @@ export function ProjectSidebar() {
|
||||
});
|
||||
}
|
||||
|
||||
async function handleRemove(id: string) {
|
||||
async function handleArchiveProject(id: string) {
|
||||
try {
|
||||
await api.projects.remove(id);
|
||||
// Server publishes project_deleted via WS; useUserEvents delivers it.
|
||||
navigate('/');
|
||||
await api.projects.archive(id);
|
||||
// Server publishes project_archived via WS.
|
||||
if (activeProject === id) navigate('/');
|
||||
} catch (err) {
|
||||
toast.error(err instanceof Error ? err.message : 'failed to remove project');
|
||||
toast.error(err instanceof Error ? err.message : 'failed to archive project');
|
||||
}
|
||||
}
|
||||
|
||||
async function handleRenameProject(id: string) {
|
||||
const trimmed = renameProjectValue.trim();
|
||||
setRenamingProject(null);
|
||||
if (!trimmed) return;
|
||||
try {
|
||||
await api.projects.update(id, { name: trimmed });
|
||||
// Server publishes project_updated via WS.
|
||||
} catch (err) {
|
||||
toast.error(err instanceof Error ? err.message : 'failed to rename project');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,52 +234,73 @@ export function ProjectSidebar() {
|
||||
const visible = p.recent_sessions.slice(0, MAX_VISIBLE_SESSIONS);
|
||||
return (
|
||||
<div key={p.id} className="px-2">
|
||||
<DropdownMenu>
|
||||
<div
|
||||
className={`group flex items-center gap-1 rounded-md px-2 py-1.5 text-sm ${rowCls(isActiveProject)}`}
|
||||
onContextMenu={(e) => {
|
||||
e.preventDefault();
|
||||
(
|
||||
e.currentTarget.parentElement?.querySelector(
|
||||
'[data-ctxtrigger]'
|
||||
) as HTMLElement | null
|
||||
)?.click();
|
||||
}}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={isExpanded ? 'Collapse' : 'Expand'}
|
||||
aria-expanded={isExpanded}
|
||||
disabled={isActiveProject}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
if (isActiveProject) return;
|
||||
toggle(p.id);
|
||||
}}
|
||||
className={cn(
|
||||
'flex items-center justify-center size-4 shrink-0 opacity-70 hover:opacity-100',
|
||||
isActiveProject &&
|
||||
'opacity-50 cursor-not-allowed hover:opacity-50'
|
||||
)}
|
||||
<ContextMenu>
|
||||
<ContextMenuTrigger asChild>
|
||||
<div
|
||||
className={`group flex items-center gap-1 rounded-md px-2 py-1.5 text-sm ${rowCls(isActiveProject)}`}
|
||||
>
|
||||
<ChevronRight
|
||||
className={`size-3.5 transition-transform ${isExpanded ? 'rotate-90' : ''}`}
|
||||
/>
|
||||
</button>
|
||||
<NavLink to={`/project/${p.id}`} className="flex items-center gap-2 min-w-0 flex-1">
|
||||
<Folder className="size-3.5 shrink-0 opacity-70" />
|
||||
<span className="truncate" title={p.name}>{p.name}</span>
|
||||
</NavLink>
|
||||
</div>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button data-ctxtrigger className="hidden" aria-hidden />
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="start">
|
||||
<DropdownMenuItem variant="destructive" onClick={() => void handleRemove(p.id)}>
|
||||
Remove from sidebar
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={isExpanded ? 'Collapse' : 'Expand'}
|
||||
aria-expanded={isExpanded}
|
||||
disabled={isActiveProject}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
if (isActiveProject) return;
|
||||
toggle(p.id);
|
||||
}}
|
||||
className={cn(
|
||||
'flex items-center justify-center size-4 shrink-0 opacity-70 hover:opacity-100',
|
||||
isActiveProject &&
|
||||
'opacity-50 cursor-not-allowed hover:opacity-50'
|
||||
)}
|
||||
>
|
||||
<ChevronRight
|
||||
className={`size-3.5 transition-transform ${isExpanded ? 'rotate-90' : ''}`}
|
||||
/>
|
||||
</button>
|
||||
{renamingProject === p.id ? (
|
||||
<div className="flex items-center gap-2 min-w-0 flex-1">
|
||||
<Folder className="size-3.5 shrink-0 opacity-70" />
|
||||
<input
|
||||
autoFocus
|
||||
value={renameProjectValue}
|
||||
onChange={(e) => setRenameProjectValue(e.target.value)}
|
||||
onBlur={() => void handleRenameProject(p.id)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') void handleRenameProject(p.id);
|
||||
if (e.key === 'Escape') setRenamingProject(null);
|
||||
}}
|
||||
className="bg-transparent border-b border-border text-sm outline-none flex-1 min-w-0"
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<NavLink to={`/project/${p.id}`} className="flex items-center gap-2 min-w-0 flex-1">
|
||||
<Folder className="size-3.5 shrink-0 opacity-70" />
|
||||
<span className="truncate" title={p.name}>{p.name}</span>
|
||||
</NavLink>
|
||||
)}
|
||||
</div>
|
||||
</ContextMenuTrigger>
|
||||
<ContextMenuContent>
|
||||
<ContextMenuItem onSelect={() => {
|
||||
setRenamingProject(p.id);
|
||||
setRenameProjectValue(p.name);
|
||||
}}>
|
||||
Rename
|
||||
</ContextMenuItem>
|
||||
<ContextMenuItem onSelect={() => setArchiveProjectConfirm({ id: p.id, name: p.name })}>
|
||||
Archive
|
||||
</ContextMenuItem>
|
||||
<ContextMenuSeparator />
|
||||
<ContextMenuItem onSelect={() => {
|
||||
const url = giteaUrlFor({ path: p.path, gitea_remote: p.gitea_remote });
|
||||
window.open(url, '_blank', 'noopener');
|
||||
}}>
|
||||
<ExternalLink size={12} /> Open in Gitea
|
||||
</ContextMenuItem>
|
||||
</ContextMenuContent>
|
||||
</ContextMenu>
|
||||
|
||||
{isExpanded && (
|
||||
<div className="ml-5 mt-0.5 space-y-0.5">
|
||||
@@ -341,6 +372,30 @@ export function ProjectSidebar() {
|
||||
|
||||
<AddProjectModal open={addOpen} onOpenChange={setAddOpen} onAdded={() => {}} />
|
||||
|
||||
<Dialog open={archiveProjectConfirm !== null} onOpenChange={(open) => { if (!open) setArchiveProjectConfirm(null); }}>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Archive project?</DialogTitle>
|
||||
<DialogDescription>
|
||||
Removes {archiveProjectConfirm ? `"${archiveProjectConfirm.name}"` : 'this project'} from the sidebar. Files on disk are untouched. You can restore it later from the Archived Projects view.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="flex gap-2 justify-end pt-2">
|
||||
<Button variant="outline" onClick={() => setArchiveProjectConfirm(null)}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => {
|
||||
if (archiveProjectConfirm) void handleArchiveProject(archiveProjectConfirm.id);
|
||||
setArchiveProjectConfirm(null);
|
||||
}}
|
||||
>
|
||||
Archive
|
||||
</Button>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
<Dialog open={deleteConfirm !== null} onOpenChange={(open) => { if (!open) setDeleteConfirm(null); }}>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
|
||||
Reference in New Issue
Block a user