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

ThreadNavigationSidebar.tsx

918 lines35.6 KB

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