| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | import { | 1 | import { |
| 2 | ArrowLeftIcon, | 2 | ArrowLeftIcon, |
| | 3 | ArrowUpDownIcon, |
| 3 | ChevronRightIcon, | 4 | ChevronRightIcon, |
| 4 | FolderIcon, | 5 | FolderIcon, |
| 5 | GitPullRequestIcon, | 6 | GitPullRequestIcon, |
| ... | @@ -10,6 +11,7 @@ import { | ... | @@ -10,6 +11,7 @@ import { |
| 10 | TerminalIcon, | 11 | TerminalIcon, |
| 11 | TriangleAlertIcon, | 12 | TriangleAlertIcon, |
| 12 | } from "lucide-react"; | 13 | } from "lucide-react"; |
| | 14 | import { autoAnimate } from "@formkit/auto-animate"; |
| 13 | import { useCallback, useEffect, useMemo, useRef, useState, type MouseEvent } from "react"; | 15 | import { useCallback, useEffect, useMemo, useRef, useState, type MouseEvent } from "react"; |
| 14 | import { | 16 | import { |
| 15 | DndContext, | 17 | DndContext, |
| ... | @@ -36,7 +38,11 @@ import { | ... | @@ -36,7 +38,11 @@ import { |
| 36 | } from "@t3tools/contracts"; | 38 | } from "@t3tools/contracts"; |
| 37 | import { useMutation, useQueries, useQuery, useQueryClient } from "@tanstack/react-query"; | 39 | import { useMutation, useQueries, useQuery, useQueryClient } from "@tanstack/react-query"; |
| 38 | import { useLocation, useNavigate, useParams } from "@tanstack/react-router"; | 40 | import { useLocation, useNavigate, useParams } from "@tanstack/react-router"; |
| 39 | import { useAppSettings } from "../appSettings"; | 41 | import { |
| | 42 | type SidebarProjectSortOrder, |
| | 43 | type SidebarThreadSortOrder, |
| | 44 | useAppSettings, |
| | 45 | } from "../appSettings"; |
| 40 | import { isElectron } from "../env"; | 46 | import { isElectron } from "../env"; |
| 41 | import { APP_STAGE_LABEL, APP_VERSION } from "../branding"; | 47 | import { APP_STAGE_LABEL, APP_VERSION } from "../branding"; |
| 42 | import { isLinuxPlatform, isMacPlatform, newCommandId, newProjectId } from "../lib/utils"; | 48 | import { isLinuxPlatform, isMacPlatform, newCommandId, newProjectId } from "../lib/utils"; |
| ... | @@ -64,6 +70,7 @@ import { | ... | @@ -64,6 +70,7 @@ import { |
| 64 | import { Alert, AlertAction, AlertDescription, AlertTitle } from "./ui/alert"; | 70 | import { Alert, AlertAction, AlertDescription, AlertTitle } from "./ui/alert"; |
| 65 | import { Button } from "./ui/button"; | 71 | import { Button } from "./ui/button"; |
| 66 | import { Collapsible, CollapsibleContent } from "./ui/collapsible"; | 72 | import { Collapsible, CollapsibleContent } from "./ui/collapsible"; |
| | 73 | import { Menu, MenuGroup, MenuPopup, MenuRadioGroup, MenuRadioItem, MenuTrigger } from "./ui/menu"; |
| 67 | import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip"; | 74 | import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip"; |
| 68 | import { | 75 | import { |
| 69 | SidebarContent, | 76 | SidebarContent, |
| ... | @@ -84,16 +91,33 @@ import { useThreadSelectionStore } from "../threadSelectionStore"; | ... | @@ -84,16 +91,33 @@ import { useThreadSelectionStore } from "../threadSelectionStore"; |
| 84 | import { formatWorktreePathForDisplay, getOrphanedWorktreePathForThread } from "../worktreeCleanup"; | 91 | import { formatWorktreePathForDisplay, getOrphanedWorktreePathForThread } from "../worktreeCleanup"; |
| 85 | import { isNonEmpty as isNonEmptyString } from "effect/String"; | 92 | import { isNonEmpty as isNonEmptyString } from "effect/String"; |
| 86 | import { | 93 | import { |
| | 94 | getVisibleThreadsForProject, |
| 87 | resolveProjectStatusIndicator, | 95 | resolveProjectStatusIndicator, |
| 88 | resolveSidebarNewThreadEnvMode, | 96 | resolveSidebarNewThreadEnvMode, |
| 89 | resolveThreadRowClassName, | 97 | resolveThreadRowClassName, |
| 90 | resolveThreadStatusPill, | 98 | resolveThreadStatusPill, |
| 91 | shouldClearThreadSelectionOnMouseDown, | 99 | shouldClearThreadSelectionOnMouseDown, |
| | 100 | sortProjectsForSidebar, |
| | 101 | sortThreadsForSidebar, |
| 92 | } from "./Sidebar.logic"; | 102 | } from "./Sidebar.logic"; |
| 93 | import { useCopyToClipboard } from "~/hooks/useCopyToClipboard"; | 103 | import { useCopyToClipboard } from "~/hooks/useCopyToClipboard"; |
| 94 | | 104 | |
| 95 | const EMPTY_KEYBINDINGS: ResolvedKeybindingsConfig = []; | 105 | const EMPTY_KEYBINDINGS: ResolvedKeybindingsConfig = []; |
| 96 | const THREAD_PREVIEW_LIMIT = 6; | 106 | const THREAD_PREVIEW_LIMIT = 6; |
| | 107 | const SIDEBAR_SORT_LABELS: Record<SidebarProjectSortOrder, string> = { |
| | 108 | updated_at: "Last user message", |
| | 109 | created_at: "Created at", |
| | 110 | manual: "Manual", |
| | 111 | }; |
| | 112 | const SIDEBAR_THREAD_SORT_LABELS: Record<SidebarThreadSortOrder, string> = { |
| | 113 | updated_at: "Last user message", |
| | 114 | created_at: "Created at", |
| | 115 | }; |
| | 116 | const SIDEBAR_LIST_ANIMATION_OPTIONS = { |
| | 117 | duration: 180, |
| | 118 | easing: "ease-out", |
| | 119 | } as const; |
| | 120 | const loadedProjectFaviconSrcs = new Set<string>(); |
| 97 | | 121 | |
| 98 | function formatRelativeTime(iso: string): string { | 122 | function formatRelativeTime(iso: string): string { |
| 99 | const diff = Date.now() - new Date(iso).getTime(); | 123 | const diff = Date.now() - new Date(iso).getTime(); |
| ... | @@ -204,9 +228,10 @@ function getServerHttpOrigin(): string { | ... | @@ -204,9 +228,10 @@ function getServerHttpOrigin(): string { |
| 204 | const serverHttpOrigin = getServerHttpOrigin(); | 228 | const serverHttpOrigin = getServerHttpOrigin(); |
| 205 | | 229 | |
| 206 | function ProjectFavicon({ cwd }: { cwd: string }) { | 230 | function ProjectFavicon({ cwd }: { cwd: string }) { |
| 207 | const [status, setStatus] = useState<"loading" | "loaded" | "error">("loading"); | | |
| 208 | | | |
| 209 | const src = `${serverHttpOrigin}/api/project-favicon?cwd=${encodeURIComponent(cwd)}`; | 231 | const src = `${serverHttpOrigin}/api/project-favicon?cwd=${encodeURIComponent(cwd)}`; |
| | 232 | const [status, setStatus] = useState<"loading" | "loaded" | "error">(() => |
| | 233 | loadedProjectFaviconSrcs.has(src) ? "loaded" : "loading", |
| | 234 | ); |
| 210 | | 235 | |
| 211 | if (status === "error") { | 236 | if (status === "error") { |
| 212 | return <FolderIcon className="size-3.5 shrink-0 text-muted-foreground/50" />; | 237 | return <FolderIcon className="size-3.5 shrink-0 text-muted-foreground/50" />; |
| ... | @@ -217,23 +242,106 @@ function ProjectFavicon({ cwd }: { cwd: string }) { | ... | @@ -217,23 +242,106 @@ function ProjectFavicon({ cwd }: { cwd: string }) { |
| 217 | src={src} | 242 | src={src} |
| 218 | alt="" | 243 | alt="" |
| 219 | className={`size-3.5 shrink-0 rounded-sm object-contain ${status === "loading" ? "hidden" : ""}`} | 244 | className={`size-3.5 shrink-0 rounded-sm object-contain ${status === "loading" ? "hidden" : ""}`} |
| 220 | onLoad={() => setStatus("loaded")} | 245 | onLoad={() => { |
| | 246 | loadedProjectFaviconSrcs.add(src); |
| | 247 | setStatus("loaded"); |
| | 248 | }} |
| 221 | onError={() => setStatus("error")} | 249 | onError={() => setStatus("error")} |
| 222 | /> | 250 | /> |
| 223 | ); | 251 | ); |
| 224 | } | 252 | } |
| 225 | | 253 | |
| 226 | type SortableProjectHandleProps = Pick<ReturnType<typeof useSortable>, "attributes" | "listeners">; | 254 | type SortableProjectHandleProps = Pick< |
| | 255 | ReturnType<typeof useSortable>, |
| | 256 | "attributes" | "listeners" | "setActivatorNodeRef" |
| | 257 | >; |
| | 258 | |
| | 259 | function ProjectSortMenu({ |
| | 260 | projectSortOrder, |
| | 261 | threadSortOrder, |
| | 262 | onProjectSortOrderChange, |
| | 263 | onThreadSortOrderChange, |
| | 264 | }: { |
| | 265 | projectSortOrder: SidebarProjectSortOrder; |
| | 266 | threadSortOrder: SidebarThreadSortOrder; |
| | 267 | onProjectSortOrderChange: (sortOrder: SidebarProjectSortOrder) => void; |
| | 268 | onThreadSortOrderChange: (sortOrder: SidebarThreadSortOrder) => void; |
| | 269 | }) { |
| | 270 | return ( |
| | 271 | <Menu> |
| | 272 | <Tooltip> |
| | 273 | <TooltipTrigger |
| | 274 | render={ |
| | 275 | <MenuTrigger className="inline-flex size-5 cursor-pointer items-center justify-center rounded-md text-muted-foreground/60 transition-colors hover:bg-accent hover:text-foreground" /> |
| | 276 | } |
| | 277 | > |
| | 278 | <ArrowUpDownIcon className="size-3.5" /> |
| | 279 | </TooltipTrigger> |
| | 280 | <TooltipPopup side="right">Sort projects</TooltipPopup> |
| | 281 | </Tooltip> |
| | 282 | <MenuPopup align="end" side="bottom" className="min-w-44"> |
| | 283 | <MenuGroup> |
| | 284 | <div className="px-2 py-1 sm:text-xs font-medium text-muted-foreground"> |
| | 285 | Sort projects |
| | 286 | </div> |
| | 287 | <MenuRadioGroup |
| | 288 | value={projectSortOrder} |
| | 289 | onValueChange={(value) => { |
| | 290 | onProjectSortOrderChange(value as SidebarProjectSortOrder); |
| | 291 | }} |
| | 292 | > |
| | 293 | {(Object.entries(SIDEBAR_SORT_LABELS) as Array<[SidebarProjectSortOrder, string]>).map( |
| | 294 | ([value, label]) => ( |
| | 295 | <MenuRadioItem key={value} value={value} className="min-h-7 py-1 sm:text-xs"> |
| | 296 | {label} |
| | 297 | </MenuRadioItem> |
| | 298 | ), |
| | 299 | )} |
| | 300 | </MenuRadioGroup> |
| | 301 | </MenuGroup> |
| | 302 | <MenuGroup> |
| | 303 | <div className="px-2 pt-2 pb-1 sm:text-xs font-medium text-muted-foreground"> |
| | 304 | Sort threads |
| | 305 | </div> |
| | 306 | <MenuRadioGroup |
| | 307 | value={threadSortOrder} |
| | 308 | onValueChange={(value) => { |
| | 309 | onThreadSortOrderChange(value as SidebarThreadSortOrder); |
| | 310 | }} |
| | 311 | > |
| | 312 | {( |
| | 313 | Object.entries(SIDEBAR_THREAD_SORT_LABELS) as Array<[SidebarThreadSortOrder, string]> |
| | 314 | ).map(([value, label]) => ( |
| | 315 | <MenuRadioItem key={value} value={value} className="min-h-7 py-1 sm:text-xs"> |
| | 316 | {label} |
| | 317 | </MenuRadioItem> |
| | 318 | ))} |
| | 319 | </MenuRadioGroup> |
| | 320 | </MenuGroup> |
| | 321 | </MenuPopup> |
| | 322 | </Menu> |
| | 323 | ); |
| | 324 | } |
| 227 | | 325 | |
| 228 | function SortableProjectItem({ | 326 | function SortableProjectItem({ |
| 229 | projectId, | 327 | projectId, |
| | 328 | disabled = false, |
| 230 | children, | 329 | children, |
| 231 | }: { | 330 | }: { |
| 232 | projectId: ProjectId; | 331 | projectId: ProjectId; |
| | 332 | disabled?: boolean; |
| 233 | children: (handleProps: SortableProjectHandleProps) => React.ReactNode; | 333 | children: (handleProps: SortableProjectHandleProps) => React.ReactNode; |
| 234 | }) { | 334 | }) { |
| 235 | const { attributes, listeners, setNodeRef, transform, transition, isDragging, isOver } = | 335 | const { |
| 236 | useSortable({ id: projectId }); | 336 | attributes, |
| | 337 | listeners, |
| | 338 | setActivatorNodeRef, |
| | 339 | setNodeRef, |
| | 340 | transform, |
| | 341 | transition, |
| | 342 | isDragging, |
| | 343 | isOver, |
| | 344 | } = useSortable({ id: projectId, disabled }); |
| 237 | return ( | 345 | return ( |
| 238 | <li | 346 | <li |
| 239 | ref={setNodeRef} | 347 | ref={setNodeRef} |
| ... | @@ -247,7 +355,7 @@ function SortableProjectItem({ | ... | @@ -247,7 +355,7 @@ function SortableProjectItem({ |
| 247 | data-sidebar="menu-item" | 355 | data-sidebar="menu-item" |
| 248 | data-slot="sidebar-menu-item" | 356 | data-slot="sidebar-menu-item" |
| 249 | > | 357 | > |
| 250 | {children({ attributes, listeners })} | 358 | {children({ attributes, listeners, setActivatorNodeRef })} |
| 251 | </li> | 359 | </li> |
| 252 | ); | 360 | ); |
| 253 | } | 361 | } |
| ... | @@ -272,7 +380,7 @@ export default function Sidebar() { | ... | @@ -272,7 +380,7 @@ export default function Sidebar() { |
| 272 | ); | 380 | ); |
| 273 | const navigate = useNavigate(); | 381 | const navigate = useNavigate(); |
| 274 | const isOnSettings = useLocation({ select: (loc) => loc.pathname === "/settings" }); | 382 | const isOnSettings = useLocation({ select: (loc) => loc.pathname === "/settings" }); |
| 275 | const { settings: appSettings } = useAppSettings(); | 383 | const { settings: appSettings, updateSettings } = useAppSettings(); |
| 276 | const { handleNewThread } = useHandleNewThread(); | 384 | const { handleNewThread } = useHandleNewThread(); |
| 277 | const routeThreadId = useParams({ | 385 | const routeThreadId = useParams({ |
| 278 | strict: false, | 386 | strict: false, |
| ... | @@ -385,13 +493,10 @@ export default function Sidebar() { | ... | @@ -385,13 +493,10 @@ export default function Sidebar() { |
| 385 | | 493 | |
| 386 | const focusMostRecentThreadForProject = useCallback( | 494 | const focusMostRecentThreadForProject = useCallback( |
| 387 | (projectId: ProjectId) => { | 495 | (projectId: ProjectId) => { |
| 388 | const latestThread = threads | 496 | const latestThread = sortThreadsForSidebar( |
| 389 | .filter((thread) => thread.projectId === projectId) | 497 | threads.filter((thread) => thread.projectId === projectId), |
| 390 | .toSorted((a, b) => { | 498 | appSettings.sidebarThreadSortOrder, |
| 391 | const byDate = new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime(); | 499 | )[0]; |
| 392 | if (byDate !== 0) return byDate; | | |
| 393 | return b.id.localeCompare(a.id); | | |
| 394 | })[0]; | | |
| 395 | if (!latestThread) return; | 500 | if (!latestThread) return; |
| 396 | | 501 | |
| 397 | void navigate({ | 502 | void navigate({ |
| ... | @@ -399,7 +504,7 @@ export default function Sidebar() { | ... | @@ -399,7 +504,7 @@ export default function Sidebar() { |
| 399 | params: { threadId: latestThread.id }, | 504 | params: { threadId: latestThread.id }, |
| 400 | }); | 505 | }); |
| 401 | }, | 506 | }, |
| 402 | [navigate, threads], | 507 | [appSettings.sidebarThreadSortOrder, navigate, threads], |
| 403 | ); | 508 | ); |
| 404 | | 509 | |
| 405 | const addProjectFromPath = useCallback( | 510 | const addProjectFromPath = useCallback( |
| ... | @@ -931,6 +1036,10 @@ export default function Sidebar() { | ... | @@ -931,6 +1036,10 @@ export default function Sidebar() { |
| 931 | | 1036 | |
| 932 | const handleProjectDragEnd = useCallback( | 1037 | const handleProjectDragEnd = useCallback( |
| 933 | (event: DragEndEvent) => { | 1038 | (event: DragEndEvent) => { |
| | 1039 | if (appSettings.sidebarProjectSortOrder !== "manual") { |
| | 1040 | dragInProgressRef.current = false; |
| | 1041 | return; |
| | 1042 | } |
| 934 | dragInProgressRef.current = false; | 1043 | dragInProgressRef.current = false; |
| 935 | const { active, over } = event; | 1044 | const { active, over } = event; |
| 936 | if (!over || active.id === over.id) return; | 1045 | if (!over || active.id === over.id) return; |
| ... | @@ -939,22 +1048,361 @@ export default function Sidebar() { | ... | @@ -939,22 +1048,361 @@ export default function Sidebar() { |
| 939 | if (!activeProject || !overProject) return; | 1048 | if (!activeProject || !overProject) return; |
| 940 | reorderProjects(activeProject.id, overProject.id); | 1049 | reorderProjects(activeProject.id, overProject.id); |
| 941 | }, | 1050 | }, |
| 942 | [projects, reorderProjects], | 1051 | [appSettings.sidebarProjectSortOrder, projects, reorderProjects], |
| 943 | ); | 1052 | ); |
| 944 | | 1053 | |
| 945 | const handleProjectDragStart = useCallback((_event: DragStartEvent) => { | 1054 | const handleProjectDragStart = useCallback( |
| 946 | dragInProgressRef.current = true; | 1055 | (_event: DragStartEvent) => { |
| 947 | suppressProjectClickAfterDragRef.current = true; | 1056 | if (appSettings.sidebarProjectSortOrder !== "manual") { |
| 948 | }, []); | 1057 | return; |
| | 1058 | } |
| | 1059 | dragInProgressRef.current = true; |
| | 1060 | suppressProjectClickAfterDragRef.current = true; |
| | 1061 | }, |
| | 1062 | [appSettings.sidebarProjectSortOrder], |
| | 1063 | ); |
| 949 | | 1064 | |
| 950 | const handleProjectDragCancel = useCallback((_event: DragCancelEvent) => { | 1065 | const handleProjectDragCancel = useCallback((_event: DragCancelEvent) => { |
| 951 | dragInProgressRef.current = false; | 1066 | dragInProgressRef.current = false; |
| 952 | }, []); | 1067 | }, []); |
| 953 | | 1068 | |
| | 1069 | const animatedProjectListsRef = useRef(new WeakSet<HTMLElement>()); |
| | 1070 | const attachProjectListAutoAnimateRef = useCallback((node: HTMLElement | null) => { |
| | 1071 | if (!node || animatedProjectListsRef.current.has(node)) { |
| | 1072 | return; |
| | 1073 | } |
| | 1074 | autoAnimate(node, SIDEBAR_LIST_ANIMATION_OPTIONS); |
| | 1075 | animatedProjectListsRef.current.add(node); |
| | 1076 | }, []); |
| | 1077 | |
| | 1078 | const animatedThreadListsRef = useRef(new WeakSet<HTMLElement>()); |
| | 1079 | const attachThreadListAutoAnimateRef = useCallback((node: HTMLElement | null) => { |
| | 1080 | if (!node || animatedThreadListsRef.current.has(node)) { |
| | 1081 | return; |
| | 1082 | } |
| | 1083 | autoAnimate(node, SIDEBAR_LIST_ANIMATION_OPTIONS); |
| | 1084 | animatedThreadListsRef.current.add(node); |
| | 1085 | }, []); |
| | 1086 | |
| 954 | const handleProjectTitlePointerDownCapture = useCallback(() => { | 1087 | const handleProjectTitlePointerDownCapture = useCallback(() => { |
| 955 | suppressProjectClickAfterDragRef.current = false; | 1088 | suppressProjectClickAfterDragRef.current = false; |
| 956 | }, []); | 1089 | }, []); |
| 957 | | 1090 | |
| | 1091 | const sortedProjects = useMemo( |
| | 1092 | () => sortProjectsForSidebar(projects, threads, appSettings.sidebarProjectSortOrder), |
| | 1093 | [appSettings.sidebarProjectSortOrder, projects, threads], |
| | 1094 | ); |
| | 1095 | const isManualProjectSorting = appSettings.sidebarProjectSortOrder === "manual"; |
| | 1096 | |
| | 1097 | function renderProjectItem( |
| | 1098 | project: (typeof sortedProjects)[number], |
| | 1099 | dragHandleProps: SortableProjectHandleProps | null, |
| | 1100 | ) { |
| | 1101 | const projectThreads = sortThreadsForSidebar( |
| | 1102 | threads.filter((thread) => thread.projectId === project.id), |
| | 1103 | appSettings.sidebarThreadSortOrder, |
| | 1104 | ); |
| | 1105 | const projectStatus = resolveProjectStatusIndicator( |
| | 1106 | projectThreads.map((thread) => |
| | 1107 | resolveThreadStatusPill({ |
| | 1108 | thread, |
| | 1109 | hasPendingApprovals: derivePendingApprovals(thread.activities).length > 0, |
| | 1110 | hasPendingUserInput: derivePendingUserInputs(thread.activities).length > 0, |
| | 1111 | }), |
| | 1112 | ), |
| | 1113 | ); |
| | 1114 | const activeThreadId = routeThreadId ?? undefined; |
| | 1115 | const isThreadListExpanded = expandedThreadListsByProject.has(project.id); |
| | 1116 | const pinnedCollapsedThread = |
| | 1117 | !project.expanded && activeThreadId |
| | 1118 | ? (projectThreads.find((thread) => thread.id === activeThreadId) ?? null) |
| | 1119 | : null; |
| | 1120 | const shouldShowThreadPanel = project.expanded || pinnedCollapsedThread !== null; |
| | 1121 | const { hasHiddenThreads, visibleThreads } = getVisibleThreadsForProject({ |
| | 1122 | threads: projectThreads, |
| | 1123 | activeThreadId, |
| | 1124 | isThreadListExpanded, |
| | 1125 | previewLimit: THREAD_PREVIEW_LIMIT, |
| | 1126 | }); |
| | 1127 | const orderedProjectThreadIds = projectThreads.map((thread) => thread.id); |
| | 1128 | const renderedThreads = pinnedCollapsedThread ? [pinnedCollapsedThread] : visibleThreads; |
| | 1129 | const renderThreadRow = (thread: (typeof projectThreads)[number]) => { |
| | 1130 | const isActive = routeThreadId === thread.id; |
| | 1131 | const isSelected = selectedThreadIds.has(thread.id); |
| | 1132 | const isHighlighted = isActive || isSelected; |
| | 1133 | const threadStatus = resolveThreadStatusPill({ |
| | 1134 | thread, |
| | 1135 | hasPendingApprovals: derivePendingApprovals(thread.activities).length > 0, |
| | 1136 | hasPendingUserInput: derivePendingUserInputs(thread.activities).length > 0, |
| | 1137 | }); |
| | 1138 | const prStatus = prStatusIndicator(prByThreadId.get(thread.id) ?? null); |
| | 1139 | const terminalStatus = terminalStatusFromRunningIds( |
| | 1140 | selectThreadTerminalState(terminalStateByThreadId, thread.id).runningTerminalIds, |
| | 1141 | ); |
| | 1142 | |
| | 1143 | return ( |
| | 1144 | <SidebarMenuSubItem key={thread.id} className="w-full" data-thread-item> |
| | 1145 | <SidebarMenuSubButton |
| | 1146 | render={<div role="button" tabIndex={0} />} |
| | 1147 | size="sm" |
| | 1148 | isActive={isActive} |
| | 1149 | className={resolveThreadRowClassName({ |
| | 1150 | isActive, |
| | 1151 | isSelected, |
| | 1152 | })} |
| | 1153 | onClick={(event) => { |
| | 1154 | handleThreadClick(event, thread.id, orderedProjectThreadIds); |
| | 1155 | }} |
| | 1156 | onKeyDown={(event) => { |
| | 1157 | if (event.key !== "Enter" && event.key !== " ") return; |
| | 1158 | event.preventDefault(); |
| | 1159 | if (selectedThreadIds.size > 0) { |
| | 1160 | clearSelection(); |
| | 1161 | } |
| | 1162 | setSelectionAnchor(thread.id); |
| | 1163 | void navigate({ |
| | 1164 | to: "/$threadId", |
| | 1165 | params: { threadId: thread.id }, |
| | 1166 | }); |
| | 1167 | }} |
| | 1168 | onContextMenu={(event) => { |
| | 1169 | event.preventDefault(); |
| | 1170 | if (selectedThreadIds.size > 0 && selectedThreadIds.has(thread.id)) { |
| | 1171 | void handleMultiSelectContextMenu({ |
| | 1172 | x: event.clientX, |
| | 1173 | y: event.clientY, |
| | 1174 | }); |
| | 1175 | } else { |
| | 1176 | if (selectedThreadIds.size > 0) { |
| | 1177 | clearSelection(); |
| | 1178 | } |
| | 1179 | void handleThreadContextMenu(thread.id, { |
| | 1180 | x: event.clientX, |
| | 1181 | y: event.clientY, |
| | 1182 | }); |
| | 1183 | } |
| | 1184 | }} |
| | 1185 | > |
| | 1186 | <div className="flex min-w-0 flex-1 items-center gap-1.5 text-left"> |
| | 1187 | {prStatus && ( |
| | 1188 | <Tooltip> |
| | 1189 | <TooltipTrigger |
| | 1190 | render={ |
| | 1191 | <button |
| | 1192 | type="button" |
| | 1193 | aria-label={prStatus.tooltip} |
| | 1194 | className={`inline-flex items-center justify-center ${prStatus.colorClass} cursor-pointer rounded-sm outline-hidden focus-visible:ring-1 focus-visible:ring-ring`} |
| | 1195 | onClick={(event) => { |
| | 1196 | openPrLink(event, prStatus.url); |
| | 1197 | }} |
| | 1198 | > |
| | 1199 | <GitPullRequestIcon className="size-3" /> |
| | 1200 | </button> |
| | 1201 | } |
| | 1202 | /> |
| | 1203 | <TooltipPopup side="top">{prStatus.tooltip}</TooltipPopup> |
| | 1204 | </Tooltip> |
| | 1205 | )} |
| | 1206 | {threadStatus && ( |
| | 1207 | <span |
| | 1208 | className={`inline-flex items-center gap-1 text-[10px] ${threadStatus.colorClass}`} |
| | 1209 | > |
| | 1210 | <span |
| | 1211 | className={`h-1.5 w-1.5 rounded-full ${threadStatus.dotClass} ${ |
| | 1212 | threadStatus.pulse ? "animate-pulse" : "" |
| | 1213 | }`} |
| | 1214 | /> |
| | 1215 | <span className="hidden md:inline">{threadStatus.label}</span> |
| | 1216 | </span> |
| | 1217 | )} |
| | 1218 | {renamingThreadId === thread.id ? ( |
| | 1219 | <input |
| | 1220 | ref={(el) => { |
| | 1221 | if (el && renamingInputRef.current !== el) { |
| | 1222 | renamingInputRef.current = el; |
| | 1223 | el.focus(); |
| | 1224 | el.select(); |
| | 1225 | } |
| | 1226 | }} |
| | 1227 | className="min-w-0 flex-1 truncate text-xs bg-transparent outline-none border border-ring rounded px-0.5" |
| | 1228 | value={renamingTitle} |
| | 1229 | onChange={(e) => setRenamingTitle(e.target.value)} |
| | 1230 | onKeyDown={(e) => { |
| | 1231 | e.stopPropagation(); |
| | 1232 | if (e.key === "Enter") { |
| | 1233 | e.preventDefault(); |
| | 1234 | renamingCommittedRef.current = true; |
| | 1235 | void commitRename(thread.id, renamingTitle, thread.title); |
| | 1236 | } else if (e.key === "Escape") { |
| | 1237 | e.preventDefault(); |
| | 1238 | renamingCommittedRef.current = true; |
| | 1239 | cancelRename(); |
| | 1240 | } |
| | 1241 | }} |
| | 1242 | onBlur={() => { |
| | 1243 | if (!renamingCommittedRef.current) { |
| | 1244 | void commitRename(thread.id, renamingTitle, thread.title); |
| | 1245 | } |
| | 1246 | }} |
| | 1247 | onClick={(e) => e.stopPropagation()} |
| | 1248 | /> |
| | 1249 | ) : ( |
| | 1250 | <span className="min-w-0 flex-1 truncate text-xs">{thread.title}</span> |
| | 1251 | )} |
| | 1252 | </div> |
| | 1253 | <div className="ml-auto flex shrink-0 items-center gap-1.5"> |
| | 1254 | {terminalStatus && ( |
| | 1255 | <span |
| | 1256 | role="img" |
| | 1257 | aria-label={terminalStatus.label} |
| | 1258 | title={terminalStatus.label} |
| | 1259 | className={`inline-flex items-center justify-center ${terminalStatus.colorClass}`} |
| | 1260 | > |
| | 1261 | <TerminalIcon |
| | 1262 | className={`size-3 ${terminalStatus.pulse ? "animate-pulse" : ""}`} |
| | 1263 | /> |
| | 1264 | </span> |
| | 1265 | )} |
| | 1266 | <span |
| | 1267 | className={`text-[10px] ${ |
| | 1268 | isHighlighted |
| | 1269 | ? "text-foreground/72 dark:text-foreground/82" |
| | 1270 | : "text-muted-foreground/40" |
| | 1271 | }`} |
| | 1272 | > |
| | 1273 | {formatRelativeTime(thread.updatedAt ?? thread.createdAt)} |
| | 1274 | </span> |
| | 1275 | </div> |
| | 1276 | </SidebarMenuSubButton> |
| | 1277 | </SidebarMenuSubItem> |
| | 1278 | ); |
| | 1279 | }; |
| | 1280 | |
| | 1281 | return ( |
| | 1282 | <Collapsible className="group/collapsible" open={shouldShowThreadPanel}> |
| | 1283 | <div className="group/project-header relative"> |
| | 1284 | <SidebarMenuButton |
| | 1285 | ref={isManualProjectSorting ? dragHandleProps?.setActivatorNodeRef : undefined} |
| | 1286 | size="sm" |
| | 1287 | className={`gap-2 px-2 py-1.5 text-left hover:bg-accent group-hover/project-header:bg-accent group-hover/project-header:text-sidebar-accent-foreground ${ |
| | 1288 | isManualProjectSorting ? "cursor-grab active:cursor-grabbing" : "cursor-pointer" |
| | 1289 | }`} |
| | 1290 | {...(isManualProjectSorting && dragHandleProps ? dragHandleProps.attributes : {})} |
| | 1291 | {...(isManualProjectSorting && dragHandleProps ? dragHandleProps.listeners : {})} |
| | 1292 | onPointerDownCapture={handleProjectTitlePointerDownCapture} |
| | 1293 | onClick={(event) => handleProjectTitleClick(event, project.id)} |
| | 1294 | onKeyDown={(event) => handleProjectTitleKeyDown(event, project.id)} |
| | 1295 | onContextMenu={(event) => { |
| | 1296 | event.preventDefault(); |
| | 1297 | void handleProjectContextMenu(project.id, { |
| | 1298 | x: event.clientX, |
| | 1299 | y: event.clientY, |
| | 1300 | }); |
| | 1301 | }} |
| | 1302 | > |
| | 1303 | {!project.expanded && projectStatus ? ( |
| | 1304 | <span |
| | 1305 | aria-hidden="true" |
| | 1306 | title={projectStatus.label} |
| | 1307 | className={`-ml-0.5 relative inline-flex size-3.5 shrink-0 items-center justify-center ${projectStatus.colorClass}`} |
| | 1308 | > |
| | 1309 | <span className="absolute inset-0 flex items-center justify-center transition-opacity duration-150 group-hover/project-header:opacity-0"> |
| | 1310 | <span |
| | 1311 | className={`size-[9px] rounded-full ${projectStatus.dotClass} ${ |
| | 1312 | projectStatus.pulse ? "animate-pulse" : "" |
| | 1313 | }`} |
| | 1314 | /> |
| | 1315 | </span> |
| | 1316 | <ChevronRightIcon className="absolute inset-0 m-auto size-3.5 text-muted-foreground/70 opacity-0 transition-opacity duration-150 group-hover/project-header:opacity-100" /> |
| | 1317 | </span> |
| | 1318 | ) : ( |
| | 1319 | <ChevronRightIcon |
| | 1320 | className={`-ml-0.5 size-3.5 shrink-0 text-muted-foreground/70 transition-transform duration-150 ${ |
| | 1321 | project.expanded ? "rotate-90" : "" |
| | 1322 | }`} |
| | 1323 | /> |
| | 1324 | )} |
| | 1325 | <ProjectFavicon cwd={project.cwd} /> |
| | 1326 | <span className="flex-1 truncate text-xs font-medium text-foreground/90"> |
| | 1327 | {project.name} |
| | 1328 | </span> |
| | 1329 | </SidebarMenuButton> |
| | 1330 | <Tooltip> |
| | 1331 | <TooltipTrigger |
| | 1332 | render={ |
| | 1333 | <SidebarMenuAction |
| | 1334 | render={ |
| | 1335 | <button |
| | 1336 | type="button" |
| | 1337 | aria-label={`Create new thread in ${project.name}`} |
| | 1338 | data-testid="new-thread-button" |
| | 1339 | /> |
| | 1340 | } |
| | 1341 | showOnHover |
| | 1342 | className="top-1 right-1 size-5 rounded-md p-0 text-muted-foreground/70 hover:bg-secondary hover:text-foreground" |
| | 1343 | onClick={(event) => { |
| | 1344 | event.preventDefault(); |
| | 1345 | event.stopPropagation(); |
| | 1346 | void handleNewThread(project.id, { |
| | 1347 | envMode: resolveSidebarNewThreadEnvMode({ |
| | 1348 | defaultEnvMode: appSettings.defaultThreadEnvMode, |
| | 1349 | }), |
| | 1350 | }); |
| | 1351 | }} |
| | 1352 | > |
| | 1353 | <SquarePenIcon className="size-3.5" /> |
| | 1354 | </SidebarMenuAction> |
| | 1355 | } |
| | 1356 | /> |
| | 1357 | <TooltipPopup side="top"> |
| | 1358 | {newThreadShortcutLabel ? `New thread (${newThreadShortcutLabel})` : "New thread"} |
| | 1359 | </TooltipPopup> |
| | 1360 | </Tooltip> |
| | 1361 | </div> |
| | 1362 | |
| | 1363 | <CollapsibleContent> |
| | 1364 | <SidebarMenuSub |
| | 1365 | ref={attachThreadListAutoAnimateRef} |
| | 1366 | className="mx-1 my-0 w-full translate-x-0 gap-0.5 px-1.5 py-0" |
| | 1367 | > |
| | 1368 | {renderedThreads.map((thread) => renderThreadRow(thread))} |
| | 1369 | |
| | 1370 | {project.expanded && hasHiddenThreads && !isThreadListExpanded && ( |
| | 1371 | <SidebarMenuSubItem className="w-full"> |
| | 1372 | <SidebarMenuSubButton |
| | 1373 | render={<button type="button" />} |
| | 1374 | data-thread-selection-safe |
| | 1375 | size="sm" |
| | 1376 | 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" |
| | 1377 | onClick={() => { |
| | 1378 | expandThreadListForProject(project.id); |
| | 1379 | }} |
| | 1380 | > |
| | 1381 | <span>Show more</span> |
| | 1382 | </SidebarMenuSubButton> |
| | 1383 | </SidebarMenuSubItem> |
| | 1384 | )} |
| | 1385 | {project.expanded && hasHiddenThreads && isThreadListExpanded && ( |
| | 1386 | <SidebarMenuSubItem className="w-full"> |
| | 1387 | <SidebarMenuSubButton |
| | 1388 | render={<button type="button" />} |
| | 1389 | data-thread-selection-safe |
| | 1390 | size="sm" |
| | 1391 | 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" |
| | 1392 | onClick={() => { |
| | 1393 | collapseThreadListForProject(project.id); |
| | 1394 | }} |
| | 1395 | > |
| | 1396 | <span>Show less</span> |
| | 1397 | </SidebarMenuSubButton> |
| | 1398 | </SidebarMenuSubItem> |
| | 1399 | )} |
| | 1400 | </SidebarMenuSub> |
| | 1401 | </CollapsibleContent> |
| | 1402 | </Collapsible> |
| | 1403 | ); |
| | 1404 | } |
| | 1405 | |
| 958 | const handleProjectTitleClick = useCallback( | 1406 | const handleProjectTitleClick = useCallback( |
| 959 | (event: React.MouseEvent<HTMLButtonElement>, projectId: ProjectId) => { | 1407 | (event: React.MouseEvent<HTMLButtonElement>, projectId: ProjectId) => { |
| 960 | if (dragInProgressRef.current) { | 1408 | if (dragInProgressRef.current) { |
| ... | @@ -1063,12 +1511,9 @@ export default function Sidebar() { | ... | @@ -1063,12 +1511,9 @@ export default function Sidebar() { |
| 1063 | : shouldHighlightDesktopUpdateError(desktopUpdateState) | 1511 | : shouldHighlightDesktopUpdateError(desktopUpdateState) |
| 1064 | ? "text-rose-500 animate-pulse" | 1512 | ? "text-rose-500 animate-pulse" |
| 1065 | : "text-amber-500 animate-pulse"; | 1513 | : "text-amber-500 animate-pulse"; |
| 1066 | const newThreadShortcutLabel = useMemo( | 1514 | const newThreadShortcutLabel = |
| 1067 | () => | 1515 | shortcutLabelForCommand(keybindings, "chat.newLocal") ?? |
| 1068 | shortcutLabelForCommand(keybindings, "chat.newLocal") ?? | 1516 | shortcutLabelForCommand(keybindings, "chat.new"); |
| 1069 | shortcutLabelForCommand(keybindings, "chat.new"), | | |
| 1070 | [keybindings], | | |
| 1071 | ); | | |
| 1072 | | 1517 | |
| 1073 | const handleDesktopUpdateButtonClick = useCallback(() => { | 1518 | const handleDesktopUpdateButtonClick = useCallback(() => { |
| 1074 | const bridge = window.desktopBridge; | 1519 | const bridge = window.desktopBridge; |
| ... | @@ -1232,28 +1677,40 @@ export default function Sidebar() { | ... | @@ -1232,28 +1677,40 @@ export default function Sidebar() { |
| 1232 | <span className="text-[10px] font-medium uppercase tracking-wider text-muted-foreground/60"> | 1677 | <span className="text-[10px] font-medium uppercase tracking-wider text-muted-foreground/60"> |
| 1233 | Projects | 1678 | Projects |
| 1234 | </span> | 1679 | </span> |
| 1235 | <Tooltip> | 1680 | <div className="flex items-center gap-1"> |
| 1236 | <TooltipTrigger | 1681 | <ProjectSortMenu |
| 1237 | render={ | 1682 | projectSortOrder={appSettings.sidebarProjectSortOrder} |
| 1238 | <button | 1683 | threadSortOrder={appSettings.sidebarThreadSortOrder} |
| 1239 | type="button" | 1684 | onProjectSortOrderChange={(sortOrder) => { |
| 1240 | aria-label={shouldShowProjectPathEntry ? "Cancel add project" : "Add project"} | 1685 | updateSettings({ sidebarProjectSortOrder: sortOrder }); |
| 1241 | aria-pressed={shouldShowProjectPathEntry} | 1686 | }} |
| 1242 | className="inline-flex size-5 cursor-pointer items-center justify-center rounded-md text-muted-foreground/60 transition-colors hover:bg-accent hover:text-foreground" | 1687 | onThreadSortOrderChange={(sortOrder) => { |
| 1243 | onClick={handleStartAddProject} | 1688 | updateSettings({ sidebarThreadSortOrder: sortOrder }); |
| | 1689 | }} |
| | 1690 | /> |
| | 1691 | <Tooltip> |
| | 1692 | <TooltipTrigger |
| | 1693 | render={ |
| | 1694 | <button |
| | 1695 | type="button" |
| | 1696 | aria-label={shouldShowProjectPathEntry ? "Cancel add project" : "Add project"} |
| | 1697 | aria-pressed={shouldShowProjectPathEntry} |
| | 1698 | className="inline-flex size-5 cursor-pointer items-center justify-center rounded-md text-muted-foreground/60 transition-colors hover:bg-accent hover:text-foreground" |
| | 1699 | onClick={handleStartAddProject} |
| | 1700 | /> |
| | 1701 | } |
| | 1702 | > |
| | 1703 | <PlusIcon |
| | 1704 | className={`size-3.5 transition-transform duration-150 ${ |
| | 1705 | shouldShowProjectPathEntry ? "rotate-45" : "rotate-0" |
| | 1706 | }`} |
| 1244 | /> | 1707 | /> |
| 1245 | } | 1708 | </TooltipTrigger> |
| 1246 | > | 1709 | <TooltipPopup side="right"> |
| 1247 | <PlusIcon | 1710 | {shouldShowProjectPathEntry ? "Cancel add project" : "Add project"} |
| 1248 | className={`size-3.5 transition-transform duration-150 ${ | 1711 | </TooltipPopup> |
| 1249 | shouldShowProjectPathEntry ? "rotate-45" : "rotate-0" | 1712 | </Tooltip> |
| 1250 | }`} | 1713 | </div> |
| 1251 | /> | | |
| 1252 | </TooltipTrigger> | | |
| 1253 | <TooltipPopup side="right"> | | |
| 1254 | {shouldShowProjectPathEntry ? "Cancel add project" : "Add project"} | | |
| 1255 | </TooltipPopup> | | |
| 1256 | </Tooltip> | | |
| 1257 | </div> | 1714 | </div> |
| 1258 | | 1715 | |
| 1259 | {shouldShowProjectPathEntry && ( | 1716 | {shouldShowProjectPathEntry && ( |
| ... | @@ -1321,352 +1778,37 @@ export default function Sidebar() { | ... | @@ -1321,352 +1778,37 @@ export default function Sidebar() { |
| 1321 | </div> | 1778 | </div> |
| 1322 | )} | 1779 | )} |
| 1323 | | 1780 | |
| 1324 | <DndContext | 1781 | {isManualProjectSorting ? ( |
| 1325 | sensors={projectDnDSensors} | 1782 | <DndContext |
| 1326 | collisionDetection={projectCollisionDetection} | 1783 | sensors={projectDnDSensors} |
| 1327 | modifiers={[restrictToVerticalAxis, restrictToFirstScrollableAncestor]} | 1784 | collisionDetection={projectCollisionDetection} |
| 1328 | onDragStart={handleProjectDragStart} | 1785 | modifiers={[restrictToVerticalAxis, restrictToFirstScrollableAncestor]} |
| 1329 | onDragEnd={handleProjectDragEnd} | 1786 | onDragStart={handleProjectDragStart} |
| 1330 | onDragCancel={handleProjectDragCancel} | 1787 | onDragEnd={handleProjectDragEnd} |
| 1331 | > | 1788 | onDragCancel={handleProjectDragCancel} |
| 1332 | <SidebarMenu> | 1789 | > |
| 1333 | <SortableContext | 1790 | <SidebarMenu> |
| 1334 | items={projects.map((project) => project.id)} | 1791 | <SortableContext |
| 1335 | strategy={verticalListSortingStrategy} | 1792 | items={sortedProjects.map((project) => project.id)} |
| 1336 | > | 1793 | strategy={verticalListSortingStrategy} |
| 1337 | {projects.map((project) => { | 1794 | > |
| 1338 | const projectThreads = threads | 1795 | {sortedProjects.map((project) => ( |
| 1339 | .filter((thread) => thread.projectId === project.id) | | |
| 1340 | .toSorted((a, b) => { | | |
| 1341 | const byDate = | | |
| 1342 | new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime(); | | |
| 1343 | if (byDate !== 0) return byDate; | | |
| 1344 | return b.id.localeCompare(a.id); | | |
| 1345 | }); | | |
| 1346 | const projectStatus = resolveProjectStatusIndicator( | | |
| 1347 | projectThreads.map((thread) => | | |
| 1348 | resolveThreadStatusPill({ | | |
| 1349 | thread, | | |
| 1350 | hasPendingApprovals: derivePendingApprovals(thread.activities).length > 0, | | |
| 1351 | hasPendingUserInput: derivePendingUserInputs(thread.activities).length > 0, | | |
| 1352 | }), | | |
| 1353 | ), | | |
| 1354 | ); | | |
| 1355 | const isThreadListExpanded = expandedThreadListsByProject.has(project.id); | | |
| 1356 | const hasHiddenThreads = projectThreads.length > THREAD_PREVIEW_LIMIT; | | |
| 1357 | const visibleThreads = | | |
| 1358 | hasHiddenThreads && !isThreadListExpanded | | |
| 1359 | ? projectThreads.slice(0, THREAD_PREVIEW_LIMIT) | | |
| 1360 | : projectThreads; | | |
| 1361 | const orderedProjectThreadIds = projectThreads.map((thread) => thread.id); | | |
| 1362 | | | |
| 1363 | return ( | | |
| 1364 | <SortableProjectItem key={project.id} projectId={project.id}> | 1796 | <SortableProjectItem key={project.id} projectId={project.id}> |
| 1365 | {(dragHandleProps) => ( | 1797 | {(dragHandleProps) => renderProjectItem(project, dragHandleProps)} |
| 1366 | <Collapsible className="group/collapsible" open={project.expanded}> | | |
| 1367 | <div className="group/project-header relative"> | | |
| 1368 | <SidebarMenuButton | | |
| 1369 | size="sm" | | |
| 1370 | className="gap-2 px-2 py-1.5 text-left cursor-grab active:cursor-grabbing hover:bg-accent group-hover/project-header:bg-accent group-hover/project-header:text-sidebar-accent-foreground" | | |
| 1371 | {...dragHandleProps.attributes} | | |
| 1372 | {...dragHandleProps.listeners} | | |
| 1373 | onPointerDownCapture={handleProjectTitlePointerDownCapture} | | |
| 1374 | onClick={(event) => handleProjectTitleClick(event, project.id)} | | |
| 1375 | onKeyDown={(event) => handleProjectTitleKeyDown(event, project.id)} | | |
| 1376 | onContextMenu={(event) => { | | |
| 1377 | event.preventDefault(); | | |
| 1378 | void handleProjectContextMenu(project.id, { | | |
| 1379 | x: event.clientX, | | |
| 1380 | y: event.clientY, | | |
| 1381 | }); | | |
| 1382 | }} | | |
| 1383 | > | | |
| 1384 | {!project.expanded && projectStatus ? ( | | |
| 1385 | <span | | |
| 1386 | aria-hidden="true" | | |
| 1387 | title={projectStatus.label} | | |
| 1388 | className={`-ml-0.5 relative inline-flex size-3.5 shrink-0 items-center justify-center ${projectStatus.colorClass}`} | | |
| 1389 | > | | |
| 1390 | <span className="absolute inset-0 flex items-center justify-center transition-opacity duration-150 group-hover/project-header:opacity-0"> | | |
| 1391 | <span | | |
| 1392 | className={`size-[9px] rounded-full ${projectStatus.dotClass} ${ | | |
| 1393 | projectStatus.pulse ? "animate-pulse" : "" | | |
| 1394 | }`} | | |
| 1395 | /> | | |
| 1396 | </span> | | |
| 1397 | <ChevronRightIcon className="absolute inset-0 m-auto size-3.5 text-muted-foreground/70 opacity-0 transition-opacity duration-150 group-hover/project-header:opacity-100" /> | | |
| 1398 | </span> | | |
| 1399 | ) : ( | | |
| 1400 | <ChevronRightIcon | | |
| 1401 | className={`-ml-0.5 size-3.5 shrink-0 text-muted-foreground/70 transition-transform duration-150 ${ | | |
| 1402 | project.expanded ? "rotate-90" : "" | | |
| 1403 | }`} | | |
| 1404 | /> | | |
| 1405 | )} | | |
| 1406 | <ProjectFavicon cwd={project.cwd} /> | | |
| 1407 | <span className="flex-1 truncate text-xs font-medium text-foreground/90"> | | |
| 1408 | {project.name} | | |
| 1409 | </span> | | |
| 1410 | </SidebarMenuButton> | | |
| 1411 | <Tooltip> | | |
| 1412 | <TooltipTrigger | | |
| 1413 | render={ | | |
| 1414 | <SidebarMenuAction | | |
| 1415 | render={ | | |
| 1416 | <button | | |
| 1417 | type="button" | | |
| 1418 | aria-label={`Create new thread in ${project.name}`} | | |
| 1419 | data-testid="new-thread-button" | | |
| 1420 | /> | | |
| 1421 | } | | |
| 1422 | showOnHover | | |
| 1423 | className="top-1 right-1 size-5 rounded-md p-0 text-muted-foreground/70 hover:bg-secondary hover:text-foreground" | | |
| 1424 | onClick={(event) => { | | |
| 1425 | event.preventDefault(); | | |
| 1426 | event.stopPropagation(); | | |
| 1427 | void handleNewThread(project.id, { | | |
| 1428 | envMode: resolveSidebarNewThreadEnvMode({ | | |
| 1429 | defaultEnvMode: appSettings.defaultThreadEnvMode, | | |
| 1430 | }), | | |
| 1431 | }); | | |
| 1432 | }} | | |
| 1433 | > | | |
| 1434 | <SquarePenIcon className="size-3.5" /> | | |
| 1435 | </SidebarMenuAction> | | |
| 1436 | } | | |
| 1437 | /> | | |
| 1438 | <TooltipPopup side="top"> | | |
| 1439 | {newThreadShortcutLabel | | |
| 1440 | ? `New thread (${newThreadShortcutLabel})` | | |
| 1441 | : "New thread"} | | |
| 1442 | </TooltipPopup> | | |
| 1443 | </Tooltip> | | |
| 1444 | </div> | | |
| 1445 | | | |
| 1446 | <CollapsibleContent keepMounted> | | |
| 1447 | <SidebarMenuSub className="mx-1 my-0 w-full translate-x-0 gap-0.5 px-1.5 py-0"> | | |
| 1448 | {visibleThreads.map((thread) => { | | |
| 1449 | const isActive = routeThreadId === thread.id; | | |
| 1450 | const isSelected = selectedThreadIds.has(thread.id); | | |
| 1451 | const isHighlighted = isActive || isSelected; | | |
| 1452 | const threadStatus = resolveThreadStatusPill({ | | |
| 1453 | thread, | | |
| 1454 | hasPendingApprovals: | | |
| 1455 | derivePendingApprovals(thread.activities).length > 0, | | |
| 1456 | hasPendingUserInput: | | |
| 1457 | derivePendingUserInputs(thread.activities).length > 0, | | |
| 1458 | }); | | |
| 1459 | const prStatus = prStatusIndicator( | | |
| 1460 | prByThreadId.get(thread.id) ?? null, | | |
| 1461 | ); | | |
| 1462 | const terminalStatus = terminalStatusFromRunningIds( | | |
| 1463 | selectThreadTerminalState(terminalStateByThreadId, thread.id) | | |
| 1464 | .runningTerminalIds, | | |
| 1465 | ); | | |
| 1466 | | | |
| 1467 | return ( | | |
| 1468 | <SidebarMenuSubItem | | |
| 1469 | key={thread.id} | | |
| 1470 | className="w-full" | | |
| 1471 | data-thread-item | | |
| 1472 | > | | |
| 1473 | <SidebarMenuSubButton | | |
| 1474 | render={<div role="button" tabIndex={0} />} | | |
| 1475 | size="sm" | | |
| 1476 | isActive={isActive} | | |
| 1477 | className={resolveThreadRowClassName({ | | |
| 1478 | isActive, | | |
| 1479 | isSelected, | | |
| 1480 | })} | | |
| 1481 | onClick={(event) => { | | |
| 1482 | handleThreadClick( | | |
| 1483 | event, | | |
| 1484 | thread.id, | | |
| 1485 | orderedProjectThreadIds, | | |
| 1486 | ); | | |
| 1487 | }} | | |
| 1488 | onKeyDown={(event) => { | | |
| 1489 | if (event.key !== "Enter" && event.key !== " ") return; | | |
| 1490 | event.preventDefault(); | | |
| 1491 | if (selectedThreadIds.size > 0) { | | |
| 1492 | clearSelection(); | | |
| 1493 | } | | |
| 1494 | setSelectionAnchor(thread.id); | | |
| 1495 | void navigate({ | | |
| 1496 | to: "/$threadId", | | |
| 1497 | params: { threadId: thread.id }, | | |
| 1498 | }); | | |
| 1499 | }} | | |
| 1500 | onContextMenu={(event) => { | | |
| 1501 | event.preventDefault(); | | |
| 1502 | if ( | | |
| 1503 | selectedThreadIds.size > 0 && | | |
| 1504 | selectedThreadIds.has(thread.id) | | |
| 1505 | ) { | | |
| 1506 | void handleMultiSelectContextMenu({ | | |
| 1507 | x: event.clientX, | | |
| 1508 | y: event.clientY, | | |
| 1509 | }); | | |
| 1510 | } else { | | |
| 1511 | if (selectedThreadIds.size > 0) { | | |
| 1512 | clearSelection(); | | |
| 1513 | } | | |
| 1514 | void handleThreadContextMenu(thread.id, { | | |
| 1515 | x: event.clientX, | | |
| 1516 | y: event.clientY, | | |
| 1517 | }); | | |
| 1518 | } | | |
| 1519 | }} | | |
| 1520 | > | | |
| 1521 | <div className="flex min-w-0 flex-1 items-center gap-1.5 text-left"> | | |
| 1522 | {prStatus && ( | | |
| 1523 | <Tooltip> | | |
| 1524 | <TooltipTrigger | | |
| 1525 | render={ | | |
| 1526 | <button | | |
| 1527 | type="button" | | |
| 1528 | aria-label={prStatus.tooltip} | | |
| 1529 | className={`inline-flex items-center justify-center ${prStatus.colorClass} cursor-pointer rounded-sm outline-hidden focus-visible:ring-1 focus-visible:ring-ring`} | | |
| 1530 | onClick={(event) => { | | |
| 1531 | openPrLink(event, prStatus.url); | | |
| 1532 | }} | | |
| 1533 | > | | |
| 1534 | <GitPullRequestIcon className="size-3" /> | | |
| 1535 | </button> | | |
| 1536 | } | | |
| 1537 | /> | | |
| 1538 | <TooltipPopup side="top"> | | |
| 1539 | {prStatus.tooltip} | | |
| 1540 | </TooltipPopup> | | |
| 1541 | </Tooltip> | | |
| 1542 | )} | | |
| 1543 | {threadStatus && ( | | |
| 1544 | <span | | |
| 1545 | className={`inline-flex items-center gap-1 text-[10px] ${threadStatus.colorClass}`} | | |
| 1546 | > | | |
| 1547 | <span | | |
| 1548 | className={`h-1.5 w-1.5 rounded-full ${threadStatus.dotClass} ${ | | |
| 1549 | threadStatus.pulse ? "animate-pulse" : "" | | |
| 1550 | }`} | | |
| 1551 | /> | | |
| 1552 | <span className="hidden md:inline"> | | |
| 1553 | {threadStatus.label} | | |
| 1554 | </span> | | |
| 1555 | </span> | | |
| 1556 | )} | | |
| 1557 | {renamingThreadId === thread.id ? ( | | |
| 1558 | <input | | |
| 1559 | ref={(el) => { | | |
| 1560 | if (el && renamingInputRef.current !== el) { | | |
| 1561 | renamingInputRef.current = el; | | |
| 1562 | el.focus(); | | |
| 1563 | el.select(); | | |
| 1564 | } | | |
| 1565 | }} | | |
| 1566 | className="min-w-0 flex-1 truncate text-xs bg-transparent outline-none border border-ring rounded px-0.5" | | |
| 1567 | value={renamingTitle} | | |
| 1568 | onChange={(e) => setRenamingTitle(e.target.value)} | | |
| 1569 | onKeyDown={(e) => { | | |
| 1570 | e.stopPropagation(); | | |
| 1571 | if (e.key === "Enter") { | | |
| 1572 | e.preventDefault(); | | |
| 1573 | renamingCommittedRef.current = true; | | |
| 1574 | void commitRename( | | |
| 1575 | thread.id, | | |
| 1576 | renamingTitle, | | |
| 1577 | thread.title, | | |
| 1578 | ); | | |
| 1579 | } else if (e.key === "Escape") { | | |
| 1580 | e.preventDefault(); | | |
| 1581 | renamingCommittedRef.current = true; | | |
| 1582 | cancelRename(); | | |
| 1583 | } | | |
| 1584 | }} | | |
| 1585 | onBlur={() => { | | |
| 1586 | if (!renamingCommittedRef.current) { | | |
| 1587 | void commitRename( | | |
| 1588 | thread.id, | | |
| 1589 | renamingTitle, | | |
| 1590 | thread.title, | | |
| 1591 | ); | | |
| 1592 | } | | |
| 1593 | }} | | |
| 1594 | onClick={(e) => e.stopPropagation()} | | |
| 1595 | /> | | |
| 1596 | ) : ( | | |
| 1597 | <span className="min-w-0 flex-1 truncate text-xs"> | | |
| 1598 | {thread.title} | | |
| 1599 | </span> | | |
| 1600 | )} | | |
| 1601 | </div> | | |
| 1602 | <div className="ml-auto flex shrink-0 items-center gap-1.5"> | | |
| 1603 | {terminalStatus && ( | | |
| 1604 | <span | | |
| 1605 | role="img" | | |
| 1606 | aria-label={terminalStatus.label} | | |
| 1607 | title={terminalStatus.label} | | |
| 1608 | className={`inline-flex items-center justify-center ${terminalStatus.colorClass}`} | | |
| 1609 | > | | |
| 1610 | <TerminalIcon | | |
| 1611 | className={`size-3 ${terminalStatus.pulse ? "animate-pulse" : ""}`} | | |
| 1612 | /> | | |
| 1613 | </span> | | |
| 1614 | )} | | |
| 1615 | <span | | |
| 1616 | className={`text-[10px] ${ | | |
| 1617 | isHighlighted | | |
| 1618 | ? "text-foreground/72 dark:text-foreground/82" | | |
| 1619 | : "text-muted-foreground/40" | | |
| 1620 | }`} | | |
| 1621 | > | | |
| 1622 | {formatRelativeTime(thread.createdAt)} | | |
| 1623 | </span> | | |
| 1624 | </div> | | |
| 1625 | </SidebarMenuSubButton> | | |
| 1626 | </SidebarMenuSubItem> | | |
| 1627 | ); | | |
| 1628 | })} | | |
| 1629 | | | |
| 1630 | {hasHiddenThreads && !isThreadListExpanded && ( | | |
| 1631 | <SidebarMenuSubItem className="w-full"> | | |
| 1632 | <SidebarMenuSubButton | | |
| 1633 | render={<button type="button" />} | | |
| 1634 | data-thread-selection-safe | | |
| 1635 | size="sm" | | |
| 1636 | 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" | | |
| 1637 | onClick={() => { | | |
| 1638 | expandThreadListForProject(project.id); | | |
| 1639 | }} | | |
| 1640 | > | | |
| 1641 | <span>Show more</span> | | |
| 1642 | </SidebarMenuSubButton> | | |
| 1643 | </SidebarMenuSubItem> | | |
| 1644 | )} | | |
| 1645 | {hasHiddenThreads && isThreadListExpanded && ( | | |
| 1646 | <SidebarMenuSubItem className="w-full"> | | |
| 1647 | <SidebarMenuSubButton | | |
| 1648 | render={<button type="button" />} | | |
| 1649 | data-thread-selection-safe | | |
| 1650 | size="sm" | | |
| 1651 | 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" | | |
| 1652 | onClick={() => { | | |
| 1653 | collapseThreadListForProject(project.id); | | |
| 1654 | }} | | |
| 1655 | > | | |
| 1656 | <span>Show less</span> | | |
| 1657 | </SidebarMenuSubButton> | | |
| 1658 | </SidebarMenuSubItem> | | |
| 1659 | )} | | |
| 1660 | </SidebarMenuSub> | | |
| 1661 | </CollapsibleContent> | | |
| 1662 | </Collapsible> | | |
| 1663 | )} | | |
| 1664 | </SortableProjectItem> | 1798 | </SortableProjectItem> |
| 1665 | ); | 1799 | ))} |
| 1666 | })} | 1800 | </SortableContext> |
| 1667 | </SortableContext> | 1801 | </SidebarMenu> |
| | 1802 | </DndContext> |
| | 1803 | ) : ( |
| | 1804 | <SidebarMenu ref={attachProjectListAutoAnimateRef}> |
| | 1805 | {sortedProjects.map((project) => ( |
| | 1806 | <SidebarMenuItem key={project.id} className="rounded-md"> |
| | 1807 | {renderProjectItem(project, null)} |
| | 1808 | </SidebarMenuItem> |
| | 1809 | ))} |
| 1668 | </SidebarMenu> | 1810 | </SidebarMenu> |
| 1669 | </DndContext> | 1811 | )} |
| 1670 | | 1812 | |
| 1671 | {projects.length === 0 && !shouldShowProjectPathEntry && ( | 1813 | {projects.length === 0 && !shouldShowProjectPathEntry && ( |
| 1672 | <div className="px-2 pt-4 text-center text-xs text-muted-foreground/60"> | 1814 | <div className="px-2 pt-4 text-center text-xs text-muted-foreground/60"> |