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:
@@ -1,35 +1,135 @@
|
||||
import { useState } from 'react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { ChevronDown, ChevronRight, Folder, RotateCcw } from 'lucide-react';
|
||||
import { toast } from 'sonner';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { AddProjectModal } from '@/components/AddProjectModal';
|
||||
import { CreateProjectModal } from '@/components/CreateProjectModal';
|
||||
import { api } from '@/api/client';
|
||||
import type { Project } from '@/api/types';
|
||||
import { sessionEvents } from '@/hooks/sessionEvents';
|
||||
import { useSidebar } from '@/hooks/useSidebar';
|
||||
|
||||
export function Home() {
|
||||
const { data } = useSidebar();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [addOpen, setAddOpen] = useState(false);
|
||||
const [createOpen, setCreateOpen] = useState(false);
|
||||
const [archived, setArchived] = useState<Project[] | null>(null);
|
||||
const [showArchived, setShowArchived] = useState(false);
|
||||
|
||||
const empty = data ? data.projects.length === 0 : false;
|
||||
|
||||
useEffect(() => {
|
||||
api.projects.list({ status: 'archived' })
|
||||
.then(setArchived)
|
||||
.catch(() => {});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
return sessionEvents.subscribe((event) => {
|
||||
if (event.type === 'project_archived') {
|
||||
setArchived((prev) => {
|
||||
if (!prev) return prev;
|
||||
if (prev.some((p) => p.id === event.project_id)) return prev;
|
||||
const fromSidebar = data?.projects.find((p) => p.id === event.project_id);
|
||||
if (!fromSidebar) return prev;
|
||||
return [
|
||||
{
|
||||
id: fromSidebar.id,
|
||||
name: fromSidebar.name,
|
||||
path: fromSidebar.path,
|
||||
added_at: new Date().toISOString(),
|
||||
last_session_id: null,
|
||||
status: 'archived' as const,
|
||||
gitea_remote: fromSidebar.gitea_remote,
|
||||
},
|
||||
...prev,
|
||||
];
|
||||
});
|
||||
}
|
||||
if (event.type === 'project_unarchived') {
|
||||
setArchived((prev) => prev ? prev.filter((p) => p.id !== event.project.id) : prev);
|
||||
}
|
||||
if (event.type === 'project_deleted') {
|
||||
setArchived((prev) => prev ? prev.filter((p) => p.id !== event.project_id) : prev);
|
||||
}
|
||||
if (event.type === 'project_updated') {
|
||||
setArchived((prev) =>
|
||||
prev ? prev.map((p) => p.id === event.project_id ? { ...p, name: event.name } : p) : prev
|
||||
);
|
||||
}
|
||||
});
|
||||
}, [data]);
|
||||
|
||||
async function handleUnarchive(id: string) {
|
||||
try {
|
||||
await api.projects.unarchive(id);
|
||||
// Server publishes project_unarchived; useUserEvents delivers it.
|
||||
} catch (err) {
|
||||
toast.error(err instanceof Error ? err.message : 'failed to restore project');
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex-1 flex items-center justify-center px-6">
|
||||
<div className="max-w-md text-center space-y-4">
|
||||
{empty ? (
|
||||
<>
|
||||
<h1 className="text-2xl font-semibold tracking-tight">No projects yet</h1>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Add a project from /opt to start chatting about its code.
|
||||
</p>
|
||||
<Button onClick={() => setOpen(true)}>Add project</Button>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<h1 className="text-2xl font-semibold tracking-tight">BooCode</h1>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Pick a project from the sidebar.
|
||||
</p>
|
||||
</>
|
||||
<div className="flex-1 flex flex-col items-center px-6 py-12 overflow-y-auto">
|
||||
<div className="w-full max-w-md space-y-6">
|
||||
<div className="text-center space-y-3">
|
||||
{empty ? (
|
||||
<>
|
||||
<h1 className="text-2xl font-semibold tracking-tight">No projects yet</h1>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Add a project from /opt or create a new one.
|
||||
</p>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<h1 className="text-2xl font-semibold tracking-tight">BooCode</h1>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Pick a project from the sidebar, or add another.
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
<div className="flex gap-2 justify-center pt-2">
|
||||
<Button variant="outline" onClick={() => setAddOpen(true)}>Add existing project</Button>
|
||||
<Button onClick={() => setCreateOpen(true)}>Create new project</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{archived && archived.length > 0 && (
|
||||
<div className="border-t pt-6">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowArchived(!showArchived)}
|
||||
className="flex items-center gap-1 text-xs font-medium text-muted-foreground mb-2 hover:text-foreground"
|
||||
>
|
||||
{showArchived ? <ChevronDown size={12} /> : <ChevronRight size={12} />}
|
||||
Archived Projects ({archived.length})
|
||||
</button>
|
||||
{showArchived && (
|
||||
<ul className="divide-y rounded-md border">
|
||||
{archived.map((p) => (
|
||||
<li key={p.id} className="flex items-center justify-between px-3 py-2 hover:bg-muted/50">
|
||||
<div className="flex-1 flex items-center gap-2 min-w-0">
|
||||
<Folder className="size-3.5 opacity-40 shrink-0" />
|
||||
<span className="truncate text-sm text-muted-foreground" title={p.name}>{p.name}</span>
|
||||
</div>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
aria-label="Restore project"
|
||||
title="Restore project"
|
||||
onClick={() => void handleUnarchive(p.id)}
|
||||
>
|
||||
<RotateCcw size={14} />
|
||||
</Button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<AddProjectModal open={open} onOpenChange={setOpen} onAdded={() => {}} />
|
||||
<AddProjectModal open={addOpen} onOpenChange={setAddOpen} onAdded={() => {}} />
|
||||
<CreateProjectModal open={createOpen} onOpenChange={setCreateOpen} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user