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

ThreadNavigationSidebar.tsx

766 lines29.7 KB

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