diff --git a/components/sidebar.tsx b/components/sidebar.tsx index 8eeb6c0..072e119 100644 --- a/components/sidebar.tsx +++ b/components/sidebar.tsx @@ -1,10 +1,11 @@ "use client"; -import { createContext, useCallback, useContext, useEffect, useState } from "react"; +import { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react"; import Link from "next/link"; import { usePathname, useRouter } from "next/navigation"; -import { PanelLeftCloseIcon, PanelLeftOpenIcon } from "lucide-react"; +import { PanelLeftCloseIcon, PanelLeftOpenIcon, PlusIcon, SearchIcon } from "lucide-react"; import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; import { cn } from "@/lib/utils"; import type { ChatListItem, Phase3 } from "@/src/core"; @@ -181,9 +182,26 @@ export function SessionRow({ function SessionsSidebar() { const { open, toggle } = useSidebar(); const [chats, setChats] = useState(null); + const [query, setQuery] = useState(""); const pathname = usePathname(); const router = useRouter(); + /* New session: one POST, then hello. Search: a client-side filter over + the poll snapshot — no server round trip. Both were visual-only in + the wave-5 mock; wiring each is a single tiny handler. */ + const newSession = useCallback(async () => { + const res = await fetch("/api/chats", { method: "POST", headers: { "content-type": "application/json" }, body: "{}" }); + const d = (await res.json().catch(() => null)) as { id?: string } | null; + if (d?.id) router.push(`/chat/${d.id}`); + }, [router]); + + const shown = useMemo(() => { + const q = query.trim().toLowerCase(); + if (!chats) return chats; + if (!q) return chats; + return chats.filter((c) => c.title.toLowerCase().includes(q)); + }, [chats, query]); + const refresh = useCallback(async () => { try { const res = await fetch("/api/chats", { cache: "no-store" }); @@ -213,22 +231,51 @@ function SessionsSidebar() { aria-hidden={!open} >
+ {/* LH wordmark — the owner's header; close toggle sits at the edge. */}
- - Learning Harness + + LH
+ + +
+ Sessions + + setQuery(e.target.value)} + placeholder="Search..." + aria-label="Search sessions" + className="h-6 rounded-sm border-border bg-background pl-6 text-xs placeholder:text-muted-foreground/60" + /> + + +
+
- {chats === null ? ( -
Loading…
- ) : chats.length === 0 ? ( -
No sessions yet.
+ {shown === null ? ( +
Loading…
+ ) : shown.length === 0 ? ( +
+ {query.trim() ? "No sessions match." : "No sessions yet."} +
) : ( - chats.map((c) => ( + shown.map((c) => (