Open History to see the last commit
1import { useGT, useMessages } from "gt-react-native";
2import { useActiveNewTask } from "../../state/active-new-task";
3import { ThreadUndoNotice } from "../home/ThreadUndoNotice";
4import { useAndroidControlSizing } from "../../components/ui/useAndroidControlSizing";
5import { pickableProjectGroups } from "@t3tools/client-runtime/state/project-grouping";
6import {
7 useAppearancePreferences,
8 useAndroidFloatingTabs,
9} from "../settings/appearance/AppearancePreferencesProvider";
10import type {
11 EnvironmentProject,
12 EnvironmentThreadShell,
13} from "@t3tools/client-runtime/state/shell";
14import { threadSearchMatchKey } from "@t3tools/client-runtime/state/thread-search";
15import type { OpenThread } from "../home/HostPressurePill";
16import { AnimatedLegendList } from "@legendapp/list/reanimated";
17import { THREAD_LIST_ROW_LAYOUT } from "./threadListAnimations";
18import { useAtomValue } from "@effect/atom-react";
19import { use, useMemo, useRef, useState } from "react";
20import { Platform, StyleSheet, View } from "react-native";
21import { GestureDetector, useNativeGesture } from "react-native-gesture-handler";
22import type { SwipeableMethods } from "react-native-gesture-handler/ReanimatedSwipeable";
23import { FLOATING_TABS } from "../layout/workspace/floating-workspace-tabs";
24import { useSafeAreaInsets } from "react-native-safe-area-context";
25
26import { AppText as Text } from "../../components/ui/AppText";
27import { Button } from "../../components/ui/Button";
28import { scopedProjectKey, scopedThreadKey } from "../../lib/scopedEntities";
29import { useProjects } from "../../state/entities";
30import { steadyNavigationThreadShellsAtom } from "../../state/threads";
31import { useThreadSearch } from "../../state/queries";
32import { useThreadListV2ShelfPreferences } from "./use-thread-list-v2-shelf-preferences";
33import { useThreadListNow } from "./use-thread-list-now";
34import { usePendingThreadOrder } from "../../state/thread-order";
35import { threadListEnvironmentsAtom } from "../../state/presentation";
36import { threadRowPermissionsAtom } from "../../state/thread-row-permissions-atom";
37import { DEFAULT_THREAD_ROW_PERMISSIONS } from "../../state/thread-row-permissions";
38import {
39 useLaunchingThreads,
40 usePendingNewTasks,
41 type PendingNewTask,
42} from "../../state/use-pending-new-tasks";
43import { useQueuedThreadKeys } from "../../state/use-thread-outbox";
44import { useWorkspaceState } from "../../state/workspace";
45import { useSavedRemoteConnections } from "../../state/use-remote-environment-registry";
46import { useThreadListV2, useThreadListV2SnoozePresets } from "./useThreadListV2";
47import { useSidebarRowThreadKey } from "./useSidebarRowThreadKey";
48import { useThreadJumpShortcuts } from "../keyboard/threadKeyboardShortcuts";
49import { requestThreadMessageJump } from "./threadMessageJump";
50import { useThreadListSearchMatches } from "./useThreadListSearchMatches";
51import { useHomeListOptions } from "../home/home-list-options";
52import { useAtomValueWhileVisible } from "../home/home-route-visibility";
53import {
54 buildHomeListFilterMenuItems,
55 homeListFilterEnvironments,
56} from "../home/home-list-filter-menu";
57import {
58 buildHomeProjectScopes,
59 resolveHomeProjectFilterScope,
60 sortHomeProjectScopes,
61} from "../home/homeThreadList";
62import { SwipeableScrollGateProvider, useSwipeableScrollGate } from "../home/thread-swipe-actions";
63import { usePendingTaskListActions } from "../home/usePendingTaskListActions";
64import { useThreadListActions } from "../home/useThreadListActions";
65import { useFabScroll } from "../home/FabScrollContext";
66import { WorkspaceListHeader } from "../layout/workspace/WorkspaceListHeader";
67import { WorkspaceSidebarColumn } from "../layout/workspace/WorkspaceSidebarColumn";
68import { useThreadRowLayout } from "./thread-row-layout";
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 "../layout/workspace/useSelectWorkspaceDetail";
88import { NativeScrollView } from "../../native/NativeScrollViewMarker";
89import { NativeWorkspaceTabActivityContext } from "../../native/v5-workspace-context";
90
91type SidebarListItem =
92 | ThreadListV2ListItem
93 | {
94 readonly type: "v2-show-more";
95 readonly key: string;
96 readonly hiddenCount: number;
97 readonly state?: "loading" | "failed";
98 };
99
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 /** Opens a thread by id, such as one named in a warning whose shell is not loaded. */
112 readonly onOpenThread: OpenThread;
113 readonly onOpenThreadPullRequests: (
114 thread: EnvironmentThreadShell,
115 pr: ThreadPrPresentation,
116 ) => void;
117 readonly onRequestVisibility: () => void;
118 readonly searchQuery: string;
119}
120
121export function ThreadNavigationSidebar(props: ThreadNavigationSidebarProps) {
122 return (
123 <ThreadPrDemandProvider visible={props.visible}>
124 <WorkspaceSidebarColumn width={props.width}>
125 <ThreadNavigationSidebarPane {...props} />
126 </WorkspaceSidebarColumn>
127 </ThreadPrDemandProvider>
128 );
129}
130
131function ThreadNavigationSidebarPane(props: ThreadNavigationSidebarProps) {
132 const gt = useGT();
133 const rowLayout = useThreadRowLayout();
134 const messages = useMessages();
135 const floatingTabsEnabled = useAndroidFloatingTabs();
136 const { themeVariables: materialTheme } = useAppearancePreferences();
137 const drawerColor = materialTheme["--color-drawer"];
138
139 const insets = useSafeAreaInsets();
140 const { fabClearance, fabSize } = useAndroidControlSizing();
141 const projects = useProjects();
142 const threads = useAtomValueWhileVisible(
143 steadyNavigationThreadShellsAtom,
144 use(NativeWorkspaceTabActivityContext)?.active ?? true,
145 );
146 const selectedThreadKey = useSidebarRowThreadKey(props.selectedThreadKey);
147 const { environments: workspaceEnvironments, state: catalogState } = useWorkspaceState();
148 const { savedConnectionsById } = useSavedRemoteConnections();
149 const openSwipeableRef = useRef<SwipeableMethods | null>(null);
150 const sidebarScrollGesture = useNativeGesture();
151 const {
152 archiveThread,
153 confirmDeleteThread,
154 settleThread,
155 snoozeThread,
156 unsnoozeThread,
157 unsettleThread,
158 pinThread,
159 unpinThread,
160 setThreadAutoSettle,
161 moveThread,
162 renameThread,
163 regenerateThreadTitle,
164 } = useThreadListActions();
165 const pendingTasks = usePendingNewTasks();
166 const launchingThreads = useLaunchingThreads(threads);
167 const activeNewTask = useActiveNewTask();
168 const queuedThreadKeys = useQueuedThreadKeys();
169 const selectDetail = useSelectWorkspaceDetail();
170 const { confirmDeletePendingTask } = usePendingTaskListActions((params) =>
171 selectDetail({ name: "Thread", params }),
172 );
173 const environments = homeListFilterEnvironments(workspaceEnvironments);
174 const availableEnvironmentIds = new Set(
175 environments.map((environment) => environment.environmentId),
176 );
177 const { options, setSelectedEnvironmentId, setSelectedProjectKey } =
178 useHomeListOptions(availableEnvironmentIds);
179 const searchEnvironmentIds =
180 options.selectedEnvironmentId === null
181 ? workspaceEnvironments
182 .filter((environment) => environment.connectionState === "connected")
183 .map((environment) => environment.environmentId)
184 : workspaceEnvironments.some(
185 (environment) =>
186 environment.environmentId === options.selectedEnvironmentId &&
187 environment.connectionState === "connected",
188 )
189 ? [options.selectedEnvironmentId]
190 : [];
191 const projectScopes = useMemo(
192 () =>
193 buildHomeProjectScopes(
194 {
195 projects,
196 environmentId: options.selectedEnvironmentId,
197 projectGroupingMode: options.projectGroupingMode,
198 },
199 messages,
200 ),
201 [projects, options.selectedEnvironmentId, options.projectGroupingMode, messages],
202 );
203 const projectFilterOptions = pickableProjectGroups(
204 sortHomeProjectScopes({
205 scopes: projectScopes,
206 threads,
207 pendingTasks: [],
208 projectSortOrder: "updated_at",
209 }),
210 ).map((scope) => ({
211 key: scope.key,
212 label: scope.title,
213 }));
214 const projectTitleByProjectKey = useMemo(
215 () =>
216 new Map(
217 projectScopes.flatMap((scope) =>
218 scope.projectRefs.map(
219 (projectRef) =>
220 [
221 scopedProjectKey(projectRef.environmentId, projectRef.projectId),
222 scope.title,
223 ] as const,
224 ),
225 ),
226 ),
227 [projectScopes],
228 );
229 const selectedProjectScope = resolveHomeProjectFilterScope(projectScopes, projects, options);
230 const threadSearch = useThreadSearch(
231 searchEnvironmentIds,
232 props.searchQuery,
233 selectedProjectScope === null
234 ? {}
235 : { projectIds: selectedProjectScope.projectRefs.map((ref) => ref.projectId) },
236 );
237 // This map reaches LegendList's extraData, which re-renders every row whenever it changes
238 // identity; the hook keeps it stable.
239 const threadSearchMatchByKey = useThreadListSearchMatches(threads, threadSearch);
240 const selectedProjectKey = selectedProjectScope?.key ?? null;
241 const projectByKey = useMemo(() => {
242 const map = new Map<string, EnvironmentProject>();
243 for (const project of projects) {
244 map.set(scopedProjectKey(project.environmentId, project.id), project);
245 }
246 return map;
247 }, [projects]);
248
249 const [settledVisibleCount, setSettledVisibleCount] = useState(
250 THREAD_LIST_V2_SETTLED_INITIAL_COUNT,
251 );
252 const settledResetKey = `${options.selectedEnvironmentId ?? "all"}:${selectedProjectKey ?? "all"}:${props.searchQuery.trim()}`;
253 const [lastSettledResetKey, setLastSettledResetKey] = useState(settledResetKey);
254 if (lastSettledResetKey !== settledResetKey) {
255 setLastSettledResetKey(settledResetKey);
256 setSettledVisibleCount(THREAD_LIST_V2_SETTLED_INITIAL_COUNT);
257 }
258 const showMoreSettled = () =>
259 setSettledVisibleCount((count) => count + THREAD_LIST_V2_SETTLED_PAGE_COUNT);
260 const {
261 loaded: shelfPreferencesLoaded,
262 settledShelfExpanded,
263 snoozedShelfExpanded,
264 workingShelfEnabled,
265 workingShelfExpanded,
266 toggleSettledShelf,
267 toggleSnoozedShelf,
268 toggleWorkingShelf,
269 } = useThreadListV2ShelfPreferences();
270 const now = useThreadListNow(threads);
271 const listEnvironments = useAtomValue(threadListEnvironmentsAtom);
272 const rowPermissionsByEnvironmentId = useAtomValue(threadRowPermissionsAtom);
273 const {
274 providersByEnvironmentId,
275 machineByEnvironmentId,
276 settlementEnvironmentIds,
277 snoozeEnvironmentIds,
278 snoozePresetsByEnvironmentId,
279 pinningEnvironmentIds,
280 autoSettleOptOutEnvironmentIds,
281 pinReorderEnvironmentIds,
282 activeReorderEnvironmentIds,
283 titleRegenerationEnvironmentIds,
284 } = listEnvironments;
285 const { locale: snoozeMenuLocale, presetsByEnvironment: resolvedSnoozePresets } =
286 useThreadListV2SnoozePresets(snoozePresetsByEnvironmentId, now);
287 const resolveProviderInstance = useThreadRowProviderInstanceResolver(providersByEnvironmentId);
288 const pendingOrder = usePendingThreadOrder();
289 const {
290 layout: threadListV2Layout,
291 items: threadListV2Items,
292 contentOnlyThreadKeys,
293 olderSettledShelf,
294 } = useThreadListV2({
295 threads: launchingThreads,
296 pendingTasks,
297 environmentId: options.selectedEnvironmentId,
298 projectRefs: selectedProjectScope === null ? null : selectedProjectScope.projectRefs,
299 searchQuery: props.searchQuery,
300 searchMatches: threadSearchMatchByKey,
301 settlementEnvironmentIds,
302 snoozeEnvironmentIds,
303 pinReorderEnvironmentIds,
304 activeReorderEnvironmentIds,
305 queuedThreadKeys,
306 settledLimit: settledVisibleCount,
307 now,
308 pendingOrder,
309 shelfPreferencesLoaded,
310 workingShelfEnabled,
311 workingShelfExpanded,
312 snoozedShelfExpanded,
313 settledShelfExpanded,
314 selectedThreadKey,
315 });
316 const listItems: readonly SidebarListItem[] =
317 settledShelfExpanded && threadListV2Layout.hiddenSettledCount > 0
318 ? [
319 ...threadListV2Items,
320 {
321 type: "v2-show-more",
322 key: "v2-show-more",
323 hiddenCount: threadListV2Layout.hiddenSettledCount,
324 ...(olderSettledShelf.loading
325 ? { state: "loading" as const }
326 : olderSettledShelf.failed
327 ? { state: "failed" as const }
328 : {}),
329 },
330 ]
331 : threadListV2Items;
332
333 const handleSwipeableWillOpen = (methods: SwipeableMethods) => {
334 if (openSwipeableRef.current !== methods) {
335 openSwipeableRef.current?.close();
336 openSwipeableRef.current = methods;
337 }
338 };
339 const handleSwipeableClose = (methods: SwipeableMethods) => {
340 if (openSwipeableRef.current === methods) {
341 openSwipeableRef.current = null;
342 }
343 };
344 // Destructure callback props; capturing all props would invalidate these row-closing handlers on unrelated changes.
345 const { onSelectThread, onOpenThreadPullRequests } = props;
346 // A row listed for a message match opens the thread at that message, by
347 // tap or by shortcut.
348 const handleSelectThread = (thread: EnvironmentThreadShell) => {
349 const key = threadSearchMatchKey({ environmentId: thread.environmentId, threadId: thread.id });
350 const messageId = contentOnlyThreadKeys.has(key)
351 ? threadSearchMatchByKey.get(key)?.messageId
352 : undefined;
353 if (messageId) {
354 requestThreadMessageJump(scopedThreadKey(thread.environmentId, thread.id), messageId);
355 }
356 onSelectThread(thread);
357 openSwipeableRef.current?.close();
358 };
359 const handleOpenThreadPullRequests = (
360 thread: EnvironmentThreadShell,
361 pr: ThreadPrPresentation,
362 ) => {
363 onOpenThreadPullRequests(thread, pr);
364 openSwipeableRef.current?.close();
365 };
366 const handleScrollBeginDrag = () => {
367 openSwipeableRef.current?.close();
368 };
369 const onFabScroll = useFabScroll();
370 const { swipeEnabled, scrollGateHandlers } = useSwipeableScrollGate({
371 onScroll: onFabScroll,
372 onScrollBeginDrag: handleScrollBeginDrag,
373 });
374 // Recycle equality needs project/search data for titles and favicons; keep the minute clock on items to limit updates.
375 const listExtraData = {
376 snoozeMenuLocale,
377 activeNewTask,
378 selectedThreadKey: selectedThreadKey ?? "",
379 projectByKey,
380 projectTitleByProjectKey,
381 savedConnectionsById,
382 listEnvironments,
383 rowPermissionsByEnvironmentId,
384 threadSearchMatchByKey,
385 workingShelfEnabled,
386 rowLayout,
387 };
388 useThreadJumpShortcuts(listItems, handleSelectThread, props.onOpenPendingTask);
389 const sidebarItemsAreEqual = (previous: SidebarListItem, item: SidebarListItem): boolean => {
390 if (isThreadListV2ListItem(previous) && isThreadListV2ListItem(item)) {
391 return threadListV2ListItemsAreEqual(previous, item);
392 }
393 if (previous.type === "v2-show-more" && item.type === "v2-show-more") {
394 return previous.hiddenCount === item.hiddenCount && previous.state === item.state;
395 }
396 return false;
397 };
398 const renderListItem = ({ item }: { readonly item: SidebarListItem }) => {
399 switch (item.type) {
400 case "v2-pending": {
401 const pendingScopeKey = scopedProjectKey(
402 item.pendingTask.environmentId,
403 item.pendingTask.projectId,
404 );
405 return (
406 <ThreadListV2PendingRow
407 pendingTask={item.pendingTask}
408 selected={
409 activeNewTask?.pendingKey === item.pendingTask.key ||
410 (item.pendingTask.kind === "pending" &&
411 scopedThreadKey(
412 item.pendingTask.environmentId,
413 item.pendingTask.message.threadId,
414 ) === selectedThreadKey)
415 }
416 project={projectByKey.get(pendingScopeKey) ?? null}
417 environmentLabel={
418 Object.keys(savedConnectionsById).length > 1
419 ? (savedConnectionsById[item.pendingTask.environmentId]?.environmentLabel ?? null)
420 : null
421 }
422 environmentMachine={machineByEnvironmentId.get(item.pendingTask.environmentId)}
423 pane="sidebar"
424 showPendingDivider={item.showPendingDivider}
425 onSelectPendingTask={props.onOpenPendingTask}
426 onDeletePendingTask={confirmDeletePendingTask}
427 fullSwipeWidth={props.width - 20}
428 onSwipeableClose={handleSwipeableClose}
429 onSwipeableWillOpen={handleSwipeableWillOpen}
430 simultaneousSwipeGesture={sidebarScrollGesture}
431 />
432 );
433 }
434 case "v2-thread": {
435 const thread = item.item.thread;
436 const scopeKey = scopedProjectKey(thread.environmentId, thread.projectId);
437 const rowPermissions =
438 rowPermissionsByEnvironmentId.get(thread.environmentId) ?? DEFAULT_THREAD_ROW_PERMISSIONS;
439 return (
440 <ThreadListV2Row
441 rowLayout={rowLayout}
442 onNewThreadOnBranch={props.onNewThreadOnBranch}
443 thread={thread}
444 variant={item.item.variant}
445 hasQueuedMessages={item.hasQueuedMessages}
446 snoozed={item.item.snoozed}
447 pinned={item.item.pinned}
448 wokeAt={item.item.wokeAt}
449 snoozePresetMinute={item.snoozePresetMinute}
450 resolvedSnoozePresets={
451 item.snoozePresetMinute === undefined
452 ? undefined
453 : resolvedSnoozePresets.get(thread.environmentId)
454 }
455 snoozeWakeLabelText={item.snoozeWakeLabelText}
456 timeLabel={item.timeLabel}
457 project={projectByKey.get(scopeKey) ?? null}
458 providerInstance={resolveProviderInstance(thread)}
459 providers={providersByEnvironmentId.get(thread.environmentId)}
460 environmentLabel={
461 Object.keys(savedConnectionsById).length > 1
462 ? (savedConnectionsById[thread.environmentId]?.environmentLabel ?? null)
463 : null
464 }
465 environmentMachine={machineByEnvironmentId.get(thread.environmentId)}
466 searchMatch={
467 // Only rows listed for their messages show one and open at it.
468 contentOnlyThreadKeys.has(
469 threadSearchMatchKey({ environmentId: thread.environmentId, threadId: thread.id }),
470 )
471 ? threadSearchMatchByKey.get(
472 threadSearchMatchKey({
473 environmentId: thread.environmentId,
474 threadId: thread.id,
475 }),
476 )
477 : undefined
478 }
479 searchQuery={threadSearch.query}
480 pane="sidebar"
481 selected={
482 !activeNewTask &&
483 scopedThreadKey(thread.environmentId, thread.id) === selectedThreadKey
484 }
485 fullSwipeWidth={props.width - 20}
486 onSelectThread={handleSelectThread}
487 onOpenThreadPullRequests={handleOpenThreadPullRequests}
488 onDeleteThread={confirmDeleteThread}
489 onArchiveThread={archiveThread}
490 onRenameThread={renameThread}
491 onRegenerateThreadTitle={regenerateThreadTitle}
492 titleRegenerationSupported={titleRegenerationEnvironmentIds.has(thread.environmentId)}
493 canOperateThread={rowPermissions.canOperateThread}
494 triageOnly={rowPermissions.triageOnly}
495 canShareWithGuest={rowPermissions.canShareWithGuest}
496 canMoveThreads={rowPermissions.canMoveThreads}
497 settlementSupported={settlementEnvironmentIds.has(thread.environmentId)}
498 onSettleThread={settleThread}
499 snoozeSupported={snoozeEnvironmentIds.has(thread.environmentId)}
500 snoozePresets={snoozePresetsByEnvironmentId.get(thread.environmentId)}
501 pinningSupported={pinningEnvironmentIds.has(thread.environmentId)}
502 autoSettleOptOutSupported={autoSettleOptOutEnvironmentIds.has(thread.environmentId)}
503 reorderSupported={
504 item.item.pinned
505 ? pinReorderEnvironmentIds.has(thread.environmentId)
506 : !workingShelfEnabled && activeReorderEnvironmentIds.has(thread.environmentId)
507 }
508 canMoveUp={item.canMoveUp}
509 canMoveDown={item.canMoveDown}
510 onSnoozeThread={snoozeThread}
511 onUnsnoozeThread={unsnoozeThread}
512 onUnsettleThread={unsettleThread}
513 onPinThread={pinThread}
514 onUnpinThread={unpinThread}
515 onSetThreadAutoSettle={setThreadAutoSettle}
516 onMoveThread={moveThread}
517 onSwipeableClose={handleSwipeableClose}
518 onSwipeableWillOpen={handleSwipeableWillOpen}
519 simultaneousSwipeGesture={sidebarScrollGesture}
520 />
521 );
522 }
523 case "v2-working-shelf":
524 return (
525 <ThreadListV2WorkingShelfHeader
526 count={item.count}
527 disabled={item.disabled}
528 expanded={item.expanded}
529 onToggle={toggleWorkingShelf}
530 pane="sidebar"
531 />
532 );
533 case "v2-snoozed-shelf":
534 return (
535 <ThreadListV2SnoozedShelfHeader
536 count={item.count}
537 disabled={item.disabled}
538 expanded={item.expanded}
539 onToggle={toggleSnoozedShelf}
540 pane="sidebar"
541 />
542 );
543 case "v2-settled-shelf":
544 return (
545 <ThreadListV2SettledShelfHeader
546 count={item.count}
547 disabled={item.disabled}
548 expanded={item.expanded}
549 onToggle={toggleSettledShelf}
550 pane="sidebar"
551 />
552 );
553 case "v2-show-more":
554 return (
555 <ThreadListV2ShowMoreRow
556 pane="sidebar"
557 hiddenCount={item.hiddenCount}
558 {...(item.state === undefined ? {} : { state: item.state })}
559 onPress={() => {
560 olderSettledShelf.retry();
561 showMoreSettled();
562 }}
563 />
564 );
565 }
566 };
567 const header = (
568 <WorkspaceListHeader
569 accessibilityLabel={gt("{appName}, Threads", { appName: "T3 Code" })}
570 onOpenEnvironments={props.onOpenEnvironmentSettings}
571 onOpenSettings={props.onOpenSettings}
572 search={{
573 value: props.searchQuery,
574 onChangeText: props.onSearchQueryChange,
575 placeholder: gt("Search", { $context: "search field placeholder" }),
576 accessibilityLabel: gt("Search threads"),
577 }}
578 filter={{
579 customized: options.selectedEnvironmentId !== null || selectedProjectKey !== null,
580 items: buildHomeListFilterMenuItems(
581 {
582 environments,
583 projects: projectFilterOptions,
584 selectedEnvironmentId: options.selectedEnvironmentId,
585 selectedProjectKey,
586 onEnvironmentChange: setSelectedEnvironmentId,
587 onProjectChange: setSelectedProjectKey,
588 },
589 messages,
590 ),
591 }}
592 sidebar={{
593 width: props.width,
594 visible: props.visible,
595 onRequestVisibility: props.onRequestVisibility,
596 }}
597 />
598 );
599 const showAddEnvironment =
600 !catalogState.isLoadingConnections &&
601 !catalogState.hasReadyEnvironment &&
602 !catalogState.hasConnectingEnvironment;
603 const listEmpty = (
604 <View>
605 <Text
606 className={
607 Platform.OS === "android"
608 ? "px-4 py-4 text-center text-sm text-drawer-foreground-muted"
609 : "px-2 py-4 text-sm text-drawer-foreground-muted"
610 }
611 >
612 {catalogState.isLoadingConnections
613 ? gt("Loading threads…")
614 : showAddEnvironment
615 ? gt("No environments connected")
616 : props.searchQuery.trim().length > 0
617 ? threadSearch.isPending
618 ? gt("Searching thread messages…")
619 : threadSearch.failed
620 ? gt("Couldn't search thread messages")
621 : gt("No matching threads")
622 : selectedProjectScope !== null
623 ? gt("No threads in {project}", { project: selectedProjectScope.title })
624 : gt("No threads yet")}
625 </Text>
626 {showAddEnvironment ? (
627 <View className={Platform.OS === "android" ? "self-center" : "px-2"}>
628 <Button
629 tone="primary"
630 size="compact"
631 icon="plus"
632 label={gt("Add environment")}
633 onPress={props.onOpenEnvironmentSettings}
634 />
635 </View>
636 ) : null}
637 </View>
638 );
639
640 if (Platform.OS === "ios") {
641 return (
642 <>
643 {header}
644 <View className="flex-1">
645 <SwipeableScrollGateProvider enabled={swipeEnabled}>
646 <GestureDetector gesture={sidebarScrollGesture}>
647 <AnimatedLegendList
648 renderScrollComponent={NativeScrollView}
649 itemLayoutAnimation={THREAD_LIST_ROW_LAYOUT}
650 data={listItems}
651 drawDistance={500}
652 estimatedItemSize={64}
653 extraData={listExtraData}
654 getItemType={(item) => item.type}
655 itemsAreEqual={sidebarItemsAreEqual}
656 keyExtractor={(item) => item.key}
657 renderItem={renderListItem}
658 automaticallyAdjustsScrollIndicatorInsets
659 // The column lays the list under its bar, glass or solid; UIKit insets it past both.
660 contentInsetAdjustmentBehavior="automatic"
661 contentContainerStyle={[
662 styles.threadListContent,
663 {
664 paddingBottom: Math.max(insets.bottom, 16) + 16,
665 paddingTop: 6,
666 },
667 ]}
668 keyboardDismissMode="on-drag"
669 keyboardShouldPersistTaps="handled"
670 {...scrollGateHandlers}
671 recycleItems
672 scrollEventThrottle={16}
673 showsVerticalScrollIndicator={false}
674 style={styles.threadList}
675 ListEmptyComponent={listEmpty}
676 />
677 </GestureDetector>
678 </SwipeableScrollGateProvider>
679 <ThreadUndoNotice visible={props.visible} onOpenThread={props.onOpenThread} />
680 </View>
681 </>
682 );
683 }
684
685 // Android: the bar floats below the list.
686 return (
687 <View testID="thread-navigation-sidebar" className="flex-1 bg-header">
688 <View
689 className="flex-1"
690 style={{
691 marginHorizontal: 4,
692 paddingBottom: insets.bottom,
693 backgroundColor: drawerColor,
694 borderTopLeftRadius: 28,
695 borderTopRightRadius: 28,
696 overflow: "hidden",
697 }}
698 >
699 {listItems.length === 0 ? (
700 <View className="flex-1 items-center justify-center">{listEmpty}</View>
701 ) : (
702 <SwipeableScrollGateProvider enabled={swipeEnabled}>
703 <GestureDetector gesture={sidebarScrollGesture}>
704 {/* oxlint-disable-next-line t3code/require-registered-list-scroll -- The Android sidebar has no native header to register with. */}
705 <AnimatedLegendList
706 itemLayoutAnimation={THREAD_LIST_ROW_LAYOUT}
707 data={listItems}
708 drawDistance={500}
709 estimatedItemSize={64}
710 extraData={listExtraData}
711 getItemType={(item) => item.type}
712 itemsAreEqual={sidebarItemsAreEqual}
713 keyExtractor={(item) => item.key}
714 renderItem={renderListItem}
715 contentContainerStyle={{
716 paddingBottom: floatingTabsEnabled
717 ? FLOATING_TABS.bottom + FLOATING_TABS.edge + fabSize
718 : Math.max(insets.bottom, 16) + fabClearance - insets.bottom,
719 paddingTop: 6,
720 }}
721 keyboardDismissMode="on-drag"
722 keyboardShouldPersistTaps="handled"
723 {...scrollGateHandlers}
724 recycleItems
725 scrollEventThrottle={16}
726 showsVerticalScrollIndicator={false}
727 style={styles.threadList}
728 ListEmptyComponent={listEmpty}
729 />
730 </GestureDetector>
731 </SwipeableScrollGateProvider>
732 )}
733 </View>
734 {header}
735 <ThreadUndoNotice visible={props.visible} onOpenThread={props.onOpenThread} />
736 </View>
737 );
738}
739
740const styles = StyleSheet.create({
741 threadList: {
742 flex: 1,
743 },
744 threadListContent: {
745 paddingHorizontal: 8,
746 },
747});