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

ThreadNavigationSidebar.tsx

916 lines35.4 KB

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