Open History to see the last commit
1import { ChevronRightIcon, TerminalIcon } from "lucide-react";
2import { useCallback, useEffect, useMemo, useState } from "react";
3import {
4 DEFAULT_MODEL,
5 ProjectId,
6 ThreadId,
7 type ResolvedKeybindingsConfig,
8} from "@t3tools/contracts";
9import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
10import { useNavigate, useParams } from "@tanstack/react-router";
11import { useAppSettings } from "../appSettings";
12import { isElectron } from "../env";
13import { APP_STAGE_LABEL } from "../branding";
14import { newCommandId, newProjectId, newThreadId } from "../lib/utils";
15import { useStore } from "../store";
16import { isChatNewLocalShortcut, isChatNewShortcut } from "../keybindings";
17import { type Thread } from "../types";
18import { gitRemoveWorktreeMutationOptions } from "../lib/gitReactQuery";
19import { serverConfigQueryOptions } from "../lib/serverReactQuery";
20import { readNativeApi } from "../nativeApi";
21import { toastManager } from "./ui/toast";
22import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "./ui/collapsible";
23import {
24 SidebarContent,
25 SidebarFooter,
26 SidebarGroup,
27 SidebarHeader,
28 SidebarMenu,
29 SidebarMenuButton,
30 SidebarMenuItem,
31 SidebarMenuSub,
32 SidebarMenuSubButton,
33 SidebarMenuSubItem,
34 SidebarSeparator,
35 SidebarTrigger,
36} from "./ui/sidebar";
37import { formatWorktreePathForDisplay, getOrphanedWorktreePathForThread } from "../worktreeCleanup";
38import { isNonEmpty as isNonEmptyString } from "effect/String";
39
40const EMPTY_KEYBINDINGS: ResolvedKeybindingsConfig = [];
41
42function formatRelativeTime(iso: string): string {
43 const diff = Date.now() - new Date(iso).getTime();
44 const minutes = Math.floor(diff / 60_000);
45 if (minutes < 1) return "just now";
46 if (minutes < 60) return `${minutes}m ago`;
47 const hours = Math.floor(minutes / 60);
48 if (hours < 24) return `${hours}h ago`;
49 return `${Math.floor(hours / 24)}d ago`;
50}
51
52interface ThreadStatusPill {
53 label: "Working" | "Connecting" | "Completed" | "Awaiting response";
54 colorClass: string;
55 dotClass: string;
56 pulse: boolean;
57}
58
59interface TerminalStatusIndicator {
60 label: "Terminal process running";
61 colorClass: string;
62 pulse: boolean;
63}
64
65function hasUnseenCompletion(thread: Thread): boolean {
66 if (!thread.latestTurnCompletedAt) return false;
67 const completedAt = Date.parse(thread.latestTurnCompletedAt);
68 if (Number.isNaN(completedAt)) return false;
69 if (!thread.lastVisitedAt) return true;
70
71 const lastVisitedAt = Date.parse(thread.lastVisitedAt);
72 if (Number.isNaN(lastVisitedAt)) return true;
73 return completedAt > lastVisitedAt;
74}
75
76function threadStatusPill(thread: Thread, hasPendingApprovals: boolean): ThreadStatusPill | null {
77 if (hasPendingApprovals) {
78 return {
79 label: "Awaiting response",
80 colorClass: "text-amber-600 dark:text-amber-300/90",
81 dotClass: "bg-amber-500 dark:bg-amber-300/90",
82 pulse: false,
83 };
84 }
85
86 if (thread.session?.status === "running") {
87 return {
88 label: "Working",
89 colorClass: "text-sky-600 dark:text-sky-300/80",
90 dotClass: "bg-sky-500 dark:bg-sky-300/80",
91 pulse: true,
92 };
93 }
94
95 if (thread.session?.status === "connecting") {
96 return {
97 label: "Connecting",
98 colorClass: "text-sky-600 dark:text-sky-300/80",
99 dotClass: "bg-sky-500 dark:bg-sky-300/80",
100 pulse: true,
101 };
102 }
103
104 if (hasUnseenCompletion(thread)) {
105 return {
106 label: "Completed",
107 colorClass: "text-emerald-600 dark:text-emerald-300/90",
108 dotClass: "bg-emerald-500 dark:bg-emerald-300/90",
109 pulse: false,
110 };
111 }
112
113 return null;
114}
115
116function terminalStatusIndicator(thread: Thread): TerminalStatusIndicator | null {
117 if (thread.runningTerminalIds.length === 0) {
118 return null;
119 }
120 return {
121 label: "Terminal process running",
122 colorClass: "text-teal-600 dark:text-teal-300/90",
123 pulse: true,
124 };
125}
126
127function T3Wordmark() {
128 return (
129 <svg
130 aria-label="T3"
131 className="h-3 w-auto shrink-0 text-foreground"
132 viewBox="15.5309 37 94.3941 56.96"
133 xmlns="http://www.w3.org/2000/svg"
134 >
135 <path
136 d="M33.4509 93V47.56H15.5309V37H64.3309V47.56H46.4109V93H33.4509ZM86.7253 93.96C82.832 93.96 78.9653 93.4533 75.1253 92.44C71.2853 91.3733 68.032 89.88 65.3653 87.96L70.4053 78.04C72.5386 79.5867 75.0186 80.8133 77.8453 81.72C80.672 82.6267 83.5253 83.08 86.4053 83.08C89.6586 83.08 92.2186 82.44 94.0853 81.16C95.952 79.88 96.8853 78.12 96.8853 75.88C96.8853 73.7467 96.0586 72.0667 94.4053 70.84C92.752 69.6133 90.0853 69 86.4053 69H80.4853V60.44L96.0853 42.76L97.5253 47.4H68.1653V37H107.365V45.4L91.8453 63.08L85.2853 59.32H89.0453C95.9253 59.32 101.125 60.8667 104.645 63.96C108.165 67.0533 109.925 71.0267 109.925 75.88C109.925 79.0267 109.099 81.9867 107.445 84.76C105.792 87.48 103.259 89.6933 99.8453 91.4C96.432 93.1067 92.0586 93.96 86.7253 93.96Z"
137 fill="currentColor"
138 />
139 </svg>
140 );
141}
142
143export default function Sidebar() {
144 const { state, dispatch } = useStore();
145 const navigate = useNavigate();
146 const { settings: appSettings } = useAppSettings();
147 const routeThreadId = useParams({
148 strict: false,
149 select: (params) => (params.threadId ? ThreadId.makeUnsafe(params.threadId) : null),
150 });
151 const { data: keybindings = EMPTY_KEYBINDINGS } = useQuery({
152 ...serverConfigQueryOptions(),
153 select: (config) => config.keybindings,
154 });
155 const queryClient = useQueryClient();
156 const removeWorktreeMutation = useMutation(gitRemoveWorktreeMutationOptions({ queryClient }));
157 const [addingProject, setAddingProject] = useState(false);
158 const [newCwd, setNewCwd] = useState("");
159 const [isPickingFolder, setIsPickingFolder] = useState(false);
160 const [isAddingProject, setIsAddingProject] = useState(false);
161 const pendingApprovalByThreadId = useMemo(() => new Map<ThreadId, boolean>(), []);
162
163 const handleNewThread = useCallback(
164 (
165 projectId: ProjectId,
166 options?: {
167 branch?: string | null;
168 worktreePath?: string | null;
169 },
170 ): Promise<void> => {
171 const api = readNativeApi();
172 if (!api) return Promise.resolve();
173 const threadId = newThreadId();
174 const createdAt = new Date().toISOString();
175 const model =
176 state.projects.find((project) => project.id === projectId)?.model ?? DEFAULT_MODEL;
177 return (async () => {
178 await api.orchestration.dispatchCommand({
179 type: "thread.create",
180 commandId: newCommandId(),
181 threadId,
182 projectId,
183 title: "New thread",
184 model,
185 branch: options?.branch ?? null,
186 worktreePath: options?.worktreePath ?? null,
187 createdAt,
188 });
189
190 // Ensure route guards can see the new thread before navigating.
191 try {
192 const snapshot = await api.orchestration.getSnapshot();
193 dispatch({ type: "SYNC_SERVER_READ_MODEL", readModel: snapshot });
194 } catch {
195 // Event stream can still hydrate the thread shortly after dispatch.
196 }
197
198 await navigate({
199 to: "/$threadId",
200 params: { threadId },
201 });
202 })();
203 },
204 [dispatch, navigate, state.projects],
205 );
206
207 const focusMostRecentThreadForProject = useCallback(
208 (projectId: ProjectId) => {
209 const latestThread = state.threads
210 .filter((thread) => thread.projectId === projectId)
211 .toSorted((a, b) => {
212 const byDate = new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime();
213 if (byDate !== 0) return byDate;
214 return b.id.localeCompare(a.id);
215 })[0];
216 if (!latestThread) return;
217
218 void navigate({
219 to: "/$threadId",
220 params: { threadId: latestThread.id },
221 });
222 },
223 [navigate, state.threads],
224 );
225
226 const addProjectFromPath = useCallback(
227 async (rawCwd: string) => {
228 const cwd = rawCwd.trim();
229 if (!cwd || isAddingProject) return;
230 const api = readNativeApi();
231
232 setIsAddingProject(true);
233 try {
234 if (!api) return;
235 const existing = state.projects.find((project) => project.cwd === cwd);
236 if (existing) {
237 focusMostRecentThreadForProject(existing.id);
238 return;
239 }
240
241 const projectId = newProjectId();
242 const createdAt = new Date().toISOString();
243 const title = cwd.split(/[/\\]/).findLast(isNonEmptyString) ?? cwd;
244 await api.orchestration.dispatchCommand({
245 type: "project.create",
246 commandId: newCommandId(),
247 projectId,
248 title,
249 workspaceRoot: cwd,
250 defaultModel: DEFAULT_MODEL,
251 createdAt,
252 });
253 await handleNewThread(projectId);
254 } finally {
255 setIsAddingProject(false);
256 setNewCwd("");
257 setAddingProject(false);
258 }
259 },
260 [focusMostRecentThreadForProject, handleNewThread, isAddingProject, state.projects],
261 );
262
263 const handleAddProject = () => {
264 void addProjectFromPath(newCwd);
265 };
266
267 const handlePickFolder = async () => {
268 const api = readNativeApi();
269 if (!api || isPickingFolder) return;
270 setIsPickingFolder(true);
271 try {
272 const pickedPath = await api.dialogs.pickFolder();
273 if (!pickedPath) return;
274 await addProjectFromPath(pickedPath);
275 } finally {
276 setIsPickingFolder(false);
277 }
278 };
279
280 const handleThreadContextMenu = useCallback(
281 async (threadId: ThreadId, position: { x: number; y: number }) => {
282 const api = readNativeApi();
283 if (!api) return;
284 const clicked = await api.contextMenu.show(
285 [
286 { id: "mark-unread", label: "Mark unread" },
287 { id: "delete", label: "Delete" },
288 ],
289 position,
290 );
291 if (clicked === "mark-unread") {
292 dispatch({ type: "MARK_THREAD_UNREAD", threadId });
293 return;
294 }
295 if (clicked !== "delete") return;
296
297 const thread = state.threads.find((t) => t.id === threadId);
298 if (!thread) return;
299 if (appSettings.confirmThreadDelete) {
300 const confirmed = await api.dialogs.confirm(
301 [
302 `Delete thread "${thread.title}"?`,
303 "This permanently clears conversation history for this thread.",
304 ].join("\n"),
305 );
306 if (!confirmed) {
307 return;
308 }
309 }
310 const threadProject = state.projects.find((project) => project.id === thread.projectId);
311 const orphanedWorktreePath = getOrphanedWorktreePathForThread(state.threads, threadId);
312 const displayWorktreePath = orphanedWorktreePath
313 ? formatWorktreePathForDisplay(orphanedWorktreePath)
314 : null;
315 const canDeleteWorktree = orphanedWorktreePath !== null && threadProject !== undefined;
316 const shouldDeleteWorktree =
317 canDeleteWorktree &&
318 (await api.dialogs.confirm(
319 [
320 "This thread is the only one linked to this worktree:",
321 displayWorktreePath ?? orphanedWorktreePath,
322 "",
323 "Delete the worktree too?",
324 ].join("\n"),
325 ));
326
327 if (thread.session && thread.session.status !== "closed") {
328 await api.orchestration
329 .dispatchCommand({
330 type: "thread.session.stop",
331 commandId: newCommandId(),
332 threadId,
333 createdAt: new Date().toISOString(),
334 })
335 .catch(() => undefined);
336 }
337
338 try {
339 await api.terminal.close({
340 threadId,
341 deleteHistory: true,
342 });
343 } catch {
344 // Terminal may already be closed
345 }
346
347 const shouldNavigateToFallback = routeThreadId === threadId;
348 const fallbackThreadId = state.threads.find((entry) => entry.id !== threadId)?.id ?? null;
349 await api.orchestration.dispatchCommand({
350 type: "thread.delete",
351 commandId: newCommandId(),
352 threadId,
353 });
354 if (shouldNavigateToFallback) {
355 if (fallbackThreadId) {
356 void navigate({
357 to: "/$threadId",
358 params: { threadId: fallbackThreadId },
359 replace: true,
360 });
361 } else {
362 void navigate({ to: "/", replace: true });
363 }
364 }
365
366 if (!shouldDeleteWorktree || !orphanedWorktreePath || !threadProject) {
367 return;
368 }
369
370 try {
371 await removeWorktreeMutation.mutateAsync({
372 cwd: threadProject.cwd,
373 path: orphanedWorktreePath,
374 force: true,
375 });
376 } catch (error) {
377 const message = error instanceof Error ? error.message : "Unknown error removing worktree.";
378 console.error("Failed to remove orphaned worktree after thread deletion", {
379 threadId,
380 projectCwd: threadProject.cwd,
381 worktreePath: orphanedWorktreePath,
382 error,
383 });
384 toastManager.add({
385 type: "error",
386 title: "Thread deleted, but worktree removal failed",
387 description: `Could not remove ${displayWorktreePath ?? orphanedWorktreePath}. ${message}`,
388 });
389 }
390 },
391 [
392 appSettings.confirmThreadDelete,
393 dispatch,
394 navigate,
395 removeWorktreeMutation,
396 routeThreadId,
397 state.projects,
398 state.threads,
399 ],
400 );
401
402 const handleProjectContextMenu = useCallback(
403 async (projectId: ProjectId, position: { x: number; y: number }) => {
404 const api = readNativeApi();
405 if (!api) return;
406 const clicked = await api.contextMenu.show([{ id: "delete", label: "Delete" }], position);
407 if (clicked !== "delete") return;
408
409 const project = state.projects.find((entry) => entry.id === projectId);
410 if (!project) return;
411
412 const projectThreads = state.threads.filter((thread) => thread.projectId === projectId);
413 if (projectThreads.length > 0) {
414 toastManager.add({
415 type: "warning",
416 title: "Project is not empty",
417 description: "Delete all threads in this project before deleting it.",
418 });
419 return;
420 }
421
422 const confirmed = await api.dialogs.confirm(
423 [`Delete project "${project.name}"?`, "This action cannot be undone."].join("\n"),
424 );
425 if (!confirmed) return;
426
427 try {
428 await api.orchestration.dispatchCommand({
429 type: "project.delete",
430 commandId: newCommandId(),
431 projectId,
432 });
433 } catch (error) {
434 const message = error instanceof Error ? error.message : "Unknown error deleting project.";
435 console.error("Failed to remove project", { projectId, error });
436 toastManager.add({
437 type: "error",
438 title: `Failed to delete "${project.name}"`,
439 description: message,
440 });
441 }
442 },
443 [state.projects, state.threads],
444 );
445
446 useEffect(() => {
447 const onWindowKeyDown = (event: KeyboardEvent) => {
448 const activeThread = routeThreadId
449 ? state.threads.find((thread) => thread.id === routeThreadId)
450 : undefined;
451 if (isChatNewLocalShortcut(event, keybindings)) {
452 const projectId = activeThread?.projectId ?? state.projects[0]?.id;
453 if (!projectId) return;
454 event.preventDefault();
455 void handleNewThread(projectId);
456 return;
457 }
458
459 if (!isChatNewShortcut(event, keybindings)) return;
460 const projectId = activeThread?.projectId ?? state.projects[0]?.id;
461 if (!projectId) return;
462 event.preventDefault();
463 void handleNewThread(projectId, {
464 branch: activeThread?.branch ?? null,
465 worktreePath: activeThread?.worktreePath ?? null,
466 });
467 };
468
469 window.addEventListener("keydown", onWindowKeyDown);
470 return () => {
471 window.removeEventListener("keydown", onWindowKeyDown);
472 };
473 }, [handleNewThread, keybindings, routeThreadId, state.projects, state.threads]);
474
475 const onCreateThreadClick = () => {
476 if (state.projects.length === 0) {
477 setAddingProject(true);
478 return;
479 }
480 const firstProject = state.projects[0];
481 if (firstProject) void handleNewThread(firstProject.id);
482 };
483
484 const wordmark = (
485 <div className={`flex items-center gap-2 ${isElectron ? "-translate-y-px" : ""}`}>
486 <SidebarTrigger className="shrink-0 md:hidden" />
487 <div className="flex min-w-0 flex-1 items-center gap-1">
488 <T3Wordmark />
489 <span className="truncate text-base font-medium tracking-tight text-muted-foreground">
490 Code
491 </span>
492 <span className="rounded-full bg-muted/50 px-1.5 py-0.5 text-[9px] font-medium uppercase tracking-widest text-muted-foreground/60">
493 {APP_STAGE_LABEL}
494 </span>
495 </div>
496 </div>
497 );
498
499 const newThreadButton = (
500 <button
501 type="button"
502 className="flex w-full items-center gap-2 rounded-lg border border-border bg-secondary px-3 py-2 text-xs text-muted-foreground transition-colors duration-150 hover:bg-accent"
503 onClick={onCreateThreadClick}
504 >
505 <span className="text-foreground">+</span>
506 New thread
507 </button>
508 );
509
510 return (
511 <>
512 {isElectron ? (
513 <>
514 <SidebarHeader className="drag-region h-[52px] flex-row items-center gap-2 px-4 py-0 pl-[88px]">
515 {wordmark}
516 </SidebarHeader>
517 <div className="px-4 pb-2">{newThreadButton}</div>
518 </>
519 ) : (
520 <SidebarHeader className="gap-3 px-3 py-2 sm:gap-2.5 sm:px-4 sm:py-3">
521 {wordmark}
522 {newThreadButton}
523 </SidebarHeader>
524 )}
525
526 <SidebarContent className="gap-0">
527 <SidebarGroup className="px-2 py-2">
528 <SidebarMenu>
529 {state.projects.map((project) => {
530 const threads = state.threads
531 .filter((thread) => thread.projectId === project.id)
532 .toSorted((a, b) => {
533 const byDate = new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime();
534 if (byDate !== 0) return byDate;
535 return b.id.localeCompare(a.id);
536 });
537
538 return (
539 <Collapsible
540 key={project.id}
541 className="group/collapsible"
542 open={project.expanded}
543 onOpenChange={(open) => {
544 if (open === project.expanded) return;
545 dispatch({ type: "TOGGLE_PROJECT", projectId: project.id });
546 }}
547 >
548 <SidebarMenuItem>
549 <CollapsibleTrigger
550 render={
551 <SidebarMenuButton
552 size="sm"
553 className="gap-2 px-2 py-1.5 text-left hover:bg-accent"
554 />
555 }
556 onContextMenu={(event) => {
557 event.preventDefault();
558 void handleProjectContextMenu(project.id, {
559 x: event.clientX,
560 y: event.clientY,
561 });
562 }}
563 >
564 <ChevronRightIcon
565 className={`-ml-0.5 size-3.5 shrink-0 text-muted-foreground/70 transition-transform duration-150 ${
566 project.expanded ? "rotate-90" : ""
567 }`}
568 />
569 <span className="flex-1 truncate text-xs font-medium text-foreground/90">
570 {project.name}
571 </span>
572 <span className="text-[10px] text-muted-foreground/60">{threads.length}</span>
573 </CollapsibleTrigger>
574
575 <CollapsibleContent>
576 <SidebarMenuSub className="mx-1 my-0 w-full translate-x-0 gap-0 px-1.5 py-0">
577 {threads.map((thread) => {
578 const isActive = routeThreadId === thread.id;
579 const threadStatus = threadStatusPill(
580 thread,
581 pendingApprovalByThreadId.get(thread.id) === true,
582 );
583 const terminalStatus = terminalStatusIndicator(thread);
584
585 return (
586 <SidebarMenuSubItem key={thread.id} className="w-full">
587 <SidebarMenuSubButton
588 render={<button type="button" />}
589 size="sm"
590 isActive={isActive}
591 className={`h-7 w-full translate-x-0 justify-start px-2 text-left hover:bg-accent hover:text-foreground ${
592 isActive
593 ? "bg-accent/85 text-foreground font-medium ring-1 ring-border/70 dark:bg-accent/55 dark:ring-border/50"
594 : "text-muted-foreground"
595 }`}
596 onClick={() => {
597 void navigate({
598 to: "/$threadId",
599 params: { threadId: thread.id },
600 });
601 }}
602 onContextMenu={(event) => {
603 event.preventDefault();
604 void handleThreadContextMenu(thread.id, {
605 x: event.clientX,
606 y: event.clientY,
607 });
608 }}
609 >
610 <div className="flex min-w-0 flex-1 items-center gap-1.5 text-left">
611 {threadStatus && (
612 <span
613 className={`inline-flex items-center gap-1 text-[10px] ${threadStatus.colorClass}`}
614 >
615 <span
616 className={`h-1.5 w-1.5 rounded-full ${threadStatus.dotClass} ${
617 threadStatus.pulse ? "animate-pulse" : ""
618 }`}
619 />
620 <span className="hidden md:inline">{threadStatus.label}</span>
621 </span>
622 )}
623 <span className="min-w-0 flex-1 truncate text-xs">
624 {thread.title}
625 </span>
626 </div>
627 <div className="ml-auto flex shrink-0 items-center gap-1.5">
628 {terminalStatus && (
629 <span
630 role="img"
631 aria-label={terminalStatus.label}
632 title={terminalStatus.label}
633 className={`inline-flex items-center justify-center ${terminalStatus.colorClass}`}
634 >
635 <TerminalIcon
636 className={`size-3 ${terminalStatus.pulse ? "animate-pulse" : ""}`}
637 />
638 </span>
639 )}
640 <span
641 className={`text-[10px] ${
642 isActive ? "text-foreground/65" : "text-muted-foreground/40"
643 }`}
644 >
645 {formatRelativeTime(thread.createdAt)}
646 </span>
647 </div>
648 </SidebarMenuSubButton>
649 </SidebarMenuSubItem>
650 );
651 })}
652
653 <SidebarMenuSubItem className="w-full">
654 <SidebarMenuSubButton
655 render={<button type="button" />}
656 size="sm"
657 className="h-6 w-full translate-x-0 justify-start px-2 text-left text-[10px] text-muted-foreground/60 hover:bg-accent hover:text-muted-foreground/80"
658 onClick={() => {
659 void handleNewThread(project.id);
660 }}
661 >
662 <span>+</span>
663 <span>New thread</span>
664 </SidebarMenuSubButton>
665 </SidebarMenuSubItem>
666 </SidebarMenuSub>
667 </CollapsibleContent>
668 </SidebarMenuItem>
669 </Collapsible>
670 );
671 })}
672 </SidebarMenu>
673
674 {state.projects.length === 0 && !addingProject && (
675 <div className="px-2 pt-4 text-center text-xs text-muted-foreground/60">
676 No projects yet.
677 <br />
678 Add one to get started.
679 </div>
680 )}
681 </SidebarGroup>
682 </SidebarContent>
683
684 <SidebarSeparator />
685 <SidebarFooter className="gap-0 p-3">
686 {addingProject ? (
687 <>
688 <p className="mb-2 text-[10px] font-medium uppercase tracking-wider text-muted-foreground/70">
689 Add project
690 </p>
691 <input
692 className="mb-2 w-full rounded-md border border-border bg-secondary px-2 py-1.5 font-mono text-xs text-foreground placeholder:text-muted-foreground/40 focus:border-ring focus:outline-none"
693 placeholder="/path/to/project"
694 value={newCwd}
695 onChange={(event) => setNewCwd(event.target.value)}
696 onKeyDown={(event) => {
697 if (event.key === "Enter") handleAddProject();
698 if (event.key === "Escape") setAddingProject(false);
699 }}
700 />
701 {isElectron && (
702 <button
703 type="button"
704 className="mb-2 flex w-full items-center justify-center rounded-md border border-border px-2 py-1.5 text-xs text-muted-foreground transition-colors duration-150 hover:bg-secondary disabled:cursor-not-allowed disabled:opacity-60"
705 onClick={() => void handlePickFolder()}
706 disabled={isPickingFolder || isAddingProject}
707 >
708 {isPickingFolder ? "Picking folder..." : "Browse for folder"}
709 </button>
710 )}
711 <div className="flex gap-2">
712 <button
713 type="button"
714 className="flex-1 rounded-md bg-primary px-2 py-1 text-xs font-medium text-primary-foreground transition-colors duration-150 hover:bg-primary/90"
715 onClick={handleAddProject}
716 disabled={isAddingProject}
717 >
718 {isAddingProject ? "Adding..." : "Add"}
719 </button>
720 <button
721 type="button"
722 className="flex-1 rounded-md border border-border px-2 py-1 text-xs text-muted-foreground/80 transition-colors duration-150 hover:bg-secondary"
723 onClick={() => setAddingProject(false)}
724 >
725 Cancel
726 </button>
727 </div>
728 </>
729 ) : (
730 <button
731 type="button"
732 className="flex w-full items-center justify-center gap-1 rounded-md border border-dashed border-border py-2 text-xs text-muted-foreground/70 transition-colors duration-150 hover:border-ring hover:text-muted-foreground"
733 onClick={() => setAddingProject(true)}
734 >
735 + Add project
736 </button>
737 )}
738 </SidebarFooter>
739 </>
740 );
741}