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

ThreadNavigationSidebar.tsx

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