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

ThreadNavigationSidebar.tsx

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