| @@ -1,5 +1,6 @@ |
| 1 | 1 | import { |
| 2 | 2 | ArrowLeftIcon, |
| 3 | + ArrowUpDownIcon, |
| 3 | 4 | ChevronRightIcon, |
| 4 | 5 | FolderIcon, |
| 5 | 6 | GitPullRequestIcon, |
| @@ -10,6 +11,7 @@ import { · 4 unmodified lines |
| 10 | 11 | TerminalIcon, |
| 11 | 12 | TriangleAlertIcon, |
| 12 | 13 | } from "lucide-react"; |
| 14 | +import { autoAnimate } from "@formkit/auto-animate"; |
| 13 | 15 | import { useCallback, useEffect, useMemo, useRef, useState, type MouseEvent } from "react"; |
| 14 | 16 | import { |
| 15 | 17 | DndContext, |
| @@ -36,7 +38,11 @@ import { · 20 unmodified lines |
| 36 | 38 | } from "@t3tools/contracts"; |
| 37 | 39 | import { useMutation, useQueries, useQuery, useQueryClient } from "@tanstack/react-query"; |
| 38 | 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 | 46 | import { isElectron } from "../env"; |
| 41 | 47 | import { APP_STAGE_LABEL, APP_VERSION } from "../branding"; |
| 42 | 48 | import { isLinuxPlatform, isMacPlatform, newCommandId, newProjectId } from "../lib/utils"; |
| @@ -64,6 +70,7 @@ import { · 21 unmodified lines |
| 64 | 70 | import { Alert, AlertAction, AlertDescription, AlertTitle } from "./ui/alert"; |
| 65 | 71 | import { Button } from "./ui/button"; |
| 66 | 72 | import { Collapsible, CollapsibleContent } from "./ui/collapsible"; |
| 73 | +import { Menu, MenuGroup, MenuPopup, MenuRadioGroup, MenuRadioItem, MenuTrigger } from "./ui/menu"; |
| 67 | 74 | import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip"; |
| 68 | 75 | import { |
| 69 | 76 | SidebarContent, |
| @@ -89,11 +96,26 @@ import { · 19 unmodified lines |
| 89 | 96 | resolveThreadRowClassName, |
| 90 | 97 | resolveThreadStatusPill, |
| 91 | 98 | shouldClearThreadSelectionOnMouseDown, |
| 99 | + sortProjectsForSidebar, |
| 100 | + sortThreadsForSidebar, |
| 92 | 101 | } from "./Sidebar.logic"; |
| 93 | 102 | import { useCopyToClipboard } from "~/hooks/useCopyToClipboard"; |
| 94 | 103 | |
| 95 | 104 | const EMPTY_KEYBINDINGS: ResolvedKeybindingsConfig = []; |
| 96 | 105 | const THREAD_PREVIEW_LIMIT = 6; |
| 106 | +const SIDEBAR_SORT_LABELS: Record<SidebarProjectSortOrder, string> = { |
| 107 | + updated_at: "Last user message", |
| 108 | + created_at: "Created", |
| 109 | + manual: "Manual", |
| 110 | +}; |
| 111 | +const SIDEBAR_THREAD_SORT_LABELS: Record<SidebarThreadSortOrder, string> = { |
| 112 | + updated_at: "Last user message", |
| 113 | + created_at: "Created", |
| 114 | +}; |
| 115 | +const SIDEBAR_LIST_ANIMATION_OPTIONS = { |
| 116 | + duration: 180, |
| 117 | + easing: "ease-out", |
| 118 | +} as const; |
| 97 | 119 | |
| 98 | 120 | function formatRelativeTime(iso: string): string { |
| 99 | 121 | const diff = Date.now() - new Date(iso).getTime(); |
| @@ -223,17 +245,97 @@ function ProjectFavicon({ cwd }: { cwd: string }) { · 123 unmodified lines |
| 223 | 245 | ); |
| 224 | 246 | } |
| 225 | 247 | |
| 226 | | −type SortableProjectHandleProps = Pick<ReturnType<typeof useSortable>, "attributes" | "listeners">; |
| 248 | +type SortableProjectHandleProps = Pick< |
| 249 | + ReturnType<typeof useSortable>, |
| 250 | + "attributes" | "listeners" | "setActivatorNodeRef" |
| 251 | +>; |
| 252 | + |
| 253 | +function ProjectSortMenu({ |
| 254 | + projectSortOrder, |
| 255 | + threadSortOrder, |
| 256 | + onProjectSortOrderChange, |
| 257 | + onThreadSortOrderChange, |
| 258 | +}: { |
| 259 | + projectSortOrder: SidebarProjectSortOrder; |
| 260 | + threadSortOrder: SidebarThreadSortOrder; |
| 261 | + onProjectSortOrderChange: (sortOrder: SidebarProjectSortOrder) => void; |
| 262 | + onThreadSortOrderChange: (sortOrder: SidebarThreadSortOrder) => void; |
| 263 | +}) { |
| 264 | + return ( |
| 265 | + <Menu> |
| 266 | + <Tooltip> |
| 267 | + <TooltipTrigger |
| 268 | + render={ |
| 269 | + <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" /> |
| 270 | + } |
| 271 | + > |
| 272 | + <ArrowUpDownIcon className="size-3.5" /> |
| 273 | + </TooltipTrigger> |
| 274 | + <TooltipPopup side="right">Sort projects</TooltipPopup> |
| 275 | + </Tooltip> |
| 276 | + <MenuPopup align="end" side="bottom" className="min-w-44"> |
| 277 | + <MenuGroup> |
| 278 | + <div className="px-2 py-1 text-[11px] font-medium text-muted-foreground"> |
| 279 | + Sort projects |
| 280 | + </div> |
| 281 | + <MenuRadioGroup |
| 282 | + value={projectSortOrder} |
| 283 | + onValueChange={(value) => { |
| 284 | + onProjectSortOrderChange(value as SidebarProjectSortOrder); |
| 285 | + }} |
| 286 | + > |
| 287 | + {(Object.entries(SIDEBAR_SORT_LABELS) as Array<[SidebarProjectSortOrder, string]>).map( |
| 288 | + ([value, label]) => ( |
| 289 | + <MenuRadioItem key={value} value={value} className="min-h-7 py-1 text-xs"> |
| 290 | + {label} |
| 291 | + </MenuRadioItem> |
| 292 | + ), |
| 293 | + )} |
| 294 | + </MenuRadioGroup> |
| 295 | + </MenuGroup> |
| 296 | + <MenuGroup> |
| 297 | + <div className="px-2 pt-2 pb-1 text-[11px] font-medium text-muted-foreground"> |
| 298 | + Sort threads |
| 299 | + </div> |
| 300 | + <MenuRadioGroup |
| 301 | + value={threadSortOrder} |
| 302 | + onValueChange={(value) => { |
| 303 | + onThreadSortOrderChange(value as SidebarThreadSortOrder); |
| 304 | + }} |
| 305 | + > |
| 306 | + {( |
| 307 | + Object.entries(SIDEBAR_THREAD_SORT_LABELS) as Array<[SidebarThreadSortOrder, string]> |
| 308 | + ).map(([value, label]) => ( |
| 309 | + <MenuRadioItem key={value} value={value} className="min-h-7 py-1 text-xs"> |
| 310 | + {label} |
| 311 | + </MenuRadioItem> |
| 312 | + ))} |
| 313 | + </MenuRadioGroup> |
| 314 | + </MenuGroup> |
| 315 | + </MenuPopup> |
| 316 | + </Menu> |
| 317 | + ); |
| 318 | +} |
| 227 | 319 | |
| 228 | 320 | function SortableProjectItem({ |
| 229 | 321 | projectId, |
| 322 | + disabled = false, |
| 230 | 323 | children, |
| 231 | 324 | }: { |
| 232 | 325 | projectId: ProjectId; |
| 326 | + disabled?: boolean; |
| 233 | 327 | children: (handleProps: SortableProjectHandleProps) => React.ReactNode; |
| 234 | 328 | }) { |
| 235 | | − const { attributes, listeners, setNodeRef, transform, transition, isDragging, isOver } = |
| 236 | | − useSortable({ id: projectId }); |
| 329 | + const { |
| 330 | + attributes, |
| 331 | + listeners, |
| 332 | + setActivatorNodeRef, |
| 333 | + setNodeRef, |
| 334 | + transform, |
| 335 | + transition, |
| 336 | + isDragging, |
| 337 | + isOver, |
| 338 | + } = useSortable({ id: projectId, disabled }); |
| 237 | 339 | return ( |
| 238 | 340 | <li |
| 239 | 341 | ref={setNodeRef} |
| @@ -247,7 +349,7 @@ function SortableProjectItem({ · 7 unmodified lines |
| 247 | 349 | data-sidebar="menu-item" |
| 248 | 350 | data-slot="sidebar-menu-item" |
| 249 | 351 | > |
| 250 | | − {children({ attributes, listeners })} |
| 352 | + {children({ attributes, listeners, setActivatorNodeRef })} |
| 251 | 353 | </li> |
| 252 | 354 | ); |
| 253 | 355 | } |
| @@ -272,7 +374,7 @@ export default function Sidebar() { · 18 unmodified lines |
| 272 | 374 | ); |
| 273 | 375 | const navigate = useNavigate(); |
| 274 | 376 | const isOnSettings = useLocation({ select: (loc) => loc.pathname === "/settings" }); |
| 275 | | − const { settings: appSettings } = useAppSettings(); |
| 377 | + const { settings: appSettings, updateSettings } = useAppSettings(); |
| 276 | 378 | const { handleNewThread } = useHandleNewThread(); |
| 277 | 379 | const routeThreadId = useParams({ |
| 278 | 380 | strict: false, |
| @@ -385,13 +487,10 @@ export default function Sidebar() { · 106 unmodified lines |
| 385 | 487 | |
| 386 | 488 | const focusMostRecentThreadForProject = useCallback( |
| 387 | 489 | (projectId: ProjectId) => { |
| 388 | | − const latestThread = threads |
| 389 | | − .filter((thread) => thread.projectId === projectId) |
| 390 | | − .toSorted((a, b) => { |
| 391 | | − const byDate = new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime(); |
| 392 | | − if (byDate !== 0) return byDate; |
| 393 | | − return b.id.localeCompare(a.id); |
| 394 | | − })[0]; |
| 490 | + const latestThread = sortThreadsForSidebar( |
| 491 | + threads.filter((thread) => thread.projectId === projectId), |
| 492 | + appSettings.sidebarThreadSortOrder, |
| 493 | + )[0]; |
| 395 | 494 | if (!latestThread) return; |
| 396 | 495 | |
| 397 | 496 | void navigate({ |
| @@ -399,7 +498,7 @@ export default function Sidebar() { · 1 unmodified line |
| 399 | 498 | params: { threadId: latestThread.id }, |
| 400 | 499 | }); |
| 401 | 500 | }, |
| 402 | | − [navigate, threads], |
| 501 | + [appSettings.sidebarThreadSortOrder, navigate, threads], |
| 403 | 502 | ); |
| 404 | 503 | |
| 405 | 504 | const addProjectFromPath = useCallback( |
| @@ -931,6 +1030,10 @@ export default function Sidebar() { · 525 unmodified lines |
| 931 | 1030 | |
| 932 | 1031 | const handleProjectDragEnd = useCallback( |
| 933 | 1032 | (event: DragEndEvent) => { |
| 1033 | + if (appSettings.sidebarProjectSortOrder !== "manual") { |
| 1034 | + dragInProgressRef.current = false; |
| 1035 | + return; |
| 1036 | + } |
| 934 | 1037 | dragInProgressRef.current = false; |
| 935 | 1038 | const { active, over } = event; |
| 936 | 1039 | if (!over || active.id === over.id) return; |
| @@ -939,22 +1042,352 @@ export default function Sidebar() { · 2 unmodified lines |
| 939 | 1042 | if (!activeProject || !overProject) return; |
| 940 | 1043 | reorderProjects(activeProject.id, overProject.id); |
| 941 | 1044 | }, |
| 942 | | − [projects, reorderProjects], |
| 1045 | + [appSettings.sidebarProjectSortOrder, projects, reorderProjects], |
| 943 | 1046 | ); |
| 944 | 1047 | |
| 945 | | − const handleProjectDragStart = useCallback((_event: DragStartEvent) => { |
| 946 | | − dragInProgressRef.current = true; |
| 947 | | − suppressProjectClickAfterDragRef.current = true; |
| 948 | | − }, []); |
| 1048 | + const handleProjectDragStart = useCallback( |
| 1049 | + (_event: DragStartEvent) => { |
| 1050 | + if (appSettings.sidebarProjectSortOrder !== "manual") { |
| 1051 | + return; |
| 1052 | + } |
| 1053 | + dragInProgressRef.current = true; |
| 1054 | + suppressProjectClickAfterDragRef.current = true; |
| 1055 | + }, |
| 1056 | + [appSettings.sidebarProjectSortOrder], |
| 1057 | + ); |
| 949 | 1058 | |
| 950 | 1059 | const handleProjectDragCancel = useCallback((_event: DragCancelEvent) => { |
| 951 | 1060 | dragInProgressRef.current = false; |
| 952 | 1061 | }, []); |
| 953 | 1062 | |
| 1063 | + const animatedProjectListsRef = useRef(new WeakSet<HTMLElement>()); |
| 1064 | + const attachProjectListAutoAnimateRef = useCallback((node: HTMLElement | null) => { |
| 1065 | + if (!node || animatedProjectListsRef.current.has(node)) { |
| 1066 | + return; |
| 1067 | + } |
| 1068 | + autoAnimate(node, SIDEBAR_LIST_ANIMATION_OPTIONS); |
| 1069 | + animatedProjectListsRef.current.add(node); |
| 1070 | + }, []); |
| 1071 | + |
| 1072 | + const animatedThreadListsRef = useRef(new WeakSet<HTMLElement>()); |
| 1073 | + const attachThreadListAutoAnimateRef = useCallback((node: HTMLElement | null) => { |
| 1074 | + if (!node || animatedThreadListsRef.current.has(node)) { |
| 1075 | + return; |
| 1076 | + } |
| 1077 | + autoAnimate(node, SIDEBAR_LIST_ANIMATION_OPTIONS); |
| 1078 | + animatedThreadListsRef.current.add(node); |
| 1079 | + }, []); |
| 1080 | + |
| 954 | 1081 | const handleProjectTitlePointerDownCapture = useCallback(() => { |
| 955 | 1082 | suppressProjectClickAfterDragRef.current = false; |
| 956 | 1083 | }, []); |
| 957 | 1084 | |
| 1085 | + const sortedProjects = useMemo( |
| 1086 | + () => sortProjectsForSidebar(projects, threads, appSettings.sidebarProjectSortOrder), |
| 1087 | + [appSettings.sidebarProjectSortOrder, projects, threads], |
| 1088 | + ); |
| 1089 | + const isManualProjectSorting = appSettings.sidebarProjectSortOrder === "manual"; |
| 1090 | + |
| 1091 | + function renderProjectItem( |
| 1092 | + project: (typeof sortedProjects)[number], |
| 1093 | + dragHandleProps: SortableProjectHandleProps | null, |
| 1094 | + ) { |
| 1095 | + const projectThreads = sortThreadsForSidebar( |
| 1096 | + threads.filter((thread) => thread.projectId === project.id), |
| 1097 | + appSettings.sidebarThreadSortOrder, |
| 1098 | + ); |
| 1099 | + const projectStatus = resolveProjectStatusIndicator( |
| 1100 | + projectThreads.map((thread) => |
| 1101 | + resolveThreadStatusPill({ |
| 1102 | + thread, |
| 1103 | + hasPendingApprovals: derivePendingApprovals(thread.activities).length > 0, |
| 1104 | + hasPendingUserInput: derivePendingUserInputs(thread.activities).length > 0, |
| 1105 | + }), |
| 1106 | + ), |
| 1107 | + ); |
| 1108 | + const isThreadListExpanded = expandedThreadListsByProject.has(project.id); |
| 1109 | + const hasHiddenThreads = projectThreads.length > THREAD_PREVIEW_LIMIT; |
| 1110 | + const visibleThreads = |
| 1111 | + hasHiddenThreads && !isThreadListExpanded |
| 1112 | + ? projectThreads.slice(0, THREAD_PREVIEW_LIMIT) |
| 1113 | + : projectThreads; |
| 1114 | + const orderedProjectThreadIds = projectThreads.map((thread) => thread.id); |
| 1115 | + |
| 1116 | + return ( |
| 1117 | + <Collapsible className="group/collapsible" open={project.expanded}> |
| 1118 | + <div className="group/project-header relative"> |
| 1119 | + <SidebarMenuButton |
| 1120 | + ref={isManualProjectSorting ? dragHandleProps?.setActivatorNodeRef : undefined} |
| 1121 | + size="sm" |
| 1122 | + 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 ${ |
| 1123 | + isManualProjectSorting ? "cursor-grab active:cursor-grabbing" : "cursor-pointer" |
| 1124 | + }`} |
| 1125 | + {...(isManualProjectSorting && dragHandleProps ? dragHandleProps.attributes : {})} |
| 1126 | + {...(isManualProjectSorting && dragHandleProps ? dragHandleProps.listeners : {})} |
| 1127 | + onPointerDownCapture={handleProjectTitlePointerDownCapture} |
| 1128 | + onClick={(event) => handleProjectTitleClick(event, project.id)} |
| 1129 | + onKeyDown={(event) => handleProjectTitleKeyDown(event, project.id)} |
| 1130 | + onContextMenu={(event) => { |
| 1131 | + event.preventDefault(); |
| 1132 | + void handleProjectContextMenu(project.id, { |
| 1133 | + x: event.clientX, |
| 1134 | + y: event.clientY, |
| 1135 | + }); |
| 1136 | + }} |
| 1137 | + > |
| 1138 | + {!project.expanded && projectStatus ? ( |
| 1139 | + <span |
| 1140 | + aria-hidden="true" |
| 1141 | + title={projectStatus.label} |
| 1142 | + className={`-ml-0.5 relative inline-flex size-3.5 shrink-0 items-center justify-center ${projectStatus.colorClass}`} |
| 1143 | + > |
| 1144 | + <span className="absolute inset-0 flex items-center justify-center transition-opacity duration-150 group-hover/project-header:opacity-0"> |
| 1145 | + <span |
| 1146 | + className={`size-[9px] rounded-full ${projectStatus.dotClass} ${ |
| 1147 | + projectStatus.pulse ? "animate-pulse" : "" |
| 1148 | + }`} |
| 1149 | + /> |
| 1150 | + </span> |
| 1151 | + <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" /> |
| 1152 | + </span> |
| 1153 | + ) : ( |
| 1154 | + <ChevronRightIcon |
| 1155 | + className={`-ml-0.5 size-3.5 shrink-0 text-muted-foreground/70 transition-transform duration-150 ${ |
| 1156 | + project.expanded ? "rotate-90" : "" |
| 1157 | + }`} |
| 1158 | + /> |
| 1159 | + )} |
| 1160 | + <ProjectFavicon cwd={project.cwd} /> |
| 1161 | + <span className="flex-1 truncate text-xs font-medium text-foreground/90"> |
| 1162 | + {project.name} |
| 1163 | + </span> |
| 1164 | + </SidebarMenuButton> |
| 1165 | + <Tooltip> |
| 1166 | + <TooltipTrigger |
| 1167 | + render={ |
| 1168 | + <SidebarMenuAction |
| 1169 | + render={ |
| 1170 | + <button |
| 1171 | + type="button" |
| 1172 | + aria-label={`Create new thread in ${project.name}`} |
| 1173 | + data-testid="new-thread-button" |
| 1174 | + /> |
| 1175 | + } |
| 1176 | + showOnHover |
| 1177 | + className="top-1 right-1 size-5 rounded-md p-0 text-muted-foreground/70 hover:bg-secondary hover:text-foreground" |
| 1178 | + onClick={(event) => { |
| 1179 | + event.preventDefault(); |
| 1180 | + event.stopPropagation(); |
| 1181 | + void handleNewThread(project.id, { |
| 1182 | + envMode: resolveSidebarNewThreadEnvMode({ |
| 1183 | + defaultEnvMode: appSettings.defaultThreadEnvMode, |
| 1184 | + }), |
| 1185 | + }); |
| 1186 | + }} |
| 1187 | + > |
| 1188 | + <SquarePenIcon className="size-3.5" /> |
| 1189 | + </SidebarMenuAction> |
| 1190 | + } |
| 1191 | + /> |
| 1192 | + <TooltipPopup side="top"> |
| 1193 | + {newThreadShortcutLabel ? `New thread (${newThreadShortcutLabel})` : "New thread"} |
| 1194 | + </TooltipPopup> |
| 1195 | + </Tooltip> |
| 1196 | + </div> |
| 1197 | + |
| 1198 | + <CollapsibleContent keepMounted> |
| 1199 | + <SidebarMenuSub |
| 1200 | + ref={attachThreadListAutoAnimateRef} |
| 1201 | + className="mx-1 my-0 w-full translate-x-0 gap-0.5 px-1.5 py-0" |
| 1202 | + > |
| 1203 | + {visibleThreads.map((thread) => { |
| 1204 | + const isActive = routeThreadId === thread.id; |
| 1205 | + const isSelected = selectedThreadIds.has(thread.id); |
| 1206 | + const isHighlighted = isActive || isSelected; |
| 1207 | + const threadStatus = resolveThreadStatusPill({ |
| 1208 | + thread, |
| 1209 | + hasPendingApprovals: derivePendingApprovals(thread.activities).length > 0, |
| 1210 | + hasPendingUserInput: derivePendingUserInputs(thread.activities).length > 0, |
| 1211 | + }); |
| 1212 | + const prStatus = prStatusIndicator(prByThreadId.get(thread.id) ?? null); |
| 1213 | + const terminalStatus = terminalStatusFromRunningIds( |
| 1214 | + selectThreadTerminalState(terminalStateByThreadId, thread.id).runningTerminalIds, |
| 1215 | + ); |
| 1216 | + |
| 1217 | + return ( |
| 1218 | + <SidebarMenuSubItem key={thread.id} className="w-full" data-thread-item> |
| 1219 | + <SidebarMenuSubButton |
| 1220 | + render={<div role="button" tabIndex={0} />} |
| 1221 | + size="sm" |
| 1222 | + isActive={isActive} |
| 1223 | + className={resolveThreadRowClassName({ |
| 1224 | + isActive, |
| 1225 | + isSelected, |
| 1226 | + })} |
| 1227 | + onClick={(event) => { |
| 1228 | + handleThreadClick(event, thread.id, orderedProjectThreadIds); |
| 1229 | + }} |
| 1230 | + onKeyDown={(event) => { |
| 1231 | + if (event.key !== "Enter" && event.key !== " ") return; |
| 1232 | + event.preventDefault(); |
| 1233 | + if (selectedThreadIds.size > 0) { |
| 1234 | + clearSelection(); |
| 1235 | + } |
| 1236 | + setSelectionAnchor(thread.id); |
| 1237 | + void navigate({ |
| 1238 | + to: "/$threadId", |
| 1239 | + params: { threadId: thread.id }, |
| 1240 | + }); |
| 1241 | + }} |
| 1242 | + onContextMenu={(event) => { |
| 1243 | + event.preventDefault(); |
| 1244 | + if (selectedThreadIds.size > 0 && selectedThreadIds.has(thread.id)) { |
| 1245 | + void handleMultiSelectContextMenu({ |
| 1246 | + x: event.clientX, |
| 1247 | + y: event.clientY, |
| 1248 | + }); |
| 1249 | + } else { |
| 1250 | + if (selectedThreadIds.size > 0) { |
| 1251 | + clearSelection(); |
| 1252 | + } |
| 1253 | + void handleThreadContextMenu(thread.id, { |
| 1254 | + x: event.clientX, |
| 1255 | + y: event.clientY, |
| 1256 | + }); |
| 1257 | + } |
| 1258 | + }} |
| 1259 | + > |
| 1260 | + <div className="flex min-w-0 flex-1 items-center gap-1.5 text-left"> |
| 1261 | + {prStatus && ( |
| 1262 | + <Tooltip> |
| 1263 | + <TooltipTrigger |
| 1264 | + render={ |
| 1265 | + <button |
| 1266 | + type="button" |
| 1267 | + aria-label={prStatus.tooltip} |
| 1268 | + className={`inline-flex items-center justify-center ${prStatus.colorClass} cursor-pointer rounded-sm outline-hidden focus-visible:ring-1 focus-visible:ring-ring`} |
| 1269 | + onClick={(event) => { |
| 1270 | + openPrLink(event, prStatus.url); |
| 1271 | + }} |
| 1272 | + > |
| 1273 | + <GitPullRequestIcon className="size-3" /> |
| 1274 | + </button> |
| 1275 | + } |
| 1276 | + /> |
| 1277 | + <TooltipPopup side="top">{prStatus.tooltip}</TooltipPopup> |
| 1278 | + </Tooltip> |
| 1279 | + )} |
| 1280 | + {threadStatus && ( |
| 1281 | + <span |
| 1282 | + className={`inline-flex items-center gap-1 text-[10px] ${threadStatus.colorClass}`} |
| 1283 | + > |
| 1284 | + <span |
| 1285 | + className={`h-1.5 w-1.5 rounded-full ${threadStatus.dotClass} ${ |
| 1286 | + threadStatus.pulse ? "animate-pulse" : "" |
| 1287 | + }`} |
| 1288 | + /> |
| 1289 | + <span className="hidden md:inline">{threadStatus.label}</span> |
| 1290 | + </span> |
| 1291 | + )} |
| 1292 | + {renamingThreadId === thread.id ? ( |
| 1293 | + <input |
| 1294 | + ref={(el) => { |
| 1295 | + if (el && renamingInputRef.current !== el) { |
| 1296 | + renamingInputRef.current = el; |
| 1297 | + el.focus(); |
| 1298 | + el.select(); |
| 1299 | + } |
| 1300 | + }} |
| 1301 | + className="min-w-0 flex-1 truncate text-xs bg-transparent outline-none border border-ring rounded px-0.5" |
| 1302 | + value={renamingTitle} |
| 1303 | + onChange={(e) => setRenamingTitle(e.target.value)} |
| 1304 | + onKeyDown={(e) => { |
| 1305 | + e.stopPropagation(); |
| 1306 | + if (e.key === "Enter") { |
| 1307 | + e.preventDefault(); |
| 1308 | + renamingCommittedRef.current = true; |
| 1309 | + void commitRename(thread.id, renamingTitle, thread.title); |
| 1310 | + } else if (e.key === "Escape") { |
| 1311 | + e.preventDefault(); |
| 1312 | + renamingCommittedRef.current = true; |
| 1313 | + cancelRename(); |
| 1314 | + } |
| 1315 | + }} |
| 1316 | + onBlur={() => { |
| 1317 | + if (!renamingCommittedRef.current) { |
| 1318 | + void commitRename(thread.id, renamingTitle, thread.title); |
| 1319 | + } |
| 1320 | + }} |
| 1321 | + onClick={(e) => e.stopPropagation()} |
| 1322 | + /> |
| 1323 | + ) : ( |
| 1324 | + <span className="min-w-0 flex-1 truncate text-xs">{thread.title}</span> |
| 1325 | + )} |
| 1326 | + </div> |
| 1327 | + <div className="ml-auto flex shrink-0 items-center gap-1.5"> |
| 1328 | + {terminalStatus && ( |
| 1329 | + <span |
| 1330 | + role="img" |
| 1331 | + aria-label={terminalStatus.label} |
| 1332 | + title={terminalStatus.label} |
| 1333 | + className={`inline-flex items-center justify-center ${terminalStatus.colorClass}`} |
| 1334 | + > |
| 1335 | + <TerminalIcon |
| 1336 | + className={`size-3 ${terminalStatus.pulse ? "animate-pulse" : ""}`} |
| 1337 | + /> |
| 1338 | + </span> |
| 1339 | + )} |
| 1340 | + <span |
| 1341 | + className={`text-[10px] ${ |
| 1342 | + isHighlighted |
| 1343 | + ? "text-foreground/72 dark:text-foreground/82" |
| 1344 | + : "text-muted-foreground/40" |
| 1345 | + }`} |
| 1346 | + > |
| 1347 | + {formatRelativeTime(thread.updatedAt ?? thread.createdAt)} |
| 1348 | + </span> |
| 1349 | + </div> |
| 1350 | + </SidebarMenuSubButton> |
| 1351 | + </SidebarMenuSubItem> |
| 1352 | + ); |
| 1353 | + })} |
| 1354 | + |
| 1355 | + {hasHiddenThreads && !isThreadListExpanded && ( |
| 1356 | + <SidebarMenuSubItem className="w-full"> |
| 1357 | + <SidebarMenuSubButton |
| 1358 | + render={<button type="button" />} |
| 1359 | + data-thread-selection-safe |
| 1360 | + size="sm" |
| 1361 | + 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" |
| 1362 | + onClick={() => { |
| 1363 | + expandThreadListForProject(project.id); |
| 1364 | + }} |
| 1365 | + > |
| 1366 | + <span>Show more</span> |
| 1367 | + </SidebarMenuSubButton> |
| 1368 | + </SidebarMenuSubItem> |
| 1369 | + )} |
| 1370 | + {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 | + collapseThreadListForProject(project.id); |
| 1379 | + }} |
| 1380 | + > |
| 1381 | + <span>Show less</span> |
| 1382 | + </SidebarMenuSubButton> |
| 1383 | + </SidebarMenuSubItem> |
| 1384 | + )} |
| 1385 | + </SidebarMenuSub> |
| 1386 | + </CollapsibleContent> |
| 1387 | + </Collapsible> |
| 1388 | + ); |
| 1389 | + } |
| 1390 | + |
| 958 | 1391 | const handleProjectTitleClick = useCallback( |
| 959 | 1392 | (event: React.MouseEvent<HTMLButtonElement>, projectId: ProjectId) => { |
| 960 | 1393 | if (dragInProgressRef.current) { |
| @@ -1063,12 +1496,9 @@ export default function Sidebar() { · 102 unmodified lines |
| 1063 | 1496 | : shouldHighlightDesktopUpdateError(desktopUpdateState) |
| 1064 | 1497 | ? "text-rose-500 animate-pulse" |
| 1065 | 1498 | : "text-amber-500 animate-pulse"; |
| 1066 | | − const newThreadShortcutLabel = useMemo( |
| 1067 | | − () => |
| 1068 | | − shortcutLabelForCommand(keybindings, "chat.newLocal") ?? |
| 1069 | | − shortcutLabelForCommand(keybindings, "chat.new"), |
| 1070 | | − [keybindings], |
| 1071 | | − ); |
| 1499 | + const newThreadShortcutLabel = |
| 1500 | + shortcutLabelForCommand(keybindings, "chat.newLocal") ?? |
| 1501 | + shortcutLabelForCommand(keybindings, "chat.new"); |
| 1072 | 1502 | |
| 1073 | 1503 | const handleDesktopUpdateButtonClick = useCallback(() => { |
| 1074 | 1504 | const bridge = window.desktopBridge; |
| @@ -1232,28 +1662,40 @@ export default function Sidebar() { · 157 unmodified lines |
| 1232 | 1662 | <span className="text-[10px] font-medium uppercase tracking-wider text-muted-foreground/60"> |
| 1233 | 1663 | Projects |
| 1234 | 1664 | </span> |
| 1235 | | − <Tooltip> |
| 1236 | | − <TooltipTrigger |
| 1237 | | − render={ |
| 1238 | | − <button |
| 1239 | | − type="button" |
| 1240 | | − aria-label={shouldShowProjectPathEntry ? "Cancel add project" : "Add project"} |
| 1241 | | − aria-pressed={shouldShowProjectPathEntry} |
| 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" |
| 1243 | | − onClick={handleStartAddProject} |
| 1665 | + <div className="flex items-center gap-1"> |
| 1666 | + <ProjectSortMenu |
| 1667 | + projectSortOrder={appSettings.sidebarProjectSortOrder} |
| 1668 | + threadSortOrder={appSettings.sidebarThreadSortOrder} |
| 1669 | + onProjectSortOrderChange={(sortOrder) => { |
| 1670 | + updateSettings({ sidebarProjectSortOrder: sortOrder }); |
| 1671 | + }} |
| 1672 | + onThreadSortOrderChange={(sortOrder) => { |
| 1673 | + updateSettings({ sidebarThreadSortOrder: sortOrder }); |
| 1674 | + }} |
| 1675 | + /> |
| 1676 | + <Tooltip> |
| 1677 | + <TooltipTrigger |
| 1678 | + render={ |
| 1679 | + <button |
| 1680 | + type="button" |
| 1681 | + aria-label={shouldShowProjectPathEntry ? "Cancel add project" : "Add project"} |
| 1682 | + aria-pressed={shouldShowProjectPathEntry} |
| 1683 | + 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" |
| 1684 | + onClick={handleStartAddProject} |
| 1685 | + /> |
| 1686 | + } |
| 1687 | + > |
| 1688 | + <PlusIcon |
| 1689 | + className={`size-3.5 transition-transform duration-150 ${ |
| 1690 | + shouldShowProjectPathEntry ? "rotate-45" : "rotate-0" |
| 1691 | + }`} |
| 1244 | 1692 | /> |
| 1245 | | − } |
| 1246 | | − > |
| 1247 | | − <PlusIcon |
| 1248 | | − className={`size-3.5 transition-transform duration-150 ${ |
| 1249 | | − shouldShowProjectPathEntry ? "rotate-45" : "rotate-0" |
| 1250 | | − }`} |
| 1251 | | − /> |
| 1252 | | − </TooltipTrigger> |
| 1253 | | − <TooltipPopup side="right"> |
| 1254 | | − {shouldShowProjectPathEntry ? "Cancel add project" : "Add project"} |
| 1255 | | − </TooltipPopup> |
| 1256 | | − </Tooltip> |
| 1693 | + </TooltipTrigger> |
| 1694 | + <TooltipPopup side="right"> |
| 1695 | + {shouldShowProjectPathEntry ? "Cancel add project" : "Add project"} |
| 1696 | + </TooltipPopup> |
| 1697 | + </Tooltip> |
| 1698 | + </div> |
| 1257 | 1699 | </div> |
| 1258 | 1700 | |
| 1259 | 1701 | {shouldShowProjectPathEntry && ( |
| @@ -1321,352 +1763,37 @@ export default function Sidebar() { · 61 unmodified lines |
| 1321 | 1763 | </div> |
| 1322 | 1764 | )} |
| 1323 | 1765 | |
| 1324 | | − <DndContext |
| 1325 | | − sensors={projectDnDSensors} |
| 1326 | | − collisionDetection={projectCollisionDetection} |
| 1327 | | − modifiers={[restrictToVerticalAxis, restrictToFirstScrollableAncestor]} |
| 1328 | | − onDragStart={handleProjectDragStart} |
| 1329 | | − onDragEnd={handleProjectDragEnd} |
| 1330 | | − onDragCancel={handleProjectDragCancel} |
| 1331 | | − > |
| 1332 | | − <SidebarMenu> |
| 1333 | | − <SortableContext |
| 1334 | | − items={projects.map((project) => project.id)} |
| 1335 | | − strategy={verticalListSortingStrategy} |
| 1336 | | − > |
| 1337 | | − {projects.map((project) => { |
| 1338 | | − const projectThreads = threads |
| 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 ( |
| 1766 | + {isManualProjectSorting ? ( |
| 1767 | + <DndContext |
| 1768 | + sensors={projectDnDSensors} |
| 1769 | + collisionDetection={projectCollisionDetection} |
| 1770 | + modifiers={[restrictToVerticalAxis, restrictToFirstScrollableAncestor]} |
| 1771 | + onDragStart={handleProjectDragStart} |
| 1772 | + onDragEnd={handleProjectDragEnd} |
| 1773 | + onDragCancel={handleProjectDragCancel} |
| 1774 | + > |
| 1775 | + <SidebarMenu> |
| 1776 | + <SortableContext |
| 1777 | + items={sortedProjects.map((project) => project.id)} |
| 1778 | + strategy={verticalListSortingStrategy} |
| 1779 | + > |
| 1780 | + {sortedProjects.map((project) => ( |
| 1364 | 1781 | <SortableProjectItem key={project.id} projectId={project.id}> |
| 1365 | | − {(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 | | − )} |
| 1782 | + {(dragHandleProps) => renderProjectItem(project, dragHandleProps)} |
| 1664 | 1783 | </SortableProjectItem> |
| 1665 | | − ); |
| 1666 | | − })} |
| 1667 | | − </SortableContext> |
| 1784 | + ))} |
| 1785 | + </SortableContext> |
| 1786 | + </SidebarMenu> |
| 1787 | + </DndContext> |
| 1788 | + ) : ( |
| 1789 | + <SidebarMenu ref={attachProjectListAutoAnimateRef}> |
| 1790 | + {sortedProjects.map((project) => ( |
| 1791 | + <SidebarMenuItem key={project.id} className="rounded-md"> |
| 1792 | + {renderProjectItem(project, null)} |
| 1793 | + </SidebarMenuItem> |
| 1794 | + ))} |
| 1668 | 1795 | </SidebarMenu> |
| 1669 | | − </DndContext> |
| 1796 | + )} |
| 1670 | 1797 | |
| 1671 | 1798 | {projects.length === 0 && !shouldShowProjectPathEntry && ( |
| 1672 | 1799 | <div className="px-2 pt-4 text-center text-xs text-muted-foreground/60"> |