Adds a singleton, ephemeral 'settings' pane kind to the workspace. Opened via a new bottom-pinned button in ProjectSidebar (emits an open_settings_pane event when a session is mounted; navigates to /settings otherwise). Pane has three sections — Session, Project, Theme — and a maximize toggle that hides sibling pane columns via display:none on desktop only. Settings panes don't count toward MAX_PANES and are filtered out of the localStorage persistence layer so reload always restores a clean workspace. Schema (additive): - projects.default_system_prompt TEXT NOT NULL DEFAULT '' - projects.default_web_search_enabled BOOLEAN NOT NULL DEFAULT false - sessions.web_search_enabled BOOLEAN (nullable; null = inherit) Inference resolves user_prompt = session.system_prompt.trim() || project.default_system_prompt.trim() — empty/whitespace at either layer means "no override". Keeps the columns NOT NULL and matches the existing inherit semantics. Server routes: - GET /api/projects/:id (new; settings pane refetches on project_updated) - PATCH /api/projects/:id accepts default_system_prompt, default_web_search_enabled - PATCH /api/sessions/:id accepts web_search_enabled (tri-state) - POST /api/projects/:id/sessions/archive-all + GET /api/projects/:id/sessions/open-count - POST /api/sessions/:id/chats/archive-all + GET /api/sessions/:id/chats/open-count - PATCH /api/sessions/:id now broadcasts session_updated on every successful PATCH (was rename-only). Lets SettingsPane open in another tab pick up edits without a refetch. Bulk-archive publishes one session_archived / chat_archived frame per affected id so useSidebar's existing reducer cases handle them incrementally — no new frame type, no payload widening. ModelPicker refactored: shared ModelList inside a responsive shell. Desktop = labeled trigger + DropdownMenu, mobile = icon-only Cpu button + BottomSheet. Header in Session.tsx drops the pill wrap on mobile since the new trigger is the visual. ChatInput gains an icon-only '+' DropdownMenu next to AgentPicker when sessionId + webSearchEnabled props are provided. One item for now — Web search — with a checkmark reflecting the stored value (true), not the effective one. Click PATCHes the override; to restore inherit-from-project the user opens SettingsPane. ThemePicker lifted out of pages/Settings.tsx into a reusable component. The standalone /settings route is now a thin wrapper that mounts <ThemePicker /> with a Back button on top (navigate(-1) with fallback to '/'); the SettingsPane Theme tab renders the same picker bare. Project section delete-flow removed (button + confirm dialog + handler). Replaced with "Archive all sessions" using the same two-step count → confirm → fire pattern as "Archive all chats" in the Session section. api.projects.remove() stays in the client because useProjects.ts still uses it. Hand-rolled Switch primitive in SettingsPane (no shadcn switch in the project; spec said no new deps). Section nav is plain buttons (no shadcn Tabs). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
172 lines
6.9 KiB
TypeScript
172 lines
6.9 KiB
TypeScript
import { useEffect, useState } from 'react';
|
|
import { ChevronDown, ChevronRight, Folder, FolderTree, Menu, 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';
|
|
import { useSidebarDrawer } from '@/hooks/useSidebarDrawer';
|
|
import { useRightRailDrawer } from '@/hooks/useRightRailDrawer';
|
|
import { useViewport } from '@/hooks/useViewport';
|
|
|
|
export function Home() {
|
|
const { data } = useSidebar();
|
|
const [addOpen, setAddOpen] = useState(false);
|
|
const [createOpen, setCreateOpen] = useState(false);
|
|
const [archived, setArchived] = useState<Project[] | null>(null);
|
|
const [showArchived, setShowArchived] = useState(false);
|
|
const { setOpen: setSidebarOpen } = useSidebarDrawer();
|
|
const { toggle: toggleRightRail } = useRightRailDrawer();
|
|
const { isMobile } = useViewport();
|
|
|
|
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,
|
|
// v1.9: synthesized stub for an archived project that only the
|
|
// sidebar cache has — defaults match the schema NOT NULL DEFAULT
|
|
// values. The full row gets re-fetched on unarchive.
|
|
default_system_prompt: '',
|
|
default_web_search_enabled: false,
|
|
},
|
|
...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 flex-col min-h-0">
|
|
{isMobile && (
|
|
<header
|
|
className="border-b px-3 sm:px-4 py-2 flex items-center gap-1.5 shrink-0 text-sm"
|
|
style={{ paddingTop: 'max(0.5rem, env(safe-area-inset-top))' }}
|
|
>
|
|
<button
|
|
type="button"
|
|
onClick={() => setSidebarOpen(true)}
|
|
className="inline-flex items-center justify-center -ml-1 min-w-[44px] min-h-[44px] rounded text-muted-foreground hover:bg-muted hover:text-foreground shrink-0"
|
|
aria-label="Open sidebar"
|
|
>
|
|
<Menu className="size-5" />
|
|
</button>
|
|
<button
|
|
type="button"
|
|
onClick={toggleRightRail}
|
|
className="inline-flex items-center justify-center -mr-1 ml-auto min-w-[44px] min-h-[44px] rounded text-muted-foreground hover:bg-muted hover:text-foreground shrink-0"
|
|
aria-label="Toggle file browser"
|
|
>
|
|
<FolderTree className="size-5" />
|
|
</button>
|
|
</header>
|
|
)}
|
|
<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={addOpen} onOpenChange={setAddOpen} onAdded={() => {}} />
|
|
<CreateProjectModal open={createOpen} onOpenChange={setCreateOpen} />
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|