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

ThreadNavigationSidebar.tsx

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