Open History to see the last commit
1import { useActiveNewTask } from "../../state/active-new-task";
2import { ThreadUndoNotice } from "../home/ThreadUndoNotice";
3import { useAndroidControlSizing } from "../../components/ui/useAndroidControlSizing";
4import {
5 pickableProjectGroups,
6 resolveScratchProjectScopeKey,
7} from "@t3tools/client-runtime/state/project-grouping";
8import {
9 useAppearancePreferences,
10 useAndroidFloatingTabs,
11} from "../settings/appearance/AppearancePreferencesProvider";
12import type {
13 EnvironmentProject,
14 EnvironmentThreadShell,
15} from "@t3tools/client-runtime/state/shell";
16import { threadSearchMatchKey } from "@t3tools/client-runtime/state/thread-search";
17import { AnimatedLegendList } from "@legendapp/list/reanimated";
18import { THREAD_SIDEBAR_ROW_LAYOUT } from "./threadListAnimations";
19import type { MenuAction } from "@react-native-menu/menu";
20import { useAtomValue } from "@effect/atom-react";
21import { useMemo, useRef, useState } from "react";
22import type { LayoutChangeEvent, TextInputInstance } from "react-native";
23import { Platform, StyleSheet, TextInput, View } from "react-native";
24import { GestureDetector, useNativeGesture } from "react-native-gesture-handler";
25import type { SwipeableMethods } from "react-native-gesture-handler/ReanimatedSwipeable";
26import { useEnabledNavigationTabs } from "../workspace/navigation-tabs";
27import { FLOATING_TABS, floatingTabsMetrics } from "../workspace/floating-workspace-tabs";
28import { useSafeAreaInsets } from "react-native-safe-area-context";
29import type { SearchBarCommands } from "react-native-screens";
30
31import { AppText as Text } from "../../components/ui/AppText";
32import { CompactBrandTitle } from "../../components/CompactBrandTitle";
33import { Menu } from "../../components/ui/Menu";
34import { SymbolView } from "../../components/ui/AppSymbol";
35import { NATIVE_LIQUID_GLASS_SUPPORTED } from "../../native/native-glass";
36import { NativeStackScreenOptions } from "../../native/StackHeader";
37import { scopedProjectKey, scopedThreadKey } from "../../lib/scopedEntities";
38import { useProjects, useNavigationThreadShells } from "../../state/entities";
39import { useThreadSearch } from "../../state/queries";
40import { useThreadListV2ShelfPreferences } from "./use-thread-list-v2-shelf-preferences";
41import { useThreadListNow } from "./use-thread-list-now";
42import { usePendingThreadOrder } from "../../state/thread-order";
43import { threadListEnvironmentsAtom } from "../../state/presentation";
44import { usePendingNewTasks, type PendingNewTask } from "../../state/use-pending-new-tasks";
45import { useQueuedThreadKeys } from "../../state/use-thread-outbox";
46import { useWorkspaceState } from "../../state/workspace";
47import { useSavedRemoteConnections } from "../../state/use-remote-environment-registry";
48import { useHardwareKeyboardCommand } from "../keyboard/hardwareKeyboardCommands";
49import { useThreadListV2 } from "./useThreadListV2";
50import { useThreadJumpShortcuts } from "../keyboard/threadKeyboardShortcuts";
51import { requestThreadMessageJump } from "./threadMessageJump";
52import { useThreadListSearchMatches } from "./useThreadListSearchMatches";
53import { useHomeListOptions } from "../home/home-list-options";
54import { buildHomeListFilterMenu } from "../home/home-list-filter-menu";
55import { buildHomeProjectScopes } from "../home/homeThreadList";
56import { SwipeableScrollGateProvider, useSwipeableScrollGate } from "../home/thread-swipe-actions";
57import { usePendingTaskListActions } from "../home/usePendingTaskListActions";
58import { useThreadListActions } from "../home/useThreadListActions";
59import {
60 getConnectionAwareBrandHeaderOptions,
61 WorkspaceConnectionTitle,
62} from "../home/WorkspaceConnectionTitle";
63import { SidebarHeaderActions } from "./sidebar-header-actions";
64import { ThreadListToolbar } from "../home/ThreadListToolbar";
65import { useToolbarLayout } from "../../components/ui/useToolbarLayout";
66import { useFabScroll } from "../home/FabScrollContext";
67import { SidebarFilterButton } from "./sidebar-filter-button";
68import { createSidebarHeaderItems } from "./sidebar-native-header-items";
69import { SidebarNavigationShell } from "./sidebar-navigation-shell";
70import {
71 ThreadListV2PendingRow,
72 ThreadListV2Row,
73 ThreadListV2SettledShelfHeader,
74 ThreadListV2ShowMoreRow,
75 ThreadListV2SnoozedShelfHeader,
76 ThreadListV2WorkingShelfHeader,
77} from "./thread-list-v2-items";
78import { useThreadRowProviderInstanceResolver } from "./thread-provider-instance";
79import type { ThreadPrPresentation } from "../../state/thread-pr-presentation";
80import { ThreadPrDemandProvider } from "../../state/thread-pr-demand";
81import {
82 isThreadListV2ListItem,
83 threadListV2ListItemsAreEqual,
84 THREAD_LIST_V2_SETTLED_INITIAL_COUNT,
85 THREAD_LIST_V2_SETTLED_PAGE_COUNT,
86 type ThreadListV2ListItem,
87} from "./threadListV2";
88import { useSelectWorkspaceDetail } from "../workspace/useSelectWorkspaceDetail";
89import { NativeScrollView } from "../../native/NativeScrollViewMarker";
90
91type SidebarListItem =
92 | ThreadListV2ListItem
93 | {
94 readonly type: "v2-show-more";
95 readonly key: string;
96 readonly hiddenCount: number;
97 readonly state?: "loading" | "failed";
98 };
99
100const SIDEBAR_STICKY_HEADER_HEIGHT = 106;
101
102interface ThreadNavigationSidebarProps {
103 readonly width: number;
104 readonly visible: boolean;
105 readonly selectedThreadKey: string | null;
106 readonly onOpenSettings: () => void;
107 readonly onOpenEnvironmentSettings: () => void;
108 readonly onNewThreadOnBranch: (thread: EnvironmentThreadShell) => void;
109 readonly onNewThreadInProject: (project: EnvironmentProject) => void;
110 readonly onOpenPendingTask: (pendingTask: PendingNewTask) => void;
111 readonly onSearchQueryChange: (query: string) => void;
112 readonly onSelectThread: (thread: EnvironmentThreadShell) => void;
113 readonly onOpenThreadPullRequests: (
114 thread: EnvironmentThreadShell,
115 pr: ThreadPrPresentation,
116 ) => void;
117 readonly onRequestVisibility: () => void;
118 readonly searchQuery: string;
119}
120
121export function ThreadNavigationSidebar(props: ThreadNavigationSidebarProps) {
122 return (
123 <ThreadPrDemandProvider visible={props.visible}>
124 {Platform.OS !== "ios" ? (
125 <ThreadNavigationSidebarPane {...props} nativeChrome={false} />
126 ) : (
127 <NativeSidebarContainer {...props} />
128 )}
129 </ThreadPrDemandProvider>
130 );
131}
132
133function NativeSidebarContainer(props: ThreadNavigationSidebarProps) {
134 return (
135 <View
136 testID="thread-navigation-sidebar"
137 className="flex-1 border-border bg-drawer"
138 style={{ borderRightWidth: StyleSheet.hairlineWidth, width: props.width }}
139 >
140 <SidebarNavigationShell>
141 <ThreadNavigationSidebarPane {...props} nativeChrome />
142 </SidebarNavigationShell>
143 </View>
144 );
145}
146
147function ThreadNavigationSidebarPane(
148 props: ThreadNavigationSidebarProps & { readonly nativeChrome: boolean },
149) {
150 const floatingTabsEnabled = useAndroidFloatingTabs();
151 const { themeVariables: materialTheme } = useAppearancePreferences();
152 const drawerColor = materialTheme["--color-drawer"];
153
154 const insets = useSafeAreaInsets();
155 const { fabClearance, scale, fabSize } = useAndroidControlSizing();
156 const enabledTabs = useEnabledNavigationTabs();
157 const floatingTabs = floatingTabsMetrics(enabledTabs.length + 1, scale, fabSize, props.width);
158 const projects = useProjects();
159 const threads = useNavigationThreadShells();
160 const { environments: workspaceEnvironments, state: catalogState } = useWorkspaceState();
161 const { savedConnectionsById } = useSavedRemoteConnections();
162 const searchInputRef = useRef<TextInputInstance>(null);
163 const searchBarRef = useRef<SearchBarCommands>(null);
164 const openSwipeableRef = useRef<SwipeableMethods | null>(null);
165 const sidebarScrollGesture = useNativeGesture();
166 const {
167 archiveThread,
168 confirmDeleteThread,
169 settleThread,
170 snoozeThread,
171 unsnoozeThread,
172 unsettleThread,
173 pinThread,
174 unpinThread,
175 setThreadAutoSettle,
176 moveThread,
177 renameThread,
178 regenerateThreadTitle,
179 } = useThreadListActions();
180 const pendingTasks = usePendingNewTasks();
181 const activeNewTask = useActiveNewTask();
182 const queuedThreadKeys = useQueuedThreadKeys();
183 const selectDetail = useSelectWorkspaceDetail();
184 const { confirmDeletePendingTask } = usePendingTaskListActions((params) =>
185 selectDetail({ name: "Thread", params }),
186 );
187 const environments = Object.values(savedConnectionsById)
188 .map((connection) => ({
189 environmentId: connection.environmentId,
190 label: connection.environmentLabel,
191 }))
192 .sort((left, right) => left.label.localeCompare(right.label));
193 const availableEnvironmentIds = new Set(
194 environments.map((environment) => environment.environmentId),
195 );
196 const { options, setSelectedEnvironmentId, setSelectedProjectKey } =
197 useHomeListOptions(availableEnvironmentIds);
198 const searchEnvironmentIds =
199 options.selectedEnvironmentId === null
200 ? workspaceEnvironments
201 .filter((environment) => environment.connectionState === "connected")
202 .map((environment) => environment.environmentId)
203 : workspaceEnvironments.some(
204 (environment) =>
205 environment.environmentId === options.selectedEnvironmentId &&
206 environment.connectionState === "connected",
207 )
208 ? [options.selectedEnvironmentId]
209 : [];
210 // A legacy per-environment scratch key resolves here on every render; the stored
211 // value is only rewritten when the user picks a filter.
212 const resolvedProjectKey = resolveScratchProjectScopeKey(options.selectedProjectKey, projects, {
213 sidebarProjectGroupingMode: options.projectGroupingMode,
214 sidebarProjectGroupingOverrides: {},
215 });
216 const projectScopes = useMemo(
217 () =>
218 buildHomeProjectScopes({
219 projects,
220 environmentId: options.selectedEnvironmentId,
221 projectGroupingMode: options.projectGroupingMode,
222 }),
223 [projects, options.selectedEnvironmentId, options.projectGroupingMode],
224 );
225 const projectFilterOptions = pickableProjectGroups(projectScopes).map((scope) => ({
226 key: scope.key,
227 label: scope.title,
228 }));
229 const projectTitleByProjectKey = useMemo(
230 () =>
231 new Map(
232 projectScopes.flatMap((scope) =>
233 scope.projectRefs.map(
234 (projectRef) =>
235 [
236 scopedProjectKey(projectRef.environmentId, projectRef.projectId),
237 scope.title,
238 ] as const,
239 ),
240 ),
241 ),
242 [projectScopes],
243 );
244 // An archived project's filter reads as all projects, matching the filter menu.
245 const selectedProjectScope =
246 pickableProjectGroups(projectScopes).find((scope) => scope.key === resolvedProjectKey) ?? null;
247 const threadSearch = useThreadSearch(
248 searchEnvironmentIds,
249 props.searchQuery,
250 selectedProjectScope === null
251 ? {}
252 : { projectIds: selectedProjectScope.projectRefs.map((ref) => ref.projectId) },
253 );
254 // This map reaches LegendList's extraData, which re-renders every row whenever it changes
255 // identity; the hook keeps it stable.
256 const threadSearchMatchByKey = useThreadListSearchMatches(threads, threadSearch);
257 const selectedProjectKey = selectedProjectScope?.key ?? null;
258 const projectByKey = useMemo(() => {
259 const map = new Map<string, EnvironmentProject>();
260 for (const project of projects) {
261 map.set(scopedProjectKey(project.environmentId, project.id), project);
262 }
263 return map;
264 }, [projects]);
265
266 const [settledVisibleCount, setSettledVisibleCount] = useState(
267 THREAD_LIST_V2_SETTLED_INITIAL_COUNT,
268 );
269 const settledResetKey = `${options.selectedEnvironmentId ?? "all"}:${selectedProjectKey ?? "all"}:${props.searchQuery.trim()}`;
270 const [lastSettledResetKey, setLastSettledResetKey] = useState(settledResetKey);
271 if (lastSettledResetKey !== settledResetKey) {
272 setLastSettledResetKey(settledResetKey);
273 setSettledVisibleCount(THREAD_LIST_V2_SETTLED_INITIAL_COUNT);
274 }
275 const showMoreSettled = () =>
276 setSettledVisibleCount((count) => count + THREAD_LIST_V2_SETTLED_PAGE_COUNT);
277 const {
278 loaded: shelfPreferencesLoaded,
279 settledShelfExpanded,
280 snoozedShelfExpanded,
281 workingShelfEnabled,
282 workingShelfExpanded,
283 toggleSettledShelf,
284 toggleSnoozedShelf,
285 toggleWorkingShelf,
286 } = useThreadListV2ShelfPreferences();
287 const now = useThreadListNow(threads);
288 const listEnvironments = useAtomValue(threadListEnvironmentsAtom);
289 const {
290 providersByEnvironmentId,
291 machineByEnvironmentId,
292 settlementEnvironmentIds,
293 snoozeEnvironmentIds,
294 snoozePresetsByEnvironmentId,
295 pinningEnvironmentIds,
296 autoSettleOptOutEnvironmentIds,
297 pinReorderEnvironmentIds,
298 activeReorderEnvironmentIds,
299 titleRegenerationEnvironmentIds,
300 } = listEnvironments;
301 const resolveProviderInstance = useThreadRowProviderInstanceResolver(providersByEnvironmentId);
302 const pendingOrder = usePendingThreadOrder();
303 const {
304 layout: threadListV2Layout,
305 items: threadListV2Items,
306 contentOnlyThreadKeys,
307 olderSettledShelf,
308 } = useThreadListV2({
309 threads,
310 pendingTasks,
311 environmentId: options.selectedEnvironmentId,
312 projectRefs: selectedProjectScope === null ? null : selectedProjectScope.projectRefs,
313 searchQuery: props.searchQuery,
314 searchMatches: threadSearchMatchByKey,
315 settlementEnvironmentIds,
316 snoozeEnvironmentIds,
317 pinReorderEnvironmentIds,
318 activeReorderEnvironmentIds,
319 queuedThreadKeys,
320 settledLimit: settledVisibleCount,
321 now,
322 pendingOrder,
323 shelfPreferencesLoaded,
324 workingShelfEnabled,
325 workingShelfExpanded,
326 snoozedShelfExpanded,
327 settledShelfExpanded,
328 selectedThreadKey: props.selectedThreadKey ?? null,
329 });
330 const listItems: readonly SidebarListItem[] =
331 settledShelfExpanded && threadListV2Layout.hiddenSettledCount > 0
332 ? [
333 ...threadListV2Items,
334 {
335 type: "v2-show-more",
336 key: "v2-show-more",
337 hiddenCount: threadListV2Layout.hiddenSettledCount,
338 ...(olderSettledShelf.loading
339 ? { state: "loading" as const }
340 : olderSettledShelf.failed
341 ? { state: "failed" as const }
342 : {}),
343 },
344 ]
345 : threadListV2Items;
346 const listMenuActions = [
347 {
348 id: "environment",
349 title: "Environment",
350 subactions: [
351 {
352 id: "environment:all",
353 title: "All environments",
354 subtitle: "Show threads from every environment",
355 state: options.selectedEnvironmentId === null ? "on" : "off",
356 },
357 ...environments.map((environment) => ({
358 id: `environment:${environment.environmentId}`,
359 title: environment.label,
360 state:
361 options.selectedEnvironmentId === environment.environmentId
362 ? ("on" as const)
363 : ("off" as const),
364 })),
365 ],
366 },
367 ...(projectFilterOptions.length === 0
368 ? []
369 : ([
370 {
371 id: "project",
372 title: "Project",
373 subactions: [
374 {
375 id: "project:all",
376 title: "All projects",
377 subtitle: "Show threads from every project",
378 state: selectedProjectKey === null ? "on" : "off",
379 },
380 ...projectFilterOptions.map((project) => ({
381 id: `project:${project.key}`,
382 title: project.label,
383 state: selectedProjectKey === project.key ? ("on" as const) : ("off" as const),
384 })),
385 ],
386 },
387 ] satisfies MenuAction[])),
388 ] satisfies MenuAction[];
389 const handleListMenuAction = ({
390 nativeEvent,
391 }: {
392 readonly nativeEvent: { readonly event: string };
393 }) => {
394 const event = nativeEvent.event;
395 if (event === "environment:all") {
396 setSelectedEnvironmentId(null);
397 return;
398 }
399 if (event.startsWith("environment:")) {
400 const environment = environments.find(
401 (candidate) => String(candidate.environmentId) === event.slice("environment:".length),
402 );
403 if (environment) setSelectedEnvironmentId(environment.environmentId);
404 return;
405 }
406 if (event === "project:all") {
407 setSelectedProjectKey(null);
408 return;
409 }
410 if (event.startsWith("project:")) {
411 const projectKey = event.slice("project:".length);
412 if (projectFilterOptions.some((project) => project.key === projectKey)) {
413 setSelectedProjectKey(projectKey);
414 }
415 return;
416 }
417 };
418
419 const [measuredHeaderHeight, setMeasuredHeaderHeight] = useState<number | null>(null);
420 const { height, paddingTop, paddingBottom } = useToolbarLayout();
421 const stickyHeaderHeight =
422 measuredHeaderHeight ??
423 (Platform.OS === "android"
424 ? paddingTop + height + paddingBottom
425 : insets.top + SIDEBAR_STICKY_HEADER_HEIGHT);
426 const topListInset = stickyHeaderHeight + 6;
427 const handleStickyHeaderLayout = (event: LayoutChangeEvent) => {
428 const nextHeight = event.nativeEvent.layout.height;
429 setMeasuredHeaderHeight((current) => (current === nextHeight ? current : nextHeight));
430 };
431 const handleSwipeableWillOpen = (methods: SwipeableMethods) => {
432 if (openSwipeableRef.current !== methods) {
433 openSwipeableRef.current?.close();
434 openSwipeableRef.current = methods;
435 }
436 };
437 const handleSwipeableClose = (methods: SwipeableMethods) => {
438 if (openSwipeableRef.current === methods) {
439 openSwipeableRef.current = null;
440 }
441 };
442 // Destructure callback props; capturing all props would invalidate these row-closing handlers on unrelated changes.
443 const { onSelectThread, onOpenThreadPullRequests } = props;
444 // A row listed for a message match opens the thread at that message, by
445 // tap or by shortcut.
446 const handleSelectThread = (thread: EnvironmentThreadShell) => {
447 const key = threadSearchMatchKey({ environmentId: thread.environmentId, threadId: thread.id });
448 const messageId = contentOnlyThreadKeys.has(key)
449 ? threadSearchMatchByKey.get(key)?.messageId
450 : undefined;
451 if (messageId) {
452 requestThreadMessageJump(scopedThreadKey(thread.environmentId, thread.id), messageId);
453 }
454 onSelectThread(thread);
455 openSwipeableRef.current?.close();
456 };
457 const handleOpenThreadPullRequests = (
458 thread: EnvironmentThreadShell,
459 pr: ThreadPrPresentation,
460 ) => {
461 onOpenThreadPullRequests(thread, pr);
462 openSwipeableRef.current?.close();
463 };
464 const handleScrollBeginDrag = () => {
465 openSwipeableRef.current?.close();
466 };
467 const onFabScroll = useFabScroll();
468 const { swipeEnabled, scrollGateHandlers } = useSwipeableScrollGate({
469 onScroll: onFabScroll,
470 onScrollBeginDrag: handleScrollBeginDrag,
471 });
472 // Recycle equality needs project/search data for titles and favicons; keep the minute clock on items to limit updates.
473 const listExtraData = {
474 activeNewTask,
475 selectedThreadKey: props.selectedThreadKey ?? "",
476 projectByKey,
477 projectTitleByProjectKey,
478 savedConnectionsById,
479 listEnvironments,
480 threadSearchMatchByKey,
481 workingShelfEnabled,
482 };
483 useThreadJumpShortcuts(listItems, handleSelectThread);
484 const sidebarItemsAreEqual = (previous: SidebarListItem, item: SidebarListItem): boolean => {
485 if (isThreadListV2ListItem(previous) && isThreadListV2ListItem(item)) {
486 return threadListV2ListItemsAreEqual(previous, item);
487 }
488 if (previous.type === "v2-show-more" && item.type === "v2-show-more") {
489 return previous.hiddenCount === item.hiddenCount && previous.state === item.state;
490 }
491 return false;
492 };
493 const focusSearch = () => {
494 if (Platform.OS === "android") return false;
495 const focus = () => {
496 if (props.nativeChrome) {
497 searchBarRef.current?.focus();
498 return;
499 }
500 searchInputRef.current?.focus();
501 };
502 if (!props.visible) {
503 props.onRequestVisibility();
504 setTimeout(focus, 240);
505 } else {
506 focus();
507 }
508 return true;
509 };
510 useHardwareKeyboardCommand("focusSearch", focusSearch);
511 const renderListItem = ({ item }: { readonly item: SidebarListItem }) => {
512 switch (item.type) {
513 case "v2-pending": {
514 const pendingScopeKey = scopedProjectKey(
515 item.pendingTask.environmentId,
516 item.pendingTask.projectId,
517 );
518 return (
519 <ThreadListV2PendingRow
520 pendingTask={item.pendingTask}
521 selected={
522 activeNewTask?.pendingKey === item.pendingTask.key ||
523 (item.pendingTask.kind === "pending" &&
524 scopedThreadKey(
525 item.pendingTask.environmentId,
526 item.pendingTask.message.threadId,
527 ) === props.selectedThreadKey)
528 }
529 project={projectByKey.get(pendingScopeKey) ?? null}
530 projectTitle={projectTitleByProjectKey.get(pendingScopeKey)}
531 environmentLabel={
532 Object.keys(savedConnectionsById).length > 1
533 ? (savedConnectionsById[item.pendingTask.environmentId]?.environmentLabel ?? null)
534 : null
535 }
536 environmentMachine={machineByEnvironmentId.get(item.pendingTask.environmentId)}
537 pane="sidebar"
538 showPendingDivider={item.showPendingDivider}
539 onSelectPendingTask={props.onOpenPendingTask}
540 onDeletePendingTask={confirmDeletePendingTask}
541 fullSwipeWidth={props.width - 20}
542 onSwipeableClose={handleSwipeableClose}
543 onSwipeableWillOpen={handleSwipeableWillOpen}
544 simultaneousSwipeGesture={sidebarScrollGesture}
545 />
546 );
547 }
548 case "v2-thread": {
549 const thread = item.item.thread;
550 const scopeKey = scopedProjectKey(thread.environmentId, thread.projectId);
551 return (
552 <ThreadListV2Row
553 onNewThreadOnBranch={props.onNewThreadOnBranch}
554 thread={thread}
555 variant={item.item.variant}
556 hasQueuedMessages={item.hasQueuedMessages}
557 snoozed={item.item.snoozed}
558 pinned={item.item.pinned}
559 wokeAt={item.item.wokeAt}
560 snoozePresetMinute={item.snoozePresetMinute ?? ""}
561 snoozeWakeLabelText={item.snoozeWakeLabelText}
562 timeLabel={item.timeLabel}
563 project={projectByKey.get(scopeKey) ?? null}
564 providerInstance={resolveProviderInstance(thread)}
565 providers={providersByEnvironmentId.get(thread.environmentId)}
566 environmentLabel={
567 Object.keys(savedConnectionsById).length > 1
568 ? (savedConnectionsById[thread.environmentId]?.environmentLabel ?? null)
569 : null
570 }
571 environmentMachine={machineByEnvironmentId.get(thread.environmentId)}
572 searchMatch={
573 // Only rows listed for their messages show one and open at it.
574 contentOnlyThreadKeys.has(
575 threadSearchMatchKey({ environmentId: thread.environmentId, threadId: thread.id }),
576 )
577 ? threadSearchMatchByKey.get(
578 threadSearchMatchKey({
579 environmentId: thread.environmentId,
580 threadId: thread.id,
581 }),
582 )
583 : undefined
584 }
585 searchQuery={threadSearch.query}
586 pane="sidebar"
587 selected={
588 !activeNewTask &&
589 scopedThreadKey(thread.environmentId, thread.id) === props.selectedThreadKey
590 }
591 fullSwipeWidth={props.width - 20}
592 onSelectThread={handleSelectThread}
593 onOpenThreadPullRequests={handleOpenThreadPullRequests}
594 onDeleteThread={confirmDeleteThread}
595 onArchiveThread={archiveThread}
596 onRenameThread={renameThread}
597 onRegenerateThreadTitle={regenerateThreadTitle}
598 titleRegenerationSupported={titleRegenerationEnvironmentIds.has(thread.environmentId)}
599 settlementSupported={settlementEnvironmentIds.has(thread.environmentId)}
600 onSettleThread={settleThread}
601 snoozeSupported={snoozeEnvironmentIds.has(thread.environmentId)}
602 snoozePresets={snoozePresetsByEnvironmentId.get(thread.environmentId)}
603 pinningSupported={pinningEnvironmentIds.has(thread.environmentId)}
604 autoSettleOptOutSupported={autoSettleOptOutEnvironmentIds.has(thread.environmentId)}
605 reorderSupported={
606 item.item.pinned
607 ? pinReorderEnvironmentIds.has(thread.environmentId)
608 : !workingShelfEnabled && activeReorderEnvironmentIds.has(thread.environmentId)
609 }
610 canMoveUp={item.canMoveUp}
611 canMoveDown={item.canMoveDown}
612 onSnoozeThread={snoozeThread}
613 onUnsnoozeThread={unsnoozeThread}
614 onUnsettleThread={unsettleThread}
615 onPinThread={pinThread}
616 onUnpinThread={unpinThread}
617 onSetThreadAutoSettle={setThreadAutoSettle}
618 onMoveThread={moveThread}
619 onSwipeableClose={handleSwipeableClose}
620 onSwipeableWillOpen={handleSwipeableWillOpen}
621 simultaneousSwipeGesture={sidebarScrollGesture}
622 />
623 );
624 }
625 case "v2-working-shelf":
626 return (
627 <ThreadListV2WorkingShelfHeader
628 count={item.count}
629 disabled={item.disabled}
630 expanded={item.expanded}
631 onToggle={toggleWorkingShelf}
632 pane="sidebar"
633 />
634 );
635 case "v2-snoozed-shelf":
636 return (
637 <ThreadListV2SnoozedShelfHeader
638 count={item.count}
639 disabled={item.disabled}
640 expanded={item.expanded}
641 onToggle={toggleSnoozedShelf}
642 pane="sidebar"
643 />
644 );
645 case "v2-settled-shelf":
646 return (
647 <ThreadListV2SettledShelfHeader
648 count={item.count}
649 disabled={item.disabled}
650 expanded={item.expanded}
651 onToggle={toggleSettledShelf}
652 pane="sidebar"
653 />
654 );
655 case "v2-show-more":
656 return (
657 <ThreadListV2ShowMoreRow
658 pane="sidebar"
659 hiddenCount={item.hiddenCount}
660 {...(item.state === undefined ? {} : { state: item.state })}
661 onPress={() => {
662 olderSettledShelf.retry();
663 showMoreSettled();
664 }}
665 />
666 );
667 }
668 };
669 const filterCustomized = options.selectedEnvironmentId !== null || selectedProjectKey !== null;
670 const filterIcon = filterCustomized
671 ? "line.3.horizontal.decrease.circle.fill"
672 : "line.3.horizontal.decrease.circle";
673 const filterMenu = buildHomeListFilterMenu({
674 environments,
675 projects: projectFilterOptions,
676 selectedEnvironmentId: options.selectedEnvironmentId,
677 selectedProjectKey,
678 onEnvironmentChange: setSelectedEnvironmentId,
679 onProjectChange: setSelectedProjectKey,
680 });
681 const nativeHeaderItems = createSidebarHeaderItems({
682 filterIcon,
683 filterMenu,
684 onOpenSettings: props.onOpenSettings,
685 });
686 const listEmpty = (
687 <Text
688 className={
689 Platform.OS === "android"
690 ? "px-4 py-4 text-center text-sm text-drawer-foreground-muted"
691 : "px-2 py-4 text-sm text-drawer-foreground-muted"
692 }
693 >
694 {catalogState.isLoadingConnections
695 ? "Loading threads…"
696 : Platform.OS === "android" && !catalogState.hasConnections
697 ? "No environments connected"
698 : props.searchQuery.trim().length > 0
699 ? threadSearch.isPending
700 ? "Searching thread messages…"
701 : "No matching threads"
702 : selectedProjectScope !== null
703 ? `No threads in ${selectedProjectScope.title}`
704 : "No threads yet"}
705 </Text>
706 );
707
708 if (props.nativeChrome) {
709 return (
710 <>
711 <NativeStackScreenOptions
712 optionsVersion={[nativeHeaderItems, props.width]}
713 options={{
714 ...getConnectionAwareBrandHeaderOptions({
715 headerWidth: props.width,
716 trailingItemCount: nativeHeaderItems.length,
717 onOpenEnvironments: props.onOpenEnvironmentSettings,
718 fallbackTitleStyle: { fontSize: 18, fontWeight: "800" },
719 }),
720 headerSearchBarOptions: {
721 ref: searchBarRef,
722 autoCapitalize: "none",
723 hideNavigationBar: false,
724 hideWhenScrolling: false,
725 obscureBackground: false,
726 placeholder: "Search",
727 placement: "stacked",
728 onCancelButtonPress: () => {
729 props.onSearchQueryChange("");
730 },
731 onChangeText: (event) => {
732 props.onSearchQueryChange(event.nativeEvent.text);
733 },
734 },
735 unstable_headerRightItems: () => nativeHeaderItems,
736 }}
737 />
738 <View className="flex-1">
739 <SwipeableScrollGateProvider enabled={swipeEnabled}>
740 <GestureDetector gesture={sidebarScrollGesture}>
741 <AnimatedLegendList
742 renderScrollComponent={Platform.OS === "ios" ? NativeScrollView : undefined}
743 itemLayoutAnimation={THREAD_SIDEBAR_ROW_LAYOUT}
744 data={listItems}
745 drawDistance={500}
746 estimatedItemSize={64}
747 extraData={listExtraData}
748 getItemType={(item) => item.type}
749 itemsAreEqual={sidebarItemsAreEqual}
750 keyExtractor={(item) => item.key}
751 renderItem={renderListItem}
752 automaticallyAdjustsScrollIndicatorInsets={NATIVE_LIQUID_GLASS_SUPPORTED}
753 contentInsetAdjustmentBehavior={
754 NATIVE_LIQUID_GLASS_SUPPORTED ? "automatic" : "never"
755 }
756 contentContainerStyle={[
757 styles.threadListContent,
758 Platform.OS === "android" ? { paddingHorizontal: 0 } : null,
759 {
760 paddingBottom: Math.max(insets.bottom, 16) + 16,
761 paddingTop: 6,
762 },
763 ]}
764 keyboardDismissMode="on-drag"
765 keyboardShouldPersistTaps="handled"
766 {...scrollGateHandlers}
767 recycleItems
768 scrollEventThrottle={16}
769 showsVerticalScrollIndicator={false}
770 style={styles.threadList}
771 ListEmptyComponent={listEmpty}
772 />
773 </GestureDetector>
774 </SwipeableScrollGateProvider>
775 <ThreadUndoNotice visible={props.visible} />
776 </View>
777 </>
778 );
779 }
780
781 return (
782 <View
783 testID="thread-navigation-sidebar"
784 className={
785 Platform.OS === "android" ? "flex-1 bg-header" : "flex-1 border-r border-border bg-drawer"
786 }
787 // Android fills its pane, which animates its width while a hinge resizes the split.
788 style={Platform.OS === "android" ? undefined : { width: props.width }}
789 >
790 <View
791 className="flex-1"
792 style={
793 Platform.OS === "android"
794 ? {
795 marginTop: stickyHeaderHeight,
796 marginHorizontal: 4,
797 paddingBottom: insets.bottom,
798 backgroundColor: drawerColor,
799 borderTopLeftRadius: 28,
800 borderTopRightRadius: 28,
801 overflow: "hidden",
802 }
803 : { paddingBottom: insets.bottom }
804 }
805 >
806 {Platform.OS === "android" && listItems.length === 0 ? (
807 <View className="flex-1 items-center justify-center">{listEmpty}</View>
808 ) : (
809 <SwipeableScrollGateProvider enabled={swipeEnabled}>
810 <GestureDetector gesture={sidebarScrollGesture}>
811 {/* oxlint-disable-next-line t3code/require-registered-list-scroll -- Only the non-native workspace layout (Android and the fallback) renders this sidebar, which has no native header to register with. */}
812 <AnimatedLegendList
813 itemLayoutAnimation={THREAD_SIDEBAR_ROW_LAYOUT}
814 data={listItems}
815 drawDistance={500}
816 estimatedItemSize={64}
817 extraData={listExtraData}
818 getItemType={(item) => item.type}
819 itemsAreEqual={sidebarItemsAreEqual}
820 keyExtractor={(item) => item.key}
821 renderItem={renderListItem}
822 contentContainerStyle={[
823 styles.threadListContent,
824 Platform.OS === "android" ? { paddingHorizontal: 0 } : null,
825 {
826 paddingBottom:
827 Platform.OS === "android"
828 ? floatingTabsEnabled
829 ? FLOATING_TABS.bottom +
830 FLOATING_TABS.edge +
831 Math.max(floatingTabs.height, floatingTabs.fabOffset + fabSize)
832 : Math.max(insets.bottom, 16) + fabClearance - insets.bottom
833 : 16 + insets.bottom,
834 paddingTop: Platform.OS === "android" ? 6 : topListInset,
835 },
836 ]}
837 keyboardDismissMode="on-drag"
838 keyboardShouldPersistTaps="handled"
839 {...scrollGateHandlers}
840 recycleItems
841 scrollEventThrottle={16}
842 showsVerticalScrollIndicator={false}
843 style={styles.threadList}
844 ListEmptyComponent={listEmpty}
845 />
846 </GestureDetector>
847 </SwipeableScrollGateProvider>
848 )}
849 </View>
850
851 {Platform.OS === "android" ? (
852 <ThreadListToolbar
853 sidebar
854 onLayout={handleStickyHeaderLayout}
855 searchQuery={props.searchQuery}
856 onSearchQueryChange={props.onSearchQueryChange}
857 filterActions={listMenuActions}
858 filterCustomized={filterCustomized}
859 onFilterAction={handleListMenuAction}
860 onOpenEnvironments={props.onOpenEnvironmentSettings}
861 onRequestVisibility={props.onRequestVisibility}
862 />
863 ) : (
864 <View
865 className="absolute inset-x-0 top-0 z-[4] bg-drawer"
866 collapsable={false}
867 onLayout={handleStickyHeaderLayout}
868 pointerEvents="auto"
869 style={{ paddingTop: insets.top }}
870 >
871 <View className="h-[50px] flex-row items-end gap-0.5 pr-2 pl-5">
872 <WorkspaceConnectionTitle
873 grow
874 onPress={props.onOpenEnvironmentSettings}
875 size="pageTitle"
876 brand={
877 <View className="h-11 flex-1 justify-center">
878 <CompactBrandTitle allowFontScaling={false} />
879 </View>
880 }
881 />
882 <View className="flex-row items-center gap-2.5">
883 <Menu actions={listMenuActions} onPressAction={handleListMenuAction}>
884 <SidebarFilterButton accessibilityLabel="Filter threads" icon={filterIcon} />
885 </Menu>
886 <SidebarHeaderActions onOpenSettings={props.onOpenSettings} />
887 </View>
888 </View>
889
890 <View className="mx-4 mt-[9px] h-[38px] flex-row items-center gap-1.5 rounded-xl bg-sidebar-search pr-2.5 pl-[11px]">
891 <SymbolView
892 name="magnifyingglass"
893 size={15}
894 tintColorClassName="accent-drawer-foreground-muted"
895 type="monochrome"
896 />
897 <TextInput
898 ref={searchInputRef}
899 accessibilityLabel="Search threads"
900 autoCapitalize="none"
901 autoCorrect={false}
902 clearButtonMode="while-editing"
903 onChangeText={props.onSearchQueryChange}
904 placeholder="Search"
905 placeholderTextColorClassName="accent-placeholder"
906 selectionColorClassName={undefined}
907 cursorColorClassName={undefined}
908 selectionHandleColorClassName={undefined}
909 returnKeyType="search"
910 className="h-[34px] flex-1 px-0 py-0 font-sans text-base text-drawer-foreground"
911 value={props.searchQuery}
912 />
913 </View>
914 </View>
915 )}
916 <ThreadUndoNotice visible={props.visible} />
917 </View>
918 );
919}
920
921const styles = StyleSheet.create({
922 threadList: {
923 flex: 1,
924 },
925 threadListContent: {
926 paddingHorizontal: 8,
927 },
928});