Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ThreadNavigationSidebar.tsx

923 lines35.5 KB

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