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

ThreadNavigationSidebar.tsx

1,399 lines52.0 KB

1import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
2import { createThreadMovePlanner } from "./threadOrder";
3import type {
4 EnvironmentProject,
5 EnvironmentThreadShell,
6} from "@t3tools/client-runtime/state/shell";
7import {
8 threadSearchMatchKey,
9 type EnvironmentThreadSearchMatch,
10} from "@t3tools/client-runtime/state/thread-search";
11import { LegendList } from "@legendapp/list/react-native";
12import type { MenuAction } from "@react-native-menu/menu";
13import { useAtomValue } from "@effect/atom-react";
14import { type EnvironmentId, resolveEnvironmentMachineKind } from "@t3tools/contracts";
15import { useCallback, useEffect, useMemo, useRef, useState } from "react";
16import type { LayoutChangeEvent } from "react-native";
17import { Platform, Pressable, StyleSheet, TextInput, View } from "react-native";
18import { Gesture, GestureDetector } from "react-native-gesture-handler";
19import type { SwipeableMethods } from "react-native-gesture-handler/ReanimatedSwipeable";
20import { useSafeAreaInsets } from "react-native-safe-area-context";
21import type { SearchBarCommands } from "react-native-screens";
22​
23import { AppText as Text } from "../../components/AppText";
24import { CompactBrandTitle } from "../../components/CompactBrandTitle";
25import { ControlPillMenu } from "../../components/ControlPill";
26import { SymbolView } from "../../components/AppSymbol";
27import { NATIVE_LIQUID_GLASS_SUPPORTED } from "../../native/native-glass";
28import { NativeStackScreenOptions } from "../../native/StackHeader";
29import { scopedProjectKey, scopedThreadKey } from "../../lib/scopedEntities";
30import { useProjects, useThreadShells } from "../../state/entities";
31import { useThreadSearch } from "../../state/queries";
32import { useThreadListV2Enabled } from "./use-thread-list-v2-enabled";
33import { useThreadListV2ShelfPreferences } from "./use-thread-list-v2-shelf-preferences";
34import { usePendingThreadOrder } from "../../state/thread-order";
35import { environmentServerConfigsAtom } from "../../state/server";
36import { usePendingNewTasks } from "../../state/use-pending-new-tasks";
37import { useQueuedThreadKeys } from "../../state/use-thread-outbox";
38import { useWorkspaceState } from "../../state/workspace";
39import { useSavedRemoteConnections } from "../../state/use-remote-environment-registry";
40import { useHardwareKeyboardCommand } from "../keyboard/hardwareKeyboardCommands";
41import { useThreadJumpShortcuts } from "../keyboard/threadKeyboardShortcuts";
42import {
43 hasCustomHomeListOptions,
44 PROJECT_SORT_OPTIONS,
45 THREAD_SORT_OPTIONS,
46 useHomeListOptions,
47} from "../home/home-list-options";
48import { buildHomeListFilterMenu } from "../home/home-list-filter-menu";
49import {
50 buildHomeListLayout,
51 DEFAULT_GROUP_DISPLAY_STATE,
52 EMPTY_HOME_LIST_LAYOUT,
53 homeListItemsAreEqual,
54 nextGroupDisplayState,
55 type HomeGroupDisplayAction,
56 type HomeGroupDisplayState,
57 type HomeListItem,
58} from "../home/homeListItems";
59import { buildHomeProjectScopes, buildHomeThreadGroups } from "../home/homeThreadList";
60import { SwipeableScrollGateProvider, useSwipeableScrollGate } from "../home/thread-swipe-actions";
61import { usePendingTaskListActions } from "../home/usePendingTaskListActions";
62import { useThreadListActions } from "../home/useThreadListActions";
63import {
64 getConnectionAwareBrandHeaderOptions,
65 WorkspaceConnectionTitle,
66} from "../home/WorkspaceConnectionTitle";
67import { SidebarHeaderActions } from "./sidebar-header-actions";
68import { SidebarFilterButton } from "./sidebar-filter-button";
69import { createSidebarHeaderItems } from "./sidebar-native-header-items";
70import { SidebarNavigationShell } from "./sidebar-navigation-shell";
71import {
72 PendingTaskListRow,
73 ThreadListGroupHeader,
74 ThreadListRow,
75 ThreadListShowMoreRow,
76} from "./thread-list-items";
77import {
78 ThreadListV2PendingRow,
79 ThreadListV2Row,
80 ThreadListV2SettledShelfHeader,
81 ThreadListV2SnoozedShelfHeader,
82} from "./thread-list-v2-items";
83import { resolveThreadProviderInstance } from "./thread-provider-instance";
84import {
85 buildThreadListV2Items,
86 getThreadListV2OrderedSection,
87 buildThreadListV2ListItems,
88 THREAD_LIST_V2_SETTLED_INITIAL_COUNT,
89 THREAD_LIST_V2_SETTLED_PAGE_COUNT,
90 type ThreadListV2ListItem,
91} from "./threadListV2";
92​
93/** The sidebar list serves both lists: v1 grouped items or, when the Thread
94 List v2 beta is on, flat v2 rows with queued tasks spliced in, and a settled
95 "Show more" pager. */
96type SidebarListItem =
97 | HomeListItem
98 | ThreadListV2ListItem
99 | { readonly type: "v2-show-more"; readonly key: string; readonly hiddenCount: number };
100​
101const SIDEBAR_STICKY_HEADER_HEIGHT = 106;
102​
103interface ThreadNavigationSidebarProps {
104 readonly width: number;
105 readonly visible: boolean;
106 readonly selectedThreadKey: string | null;
107 readonly onOpenSettings: () => void;
108 readonly onOpenEnvironmentSettings: () => void;
109 readonly onNewThreadOnBranch: (thread: EnvironmentThreadShell) => void;
110 readonly onNewThreadInProject: (project: EnvironmentProject) => void;
111 readonly onSearchQueryChange: (query: string) => void;
112 readonly onSelectThread: (thread: EnvironmentThreadShell) => void;
113 readonly onRequestVisibility: () => void;
114 readonly searchQuery: string;
116​
117/**
118 * iPad/large-width sidebar column.
119 *
120 * On iOS the pane is hosted inside its own navigation-inert single-screen
121 * native stack (SidebarNavigationShell) so the header is a real
122 * UINavigationBar: large title, native bar-button items, and a
123 * UISearchController search field — the same chrome a UISplitViewController
124 * column gets. Other platforms keep the custom header chrome.
125 */
126export function ThreadNavigationSidebar(props: ThreadNavigationSidebarProps) {
127 if (Platform.OS !== "ios") {
128 return <ThreadNavigationSidebarPane {...props} nativeChrome={false} />;
129 }
130 return <NativeSidebarContainer {...props} />;
132​
133function NativeSidebarContainer(props: ThreadNavigationSidebarProps) {
134 return (
135 <View
136 testID="thread-navigation-sidebar"
137 className="flex-1 border-border bg-drawer"
138 style={{ borderRightWidth: StyleSheet.hairlineWidth, width: props.width }}
139 >
140 <SidebarNavigationShell>
141 <ThreadNavigationSidebarPane {...props} nativeChrome />
142 </SidebarNavigationShell>
143 </View>
144 );
146​
147function ThreadNavigationSidebarPane(
148 props: ThreadNavigationSidebarProps & { readonly nativeChrome: boolean },
149) {
150 const { materialYouStyleLayoutActive, themeVariables: materialTheme } =
151 useAppearancePreferences();
152 const screenColor = materialTheme["--color-screen"];
153 const mutedColor = materialTheme["--color-foreground-muted"];
154​
155 const insets = useSafeAreaInsets();
156 const projects = useProjects();
157 const threads = useThreadShells();
158 const { environments: workspaceEnvironments, state: catalogState } = useWorkspaceState();
159 const { savedConnectionsById } = useSavedRemoteConnections();
160 const searchInputRef = useRef<TextInput>(null);
161 const searchBarRef = useRef<SearchBarCommands>(null);
162 const openSwipeableRef = useRef<SwipeableMethods | null>(null);
163 const sidebarScrollGesture = useMemo(() => Gesture.Native(), []);
164 const {
165 archiveThread,
166 confirmDeleteThread,
167 settleThread,
168 snoozeThread,
169 unsnoozeThread,
170 unsettleThread,
171 pinThread,
172 unpinThread,
173 moveThread,
174 renameThread,
175 regenerateThreadTitle,
176 } = useThreadListActions();
177 const threadListV2Enabled = useThreadListV2Enabled();
178 const pendingTasks = usePendingNewTasks();
179 const queuedThreadKeys = useQueuedThreadKeys();
180 const { openPendingTask, confirmDeletePendingTask } = usePendingTaskListActions();
181 const environments = useMemo(
182 () =>
183 Object.values(savedConnectionsById)
184 .map((connection) => ({
185 environmentId: connection.environmentId,
186 label: connection.environmentLabel,
187 }))
188 .sort((left, right) => left.label.localeCompare(right.label)),
189 [savedConnectionsById],
190 );
191 const availableEnvironmentIds = useMemo(
192 () => new Set(environments.map((environment) => environment.environmentId)),
193 [environments],
194 );
195 const { options, setSelectedEnvironmentId, setProjectSortOrder, setThreadSortOrder } =
196 useHomeListOptions(availableEnvironmentIds);
197 const searchEnvironmentIds = useMemo(
198 () =>
199 options.selectedEnvironmentId === null
200 ? workspaceEnvironments
201 .filter((environment) => environment.connectionState === "connected")
202 .map((environment) => environment.environmentId)
203 : workspaceEnvironments.some(
204 (environment) =>
205 environment.environmentId === options.selectedEnvironmentId &&
206 environment.connectionState === "connected",
207 )
208 ? [options.selectedEnvironmentId]
209 : [],
210 [options.selectedEnvironmentId, workspaceEnvironments],
211 );
212 const threadSearch = useThreadSearch(searchEnvironmentIds, props.searchQuery);
213 const threadSearchMatchByKey = useMemo(() => {
214 const matches = new Map<string, EnvironmentThreadSearchMatch>();
215 for (const match of threadSearch.matches) {
216 if (match.source === "user" || match.source === "assistant") {
217 matches.set(threadSearchMatchKey(match), match);
218 }
219 }
220 return matches;
221 }, [threadSearch.matches]);
222 const matchedThreadKeys = useMemo(
223 () => new Set(threadSearch.matches.map(threadSearchMatchKey)),
224 [threadSearch.matches],
225 );
226 const [selectedProjectKey, setSelectedProjectKey] = useState<string | null>(null);
227 const projectScopes = useMemo(
228 () =>
229 buildHomeProjectScopes({
230 projects,
231 environmentId: options.selectedEnvironmentId,
232 projectGroupingMode: options.projectGroupingMode,
233 }),
234 [options.projectGroupingMode, options.selectedEnvironmentId, projects],
235 );
236 const projectFilterOptions = useMemo(
237 () =>
238 projectScopes.map((scope) => ({
239 key: scope.key,
240 label: scope.title,
241 })),
242 [projectScopes],
243 );
244 const projectTitleByProjectKey = useMemo(
245 () =>
246 new Map(
247 projectScopes.flatMap((scope) =>
248 scope.projectRefs.map(
249 (projectRef) =>
250 [
251 scopedProjectKey(projectRef.environmentId, projectRef.projectId),
252 scope.title,
253 ] as const,
254 ),
255 ),
256 ),
257 [projectScopes],
258 );
259 const selectedProjectScope = useMemo(
260 () =>
261 selectedProjectKey === null
262 ? null
263 : (projectScopes.find((scope) => scope.key === selectedProjectKey) ?? null),
264 [projectScopes, selectedProjectKey],
265 );
266 useEffect(() => {
267 if (
268 selectedProjectKey !== null &&
269 !projectFilterOptions.some((project) => project.key === selectedProjectKey)
270 ) {
271 setSelectedProjectKey(null);
272 }
273 }, [projectFilterOptions, selectedProjectKey]);
274 const selectedProjectRefs = useMemo(
275 () =>
276 selectedProjectScope === null
277 ? null
278 : new Set(
279 selectedProjectScope.projectRefs.map((projectRef) =>
280 scopedProjectKey(projectRef.environmentId, projectRef.projectId),
281 ),
282 ),
283 [selectedProjectScope],
284 );
285 const scopedProjects = useMemo(
286 () =>
287 threadListV2Enabled
288 ? []
289 : selectedProjectRefs === null
290 ? projects
291 : projects.filter((project) =>
292 selectedProjectRefs.has(scopedProjectKey(project.environmentId, project.id)),
293 ),
294 [threadListV2Enabled, projects, selectedProjectRefs],
295 );
296 const scopedThreads = useMemo(
297 () =>
298 threadListV2Enabled
299 ? []
300 : selectedProjectRefs === null
301 ? threads
302 : threads.filter((thread) =>
303 selectedProjectRefs.has(scopedProjectKey(thread.environmentId, thread.projectId)),
304 ),
305 [threadListV2Enabled, selectedProjectRefs, threads],
306 );
307 const scopedPendingTasks = useMemo(
308 () =>
309 threadListV2Enabled
310 ? []
311 : selectedProjectRefs === null
312 ? pendingTasks
313 : pendingTasks.filter((pendingTask) =>
314 selectedProjectRefs.has(
315 scopedProjectKey(pendingTask.environmentId, pendingTask.projectId),
316 ),
317 ),
318 [threadListV2Enabled, pendingTasks, selectedProjectRefs],
319 );
320 const groups = useMemo(
321 () =>
322 threadListV2Enabled
323 ? []
324 : buildHomeThreadGroups({
325 projects: scopedProjects,
326 threads: scopedThreads,
327 pendingTasks: scopedPendingTasks,
328 queuedThreadKeys,
329 environmentId: options.selectedEnvironmentId,
330 searchQuery: props.searchQuery,
331 matchedThreadKeys,
332 projectSortOrder: options.projectSortOrder,
333 threadSortOrder: options.threadSortOrder,
334 projectGroupingMode: options.projectGroupingMode,
335 }),
336 [
337 threadListV2Enabled,
338 queuedThreadKeys,
339 matchedThreadKeys,
340 options,
341 props.searchQuery,
342 scopedPendingTasks,
343 scopedProjects,
344 scopedThreads,
345 ],
346 );
347 const [groupDisplayStates, setGroupDisplayStates] = useState<
348 ReadonlyMap<string, HomeGroupDisplayState>
349 >(() => new Map());
350 const updateGroupDisplay = useCallback((key: string, action: HomeGroupDisplayAction) => {
351 setGroupDisplayStates((previous) => {
352 const next = new Map(previous);
353 next.set(
354 key,
355 nextGroupDisplayState(previous.get(key) ?? DEFAULT_GROUP_DISPLAY_STATE, action),
356 );
357 return next;
358 });
359 }, []);
360 const hasSearchQuery = props.searchQuery.trim().length > 0;
361 const listLayout = useMemo(
362 () =>
363 threadListV2Enabled
364 ? EMPTY_HOME_LIST_LAYOUT
365 : buildHomeListLayout({
366 groups,
367 displayStates: groupDisplayStates,
368 showAllThreads: hasSearchQuery,
369 }),
370 [threadListV2Enabled, groups, groupDisplayStates, hasSearchQuery],
371 );
372 const projectByKey = useMemo(() => {
373 const map = new Map<string, EnvironmentProject>();
374 for (const project of projects) {
375 map.set(scopedProjectKey(project.environmentId, project.id), project);
376 }
377 return map;
378 }, [projects]);
379​
380 // Thread List v2 (beta) support — same model as the compact Home list
381 // (HomeScreen.tsx): flat creation-order card block + settled recency tail.
382 // The settled tail renders in pages; expansion resets when the filter
383 // context changes so environment/search flips never inherit a deep page.
384 const [settledVisibleCount, setSettledVisibleCount] = useState(
385 THREAD_LIST_V2_SETTLED_INITIAL_COUNT,
386 );
387 const settledResetKey = `${options.selectedEnvironmentId ?? "all"}:${selectedProjectKey ?? "all"}:${props.searchQuery.trim()}`;
388 const lastSettledResetKeyRef = useRef(settledResetKey);
389 if (lastSettledResetKeyRef.current !== settledResetKey) {
390 lastSettledResetKeyRef.current = settledResetKey;
391 setSettledVisibleCount(THREAD_LIST_V2_SETTLED_INITIAL_COUNT);
392 }
393 const showMoreSettled = useCallback(
394 () => setSettledVisibleCount((count) => count + THREAD_LIST_V2_SETTLED_PAGE_COUNT),
395 [],
396 );
397 const {
398 loaded: shelfPreferencesLoaded,
399 settledShelfExpanded,
400 snoozedShelfExpanded,
401 toggleSettledShelf,
402 toggleSnoozedShelf,
403 } = useThreadListV2ShelfPreferences();
404 // The queued-start and snooze helpers need a clock while the pane stays open.
405 const [nowMinute, setNowMinute] = useState(() => new Date().toISOString().slice(0, 16));
406 // Snooze wake times are second-precise; a counter bumped exactly at the
407 // next wake boundary re-runs the partition with a fresh clock so a woken
408 // thread reappears immediately instead of on the next minute tick.
409 const [snoozeWakeTick, bumpSnoozeWakeTick] = useState(0);
410 useEffect(() => {
411 if (!threadListV2Enabled) return;
412 // Refresh immediately because the mount-time value can be hours old.
413 setNowMinute(new Date().toISOString().slice(0, 16));
414 const id = setInterval(() => setNowMinute(new Date().toISOString().slice(0, 16)), 60_000);
415 return () => clearInterval(id);
416 }, [threadListV2Enabled]);
417 // Threads on servers without the settlement capability never classify as
418 // settled (the user could neither un-settle nor pin them).
419 const serverConfigs = useAtomValue(environmentServerConfigsAtom);
420 const settlementEnvironmentIds = useMemo(() => {
421 const supported = new Set<EnvironmentId>();
422 for (const [environmentId, config] of serverConfigs) {
423 if (config.environment.capabilities.threadSettlement === true) {
424 supported.add(environmentId);
425 }
426 }
427 return supported;
428 }, [serverConfigs]);
429 const snoozeEnvironmentIds = useMemo(() => {
430 const supported = new Set<EnvironmentId>();
431 for (const [environmentId, config] of serverConfigs) {
432 if (config.environment.capabilities.threadSnooze === true) {
433 supported.add(environmentId);
434 }
435 }
436 return supported;
437 }, [serverConfigs]);
438 const pinningEnvironmentIds = useMemo(() => {
439 const supported = new Set<EnvironmentId>();
440 for (const [environmentId, config] of serverConfigs) {
441 if (config.environment.capabilities.threadPinning === true) {
442 supported.add(environmentId);
443 }
444 }
445 return supported;
446 }, [serverConfigs]);
447 const pinReorderEnvironmentIds = useMemo(() => {
448 const supported = new Set<EnvironmentId>();
449 for (const [environmentId, config] of serverConfigs) {
450 if (config.environment.capabilities.threadPinReorder === true) {
451 supported.add(environmentId);
452 }
453 }
454 return supported;
455 }, [serverConfigs]);
456 const activeReorderEnvironmentIds = useMemo(() => {
457 const supported = new Set<EnvironmentId>();
458 for (const [environmentId, config] of serverConfigs) {
459 if (config.environment.capabilities.threadActiveReorder === true) {
460 supported.add(environmentId);
461 }
462 }
463 return supported;
464 }, [serverConfigs]);
465 const titleRegenerationEnvironmentIds = useMemo(() => {
466 const supported = new Set<EnvironmentId>();
467 for (const [environmentId, config] of serverConfigs) {
468 if (config.environment.capabilities.threadTitleRegeneration === true) {
469 supported.add(environmentId);
470 }
471 }
472 return supported;
473 }, [serverConfigs]);
474 const machineByEnvironmentId = useMemo(
475 () =>
476 new Map(
477 [...serverConfigs].map(
478 ([environmentId, config]) =>
479 [environmentId, resolveEnvironmentMachineKind(config)] as const,
480 ),
481 ),
482 [serverConfigs],
483 );
484 const pendingOrder = usePendingThreadOrder(nowMinute, snoozeWakeTick);
485 const threadMovePlanners = useMemo(() => {
486 const sectionPlanner = (section: "pinned" | "active") =>
487 createThreadMovePlanner({
488 allThreads: threads,
489 section,
490 reorderableEnvironmentIds: new Set(
491 [...serverConfigs].flatMap(([id, config]) =>
492 (section === "pinned"
493 ? config.environment.capabilities.threadPinReorder
494 : config.environment.capabilities.threadActiveReorder) === true
495 ? [id]
496 : [],
497 ),
498 ),
499 ordered: getThreadListV2OrderedSection({
500 threads,
501 section,
502 pendingOrder,
503 now: new Date().toISOString(),
504 settlementEnvironmentIds,
505 snoozeEnvironmentIds,
506 queuedThreadKeys,
507 }),
508 });
509 return { pinned: sectionPlanner("pinned"), active: sectionPlanner("active") };
510 }, [
511 serverConfigs,
512 threads,
513 pendingOrder,
514 queuedThreadKeys,
515 settlementEnvironmentIds,
516 snoozeEnvironmentIds,
517 nowMinute,
518 snoozeWakeTick,
519 ]);
520 const threadListV2Layout = useMemo(() => {
521 if (!threadListV2Enabled)
522 return {
523 items: [],
524 hiddenSettledCount: 0,
525 snoozedCount: 0,
526 snoozedShelfHeaderIndex: null,
527 settledCount: 0,
528 settledShelfHeaderIndex: null,
529 nextSnoozeWakeAt: null,
530 };
531 return buildThreadListV2Items({
532 pendingOrder,
533 threads: threads.filter((thread) => thread.archivedAt === null),
534 environmentId: options.selectedEnvironmentId,
535 projectRefs: selectedProjectScope === null ? null : selectedProjectScope.projectRefs,
536 searchQuery: props.searchQuery,
537 matchedThreadKeys,
538 settlementEnvironmentIds,
539 snoozeEnvironmentIds,
540 queuedThreadKeys,
541 settledLimit: settledVisibleCount,
542 now: new Date().toISOString(),
543 snoozedShelfExpanded,
544 settledShelfExpanded,
545 selectedThreadKey: props.selectedThreadKey ?? null,
546 });
547 }, [
548 pendingOrder,
549 queuedThreadKeys,
550 nowMinute,
551 snoozeWakeTick,
552 snoozedShelfExpanded,
553 settledShelfExpanded,
554 props.selectedThreadKey,
555 options.selectedEnvironmentId,
556 props.searchQuery,
557 matchedThreadKeys,
558 settledVisibleCount,
559 settlementEnvironmentIds,
560 snoozeEnvironmentIds,
561 threadListV2Enabled,
562 threads,
563 selectedProjectScope,
564 ]);
565 // Re-partition the moment the earliest snooze expires (clamped to the
566 // signed-32-bit setTimeout range; far-future wakes re-arm at the clamp).
567 const nextSnoozeWakeAt = threadListV2Layout.nextSnoozeWakeAt;
568 useEffect(() => {
569 if (nextSnoozeWakeAt === null) return;
570 const wakeAtMs = Date.parse(nextSnoozeWakeAt);
571 if (Number.isNaN(wakeAtMs)) return;
572 const delayMs = Math.min(Math.max(0, wakeAtMs - Date.now()) + 50, 2_147_483_647);
573 const id = setTimeout(() => bumpSnoozeWakeTick((tick) => tick + 1), delayMs);
574 return () => clearTimeout(id);
575 // snoozeWakeTick must re-arm the timer even when nextSnoozeWakeAt is
576 // unchanged: after a clamped fire (wake beyond the 32-bit setTimeout
577 // range) the boundary string is identical and the chain would die.
578 }, [nextSnoozeWakeAt, snoozeWakeTick]);
579 const listItems = useMemo<readonly SidebarListItem[]>(() => {
580 if (!threadListV2Enabled) return listLayout.items;
581 // Queued offline tasks are not thread shells, so the v2 item builder
582 // never sees them; the shared splice puts them below the active block
583 // (mirrors the compact Home v2 list) where they stay visible and
584 // deletable while their environment is offline. Same environment scope
585 // and search filter as the list.
586 const v2SearchQuery = props.searchQuery.trim().toLocaleLowerCase();
587 const v2PendingTasks = pendingTasks.filter(
588 (pendingTask) =>
589 (options.selectedEnvironmentId === null ||
590 pendingTask.environmentId === options.selectedEnvironmentId) &&
591 (selectedProjectRefs === null ||
592 selectedProjectRefs.has(
593 scopedProjectKey(pendingTask.environmentId, pendingTask.projectId),
594 )) &&
595 (v2SearchQuery.length === 0 ||
596 pendingTask.title.toLocaleLowerCase().includes(v2SearchQuery)),
597 );
598 const items: SidebarListItem[] = buildThreadListV2ListItems({
599 items: threadListV2Layout.items,
600 pendingTasks: v2PendingTasks,
601 snoozedCount: threadListV2Layout.snoozedCount,
602 snoozedShelfExpanded,
603 snoozedShelfHeaderIndex: threadListV2Layout.snoozedShelfHeaderIndex,
604 settledCount: threadListV2Layout.settledCount,
605 settledShelfExpanded,
606 settledShelfHeaderIndex: threadListV2Layout.settledShelfHeaderIndex,
607 snoozeLabelNow: `${nowMinute}:00.000Z`,
608 });
609 if (settledShelfExpanded && threadListV2Layout.hiddenSettledCount > 0) {
610 items.push({
611 type: "v2-show-more",
612 key: "v2-show-more",
613 hiddenCount: threadListV2Layout.hiddenSettledCount,
614 });
615 }
616 return items;
617 }, [
618 listLayout.items,
619 nowMinute,
620 options.selectedEnvironmentId,
621 pendingTasks,
622 props.searchQuery,
623 selectedProjectRefs,
624 settledShelfExpanded,
625 snoozedShelfExpanded,
626 threadListV2Enabled,
627 threadListV2Layout,
628 ]);
629 const listMenuActions = useMemo<MenuAction[]>(
630 () => [
631 {
632 id: "environment",
633 title: "Environment",
634 subactions: [
635 {
636 id: "environment:all",
637 title: "All environments",
638 subtitle: "Show threads from every environment",
639 state: options.selectedEnvironmentId === null ? "on" : "off",
640 },
641 ...environments.map((environment) => ({
642 id: `environment:${environment.environmentId}`,
643 title: environment.label,
644 state:
645 options.selectedEnvironmentId === environment.environmentId
646 ? ("on" as const)
647 : ("off" as const),
648 })),
649 ],
650 },
651 ...(projectFilterOptions.length === 0
652 ? []
653 : ([
654 {
655 id: "project",
656 title: "Project",
657 subactions: [
658 {
659 id: "project:all",
660 title: "All projects",
661 subtitle: "Show threads from every project",
662 state: selectedProjectKey === null ? "on" : "off",
663 },
664 ...projectFilterOptions.map((project) => ({
665 id: `project:${project.key}`,
666 title: project.label,
667 state: selectedProjectKey === project.key ? ("on" as const) : ("off" as const),
668 })),
669 ],
670 },
671 ] satisfies MenuAction[])),
672 // v2 lays the list out in fixed creation order — offering sort/group
673 // controls it silently ignores would be a lie. Environment still
674 // scopes the v2 partition, so it stays.
675 ...(threadListV2Enabled
676 ? []
677 : ([
678 {
679 id: "project-sort",
680 title: "Sort projects",
681 subactions: PROJECT_SORT_OPTIONS.map((option) => ({
682 id: `project-sort:${option.value}`,
683 title: option.label,
684 state: options.projectSortOrder === option.value ? "on" : "off",
685 })),
686 },
687 {
688 id: "thread-sort",
689 title: "Sort threads",
690 subactions: THREAD_SORT_OPTIONS.map((option) => ({
691 id: `thread-sort:${option.value}`,
692 title: option.label,
693 state: options.threadSortOrder === option.value ? "on" : "off",
694 })),
695 },
696 ] satisfies MenuAction[])),
697 ],
698 [environments, options, projectFilterOptions, selectedProjectKey, threadListV2Enabled],
699 );
700 const handleListMenuAction = useCallback(
701 ({ nativeEvent }: { readonly nativeEvent: { readonly event: string } }) => {
702 const event = nativeEvent.event;
703 if (event === "environment:all") {
704 setSelectedEnvironmentId(null);
705 return;
706 }
707 if (event.startsWith("environment:")) {
708 const environment = environments.find(
709 (candidate) => String(candidate.environmentId) === event.slice("environment:".length),
710 );
711 if (environment) setSelectedEnvironmentId(environment.environmentId);
712 return;
713 }
714 if (event === "project:all") {
715 setSelectedProjectKey(null);
716 return;
717 }
718 if (event.startsWith("project:")) {
719 const projectKey = event.slice("project:".length);
720 if (projectFilterOptions.some((project) => project.key === projectKey)) {
721 setSelectedProjectKey(projectKey);
722 }
723 return;
724 }
725 const projectSort = PROJECT_SORT_OPTIONS.find(
726 (option) => `project-sort:${option.value}` === event,
727 );
728 if (projectSort) {
729 setProjectSortOrder(projectSort.value);
730 return;
731 }
732 const threadSort = THREAD_SORT_OPTIONS.find(
733 (option) => `thread-sort:${option.value}` === event,
734 );
735 if (threadSort) {
736 setThreadSortOrder(threadSort.value);
737 return;
738 }
739 },
740 [
741 environments,
742 projectFilterOptions,
743 setProjectSortOrder,
744 setSelectedEnvironmentId,
745 setThreadSortOrder,
746 ],
747 );
748​
749 const [measuredHeaderHeight, setMeasuredHeaderHeight] = useState<number | null>(null);
750 // The sticky header (title row, search field, optional connection status)
751 // is measured so the list inset always matches its real height — no
752 // hardcoded per-variant constants.
753 const stickyHeaderHeight = measuredHeaderHeight ?? insets.top + SIDEBAR_STICKY_HEADER_HEIGHT;
754 const topListInset = stickyHeaderHeight + 6;
755 const handleStickyHeaderLayout = useCallback((event: LayoutChangeEvent) => {
756 const nextHeight = Math.round(event.nativeEvent.layout.height);
757 setMeasuredHeaderHeight((current) => (current === nextHeight ? current : nextHeight));
758 }, []);
759 const handleSwipeableWillOpen = useCallback((methods: SwipeableMethods) => {
760 if (openSwipeableRef.current !== methods) {
761 openSwipeableRef.current?.close();
762 openSwipeableRef.current = methods;
763 }
764 }, []);
765 const handleSwipeableClose = useCallback((methods: SwipeableMethods) => {
766 if (openSwipeableRef.current === methods) {
767 openSwipeableRef.current = null;
768 }
769 }, []);
770 const handleSelectThread = useCallback(
771 (thread: EnvironmentThreadShell) => {
772 props.onSelectThread(thread);
773 openSwipeableRef.current?.close();
774 },
775 [props.onSelectThread],
776 );
777 const handleScrollBeginDrag = useCallback(() => {
778 openSwipeableRef.current?.close();
779 }, []);
780 const { swipeEnabled, scrollGateHandlers } = useSwipeableScrollGate({
781 onScrollBeginDrag: handleScrollBeginDrag,
782 });
783 // Project shells load after the first rows draw, so the maps they feed have
784 // to bust the recycler's memoization — otherwise a row keeps the blank
785 // favicon and fallback title it was first rendered with.
786 const listExtraData = useMemo(
787 () => ({
788 selectedThreadKey: props.selectedThreadKey ?? "",
789 projectByKey,
790 projectTitleByProjectKey,
791 savedConnectionsById,
792 serverConfigs,
793 snoozePresetMinute: nowMinute,
794 threadSearchMatchByKey,
795 }),
796 [
797 props.selectedThreadKey,
798 projectByKey,
799 projectTitleByProjectKey,
800 savedConnectionsById,
801 serverConfigs,
802 nowMinute,
803 threadSearchMatchByKey,
804 ],
805 );
806 useThreadJumpShortcuts(listItems, handleSelectThread);
807 const sidebarItemsAreEqual = useCallback(
808 (previous: SidebarListItem, item: SidebarListItem): boolean => {
809 if (previous.type === "v2-thread" && item.type === "v2-thread") {
810 return (
811 previous.key === item.key &&
812 previous.item.thread === item.item.thread &&
813 previous.item.variant === item.item.variant &&
814 previous.item.snoozed === item.item.snoozed &&
815 previous.item.pinned === item.item.pinned &&
816 previous.snoozeWakeLabelText === item.snoozeWakeLabelText
817 );
818 }
819 if (previous.type === "v2-show-more" && item.type === "v2-show-more") {
820 return previous.hiddenCount === item.hiddenCount;
821 }
822 if (previous.type === "v2-pending" && item.type === "v2-pending") {
823 return (
824 previous.pendingTask === item.pendingTask &&
825 previous.showPendingDivider === item.showPendingDivider
826 );
827 }
828 if (previous.type === "v2-snoozed-shelf" && item.type === "v2-snoozed-shelf") {
829 return previous.count === item.count && previous.expanded === item.expanded;
830 }
831 if (previous.type === "v2-settled-shelf" && item.type === "v2-settled-shelf") {
832 return previous.count === item.count && previous.expanded === item.expanded;
833 }
834 if (
835 previous.type === "v2-thread" ||
836 previous.type === "v2-show-more" ||
837 previous.type === "v2-pending" ||
838 previous.type === "v2-snoozed-shelf" ||
839 previous.type === "v2-settled-shelf" ||
840 item.type === "v2-thread" ||
841 item.type === "v2-show-more" ||
842 item.type === "v2-pending" ||
843 item.type === "v2-snoozed-shelf" ||
844 item.type === "v2-settled-shelf"
845 ) {
846 return false;
847 }
848 return homeListItemsAreEqual(previous, item);
849 },
850 [],
851 );
852 const focusSearch = useCallback(() => {
853 const focus = () => {
854 if (props.nativeChrome) {
855 searchBarRef.current?.focus();
856 return;
857 }
858 searchInputRef.current?.focus();
859 };
860 if (!props.visible) {
861 props.onRequestVisibility();
862 setTimeout(focus, 240);
863 } else {
864 focus();
865 }
866 return true;
867 }, [props.nativeChrome, props.onRequestVisibility, props.visible]);
868 useHardwareKeyboardCommand("focusSearch", focusSearch);
869 const renderListItem = useCallback(
870 ({ item }: { readonly item: SidebarListItem }) => {
871 switch (item.type) {
872 case "v2-pending": {
873 const pendingScopeKey = scopedProjectKey(
874 item.pendingTask.environmentId,
875 item.pendingTask.projectId,
876 );
877 return (
878 <ThreadListV2PendingRow
879 pendingTask={item.pendingTask}
880 project={projectByKey.get(pendingScopeKey) ?? null}
881 projectTitle={projectTitleByProjectKey.get(pendingScopeKey)}
882 environmentLabel={
883 Object.keys(savedConnectionsById).length > 1
884 ? (savedConnectionsById[item.pendingTask.environmentId]?.environmentLabel ?? null)
885 : null
886 }
887 environmentMachine={machineByEnvironmentId.get(item.pendingTask.environmentId)}
888 pane="sidebar"
889 showPendingDivider={item.showPendingDivider}
890 onSelectPendingTask={openPendingTask}
891 onDeletePendingTask={confirmDeletePendingTask}
892 />
893 );
894 }
895 case "v2-thread": {
896 const thread = item.item.thread;
897 const movePlanner = item.item.pinned
898 ? threadMovePlanners.pinned
899 : threadMovePlanners.active;
900 const movedId = `${thread.environmentId}:${thread.id}`;
901 const scopeKey = scopedProjectKey(thread.environmentId, thread.projectId);
902 return (
903 <ThreadListV2Row
904 onNewThreadOnBranch={props.onNewThreadOnBranch}
905 thread={thread}
906 variant={item.item.variant}
907 hasQueuedMessages={queuedThreadKeys.has(`${thread.environmentId}:${thread.id}`)}
908 snoozed={item.item.snoozed}
909 pinned={item.item.pinned}
910 snoozePresetMinute={nowMinute}
911 snoozeWakeLabelText={item.snoozeWakeLabelText}
912 project={projectByKey.get(scopeKey) ?? null}
913 projectTitle={projectTitleByProjectKey.get(scopeKey)}
914 providerInstance={resolveThreadProviderInstance(serverConfigs, thread)}
915 environmentLabel={
916 Object.keys(savedConnectionsById).length > 1
917 ? (savedConnectionsById[thread.environmentId]?.environmentLabel ?? null)
918 : null
919 }
920 environmentMachine={machineByEnvironmentId.get(thread.environmentId)}
921 searchMatch={threadSearchMatchByKey.get(
922 threadSearchMatchKey({
923 environmentId: thread.environmentId,
924 threadId: thread.id,
925 }),
926 )}
927 searchQuery={props.searchQuery}
928 pane={materialYouStyleLayoutActive ? "screen" : "sidebar"}
929 selected={
930 scopedThreadKey(thread.environmentId, thread.id) === props.selectedThreadKey
931 }
932 fullSwipeWidth={props.width - 20}
933 onSelectThread={handleSelectThread}
934 onDeleteThread={confirmDeleteThread}
935 onArchiveThread={archiveThread}
936 onRenameThread={renameThread}
937 onRegenerateThreadTitle={regenerateThreadTitle}
938 titleRegenerationSupported={titleRegenerationEnvironmentIds.has(thread.environmentId)}
939 settlementSupported={settlementEnvironmentIds.has(thread.environmentId)}
940 onSettleThread={settleThread}
941 snoozeSupported={snoozeEnvironmentIds.has(thread.environmentId)}
942 pinningSupported={pinningEnvironmentIds.has(thread.environmentId)}
943 reorderSupported={
944 item.item.pinned
945 ? pinReorderEnvironmentIds.has(thread.environmentId)
946 : activeReorderEnvironmentIds.has(thread.environmentId)
947 }
948 canMoveUp={pendingOrder === null && movePlanner(movedId, "up") !== null}
949 canMoveDown={pendingOrder === null && movePlanner(movedId, "down") !== null}
950 onSnoozeThread={snoozeThread}
951 onUnsnoozeThread={unsnoozeThread}
952 onUnsettleThread={unsettleThread}
953 onPinThread={pinThread}
954 onUnpinThread={unpinThread}
955 onMoveThread={moveThread}
956 onSwipeableClose={handleSwipeableClose}
957 onSwipeableWillOpen={handleSwipeableWillOpen}
958 simultaneousSwipeGesture={sidebarScrollGesture}
959 />
960 );
961 }
962 case "v2-snoozed-shelf":
963 return (
964 <ThreadListV2SnoozedShelfHeader
965 count={item.count}
966 disabled={!shelfPreferencesLoaded}
967 expanded={item.expanded}
968 onToggle={toggleSnoozedShelf}
969 pane={materialYouStyleLayoutActive ? "screen" : "sidebar"}
970 />
971 );
972 case "v2-settled-shelf":
973 return (
974 <ThreadListV2SettledShelfHeader
975 count={item.count}
976 disabled={!shelfPreferencesLoaded}
977 expanded={item.expanded}
978 onToggle={toggleSettledShelf}
979 pane={materialYouStyleLayoutActive ? "screen" : "sidebar"}
980 />
981 );
982 case "v2-show-more":
983 return (
984 <Pressable
985 accessibilityRole="button"
986 accessibilityLabel={`Show ${Math.min(item.hiddenCount, THREAD_LIST_V2_SETTLED_PAGE_COUNT)} more settled threads`}
987 onPress={showMoreSettled}
988 className="mx-4 mt-2 items-center rounded-lg border border-dashed border-border py-2.5"
989 style={({ pressed }) => ({ opacity: pressed ? 0.6 : 1 })}
990 >
991 <Text className="text-xs font-t3-medium text-foreground-muted">
992 Show more ({item.hiddenCount} settled hidden)
993 </Text>
994 </Pressable>
995 );
996 case "header":
997 return (
998 <ThreadListGroupHeader
999 variant={materialYouStyleLayoutActive ? "compact" : "sidebar"}
1000 collapsed={item.collapsed}
1001 isFirst={item.isFirst}
1002 groupKey={item.group.key}
1003 onGroupAction={updateGroupDisplay}
1004 // Same gating as the compact Home list: aggregated groups have no
1005 // single target project, and pending-project groups hold a
1006 // placeholder shell rather than a real project.
1007 newThreadTarget={item.group.newThreadTarget}
1008 onNewThread={props.onNewThreadInProject}
1009 project={item.group.representative}
1010 threadCount={item.group.threads.length + item.group.pendingTasks.length}
1011 title={item.group.title}
1012 />
1013 );
1014 case "pending-task":
1015 return (
1016 <PendingTaskListRow
1017 variant={materialYouStyleLayoutActive ? "compact" : "sidebar"}
1018 pendingTask={item.pendingTask}
1019 environmentLabel={
1020 savedConnectionsById[item.pendingTask.environmentId]?.environmentLabel ?? null
1022 environmentMachine={machineByEnvironmentId.get(item.pendingTask.environmentId)}
1023 isLast={item.isLast}
1024 onSelectPendingTask={openPendingTask}
1025 onDeletePendingTask={confirmDeletePendingTask}
1026 />
1027 );
1028 case "thread": {
1029 const thread = item.thread;
1030 return (
1031 <ThreadListRow
1032 onNewThreadOnBranch={props.onNewThreadOnBranch}
1033 variant="sidebar"
1034 thread={thread}
1035 hasQueuedMessages={queuedThreadKeys.has(`${thread.environmentId}:${thread.id}`)}
1036 environmentLabel={
1037 savedConnectionsById[thread.environmentId]?.environmentLabel ?? null
1039 environmentMachine={machineByEnvironmentId.get(thread.environmentId)}
1040 isLast={item.isLast}
1041 searchMatch={threadSearchMatchByKey.get(
1042 threadSearchMatchKey({
1043 environmentId: thread.environmentId,
1044 threadId: thread.id,
1045 }),
1046 )}
1047 searchQuery={props.searchQuery}
1048 selected={
1049 scopedThreadKey(thread.environmentId, thread.id) === props.selectedThreadKey
1051 fullSwipeWidth={props.width - 20}
1052 onArchiveThread={archiveThread}
1053 onDeleteThread={confirmDeleteThread}
1054 onRenameThread={renameThread}
1055 onRegenerateThreadTitle={regenerateThreadTitle}
1056 titleRegenerationSupported={titleRegenerationEnvironmentIds.has(thread.environmentId)}
1057 onSelectThread={handleSelectThread}
1058 onSwipeableClose={handleSwipeableClose}
1059 onSwipeableWillOpen={handleSwipeableWillOpen}
1060 simultaneousSwipeGesture={sidebarScrollGesture}
1061 />
1062 );
1064 case "show-more":
1065 return (
1066 <ThreadListShowMoreRow
1067 variant={materialYouStyleLayoutActive ? "compact" : "sidebar"}
1068 hiddenCount={item.hiddenCount}
1069 canShowLess={item.canShowLess}
1070 groupKey={item.groupKey}
1071 onGroupAction={updateGroupDisplay}
1072 />
1073 );
1075 },
1077 materialYouStyleLayoutActive,
1078 archiveThread,
1079 activeReorderEnvironmentIds,
1080 threadMovePlanners,
1081 pendingOrder,
1082 queuedThreadKeys,
1083 confirmDeletePendingTask,
1084 confirmDeleteThread,
1085 handleSelectThread,
1086 handleSwipeableClose,
1087 handleSwipeableWillOpen,
1088 machineByEnvironmentId,
1089 moveThread,
1090 openPendingTask,
1091 pinReorderEnvironmentIds,
1092 pinThread,
1093 pinningEnvironmentIds,
1094 projectByKey,
1095 projectTitleByProjectKey,
1096 regenerateThreadTitle,
1097 renameThread,
1098 props.onNewThreadInProject,
1099 props.onNewThreadOnBranch,
1100 props.searchQuery,
1101 props.selectedThreadKey,
1102 props.width,
1103 savedConnectionsById,
1104 serverConfigs,
1105 shelfPreferencesLoaded,
1106 threadSearchMatchByKey,
1107 titleRegenerationEnvironmentIds,
1108 settleThread,
1109 settlementEnvironmentIds,
1110 showMoreSettled,
1111 sidebarScrollGesture,
1112 snoozeEnvironmentIds,
1113 snoozeThread,
1114 nowMinute,
1115 toggleSettledShelf,
1116 toggleSnoozedShelf,
1117 unpinThread,
1118 unsettleThread,
1119 unsnoozeThread,
1120 updateGroupDisplay,
1121 ],
1122 );
1123 // v2 ignores the sort/group options, so only the environment filter can
1124 // light the "customized" state while the beta is on.
1125 const filterCustomized = threadListV2Enabled
1126 ? options.selectedEnvironmentId !== null || selectedProjectKey !== null
1127 : hasCustomHomeListOptions({ ...options, selectedProjectKey });
1128 const filterIcon = filterCustomized
1129 ? "line.3.horizontal.decrease.circle.fill"
1130 : "line.3.horizontal.decrease.circle";
1131 const filterMenu = useMemo(
1132 () =>
1133 buildHomeListFilterMenu({
1134 environments,
1135 projects: projectFilterOptions,
1136 selectedEnvironmentId: options.selectedEnvironmentId,
1137 selectedProjectKey,
1138 projectSortOrder: options.projectSortOrder,
1139 threadSortOrder: options.threadSortOrder,
1140 onEnvironmentChange: setSelectedEnvironmentId,
1141 onProjectChange: setSelectedProjectKey,
1142 onProjectSortOrderChange: setProjectSortOrder,
1143 onThreadSortOrderChange: setThreadSortOrder,
1144 listOrganization: !threadListV2Enabled,
1145 }),
1147 environments,
1148 options,
1149 projectFilterOptions,
1150 selectedProjectKey,
1151 setProjectSortOrder,
1152 setSelectedEnvironmentId,
1153 setThreadSortOrder,
1154 threadListV2Enabled,
1155 ],
1156 );
1157 const nativeHeaderItems = useMemo(
1158 () =>
1159 createSidebarHeaderItems({
1160 filterIcon,
1161 filterMenu,
1162 onOpenSettings: props.onOpenSettings,
1163 }),
1164 [filterIcon, filterMenu, props.onOpenSettings],
1165 );
1166 // Snoozed threads need no special case: the shelf header is a list row
1167 // even while collapsed.
1168 const listEmpty = (
1169 <Text className="px-2 py-4 text-sm text-foreground-muted">
1170 {catalogState.isLoadingConnections
1171 ? "Loading threads…"
1172 : props.searchQuery.trim().length > 0
1173 ? threadSearch.isPending
1174 ? "Searching thread messages…"
1175 : "No matching threads"
1176 : selectedProjectScope !== null
1177 ? `No threads in ${selectedProjectScope.title}`
1178 : "No threads yet"}
1179 </Text>
1180 );
1181​
1182 if (props.nativeChrome) {
1183 return (
1184 <>
1185 <NativeStackScreenOptions
1186 optionsVersion={[nativeHeaderItems, props.width]}
1187 options={{
1188 // Re-applies the shell's static brand slot with the
1189 // connection-status swap so reconnects surface in the header
1190 // instead of shifting the list.
1191 ...getConnectionAwareBrandHeaderOptions({
1192 headerWidth: props.width,
1193 trailingItemCount: nativeHeaderItems.length,
1194 onOpenEnvironments: props.onOpenEnvironmentSettings,
1195 fallbackTitleStyle: { fontSize: 18, fontWeight: "800" },
1196 }),
1197 headerSearchBarOptions: {
1198 ref: searchBarRef,
1199 autoCapitalize: "none",
1200 hideNavigationBar: false,
1201 // Keep the search bar pinned under the title — UIKit's default
1202 // hidesSearchBarWhenScrolling collapses it on scroll.
1203 hideWhenScrolling: false,
1204 obscureBackground: false,
1205 placeholder: "Search",
1206 placement: "stacked",
1207 onCancelButtonPress: () => {
1208 props.onSearchQueryChange("");
1209 },
1210 onChangeText: (event) => {
1211 props.onSearchQueryChange(event.nativeEvent.text);
1212 },
1213 },
1214 unstable_headerRightItems: () => nativeHeaderItems,
1215 }}
1216 />
1217 <View className="flex-1">
1218 <SwipeableScrollGateProvider enabled={swipeEnabled}>
1219 <GestureDetector gesture={sidebarScrollGesture}>
1220 <LegendList
1221 data={listItems}
1222 drawDistance={500}
1223 estimatedItemSize={64}
1224 extraData={listExtraData}
1225 getItemType={(item) => item.type}
1226 itemsAreEqual={sidebarItemsAreEqual}
1227 keyExtractor={(item) => item.key}
1228 renderItem={renderListItem}
1229 automaticallyAdjustsScrollIndicatorInsets={NATIVE_LIQUID_GLASS_SUPPORTED}
1230 contentInsetAdjustmentBehavior={
1231 NATIVE_LIQUID_GLASS_SUPPORTED ? "automatic" : "never"
1233 contentContainerStyle={[
1234 styles.threadListContent,
1235 materialYouStyleLayoutActive ? { paddingHorizontal: 0 } : null,
1237 paddingBottom: Math.max(insets.bottom, 16) + 16,
1238 paddingTop: 6,
1239 },
1240 ]}
1241 keyboardDismissMode="on-drag"
1242 keyboardShouldPersistTaps="handled"
1243 {...scrollGateHandlers}
1244 recycleItems
1245 scrollEventThrottle={16}
1246 showsVerticalScrollIndicator={false}
1247 style={styles.threadList}
1248 ListEmptyComponent={listEmpty}
1249 />
1250 </GestureDetector>
1251 </SwipeableScrollGateProvider>
1252 </View>
1253 </>
1254 );
1256​
1257 return (
1258 <View
1259 testID="thread-navigation-sidebar"
1260 className="flex-1 border-r border-border bg-drawer"
1261 style={{ width: props.width }}
1263 <View
1264 className="flex-1"
1265 style={
1266 materialYouStyleLayoutActive
1267 ? {
1268 marginTop: stickyHeaderHeight,
1269 paddingBottom: insets.bottom,
1270 backgroundColor: screenColor,
1271 borderTopLeftRadius: 28,
1272 borderTopRightRadius: 28,
1273 overflow: "hidden",
1275 : { paddingBottom: insets.bottom }
1278 <SwipeableScrollGateProvider enabled={swipeEnabled}>
1279 <GestureDetector gesture={sidebarScrollGesture}>
1280 <LegendList
1281 data={listItems}
1282 drawDistance={500}
1283 estimatedItemSize={64}
1284 extraData={listExtraData}
1285 getItemType={(item) => item.type}
1286 itemsAreEqual={sidebarItemsAreEqual}
1287 keyExtractor={(item) => item.key}
1288 renderItem={renderListItem}
1289 contentContainerStyle={[
1290 styles.threadListContent,
1291 materialYouStyleLayoutActive ? { paddingHorizontal: 0 } : null,
1293 paddingBottom:
1294 Platform.OS === "android"
1295 ? Math.max(insets.bottom, 16) + 88 - insets.bottom
1296 : 16 + insets.bottom,
1297 paddingTop: materialYouStyleLayoutActive ? 6 : topListInset,
1298 },
1299 ]}
1300 keyboardDismissMode="on-drag"
1301 keyboardShouldPersistTaps="handled"
1302 {...scrollGateHandlers}
1303 recycleItems
1304 scrollEventThrottle={16}
1305 showsVerticalScrollIndicator={false}
1306 style={styles.threadList}
1307 ListEmptyComponent={listEmpty}
1308 />
1309 </GestureDetector>
1310 </SwipeableScrollGateProvider>
1311 </View>
1312​
1313 <View
1314 className="absolute inset-x-0 top-0 z-[4] bg-drawer"
1315 collapsable={false}
1316 onLayout={handleStickyHeaderLayout}
1317 pointerEvents="auto"
1318 style={{ paddingTop: insets.top }}
1320 <View className="h-[50px] flex-row items-end gap-0.5 pr-2 pl-5">
1321 {/* Title slot doubles as the connection status surface: while an
1322 environment reconnects, the brand fades to a status label in
1323 place (no layout shift in the list below). */}
1324 <WorkspaceConnectionTitle
1325 grow
1326 onPress={props.onOpenEnvironmentSettings}
1327 size="pageTitle"
1328 brand={
1329 <View className="h-11 flex-1 justify-center">
1330 <CompactBrandTitle allowFontScaling={false} />
1331 </View>
1333 />
1334 <View className="flex-row items-center gap-2.5">
1335 <ControlPillMenu actions={listMenuActions} onPressAction={handleListMenuAction}>
1336 <SidebarFilterButton accessibilityLabel="Filter and sort threads" icon={filterIcon} />
1337 </ControlPillMenu>
1338 <SidebarHeaderActions onOpenSettings={props.onOpenSettings} />
1339 </View>
1340 </View>
1341​
1342 <View
1343 className={
1344 materialYouStyleLayoutActive
1345 ? "mx-4 mt-[9px] min-h-12 flex-row items-center gap-2.5 rounded-full border border-input-border bg-input px-3.5"
1346 : "mx-4 mt-[9px] h-[38px] flex-row items-center gap-1.5 rounded-xl bg-sidebar-search pr-2.5 pl-[11px]"
1349 <SymbolView
1350 name="magnifyingglass"
1351 size={15}
1352 tintColorClassName={"accent-foreground-muted"}
1353 type="monochrome"
1354 />
1355 <TextInput
1356 ref={searchInputRef}
1357 accessibilityLabel="Search threads"
1358 autoCapitalize="none"
1359 autoCorrect={false}
1360 clearButtonMode={materialYouStyleLayoutActive ? "never" : "while-editing"}
1361 onChangeText={props.onSearchQueryChange}
1362 placeholder="Search"
1363 placeholderTextColorClassName={"accent-placeholder"}
1364 returnKeyType="search"
1365 className={
1366 materialYouStyleLayoutActive
1367 ? "flex-1 px-0 py-2.5 font-sans text-base text-foreground"
1368 : "h-[34px] flex-1 px-0 py-0 font-sans text-base text-foreground"
1370 value={props.searchQuery}
1371 />
1372 {materialYouStyleLayoutActive && props.searchQuery.length > 0 ? (
1373 <Pressable
1374 accessibilityLabel="Clear search"
1375 hitSlop={10}
1376 onPress={() => props.onSearchQueryChange("")}
1378 <SymbolView
1379 name="xmark.circle.fill"
1380 size={17}
1381 tintColor={mutedColor}
1382 type="monochrome"
1383 />
1384 </Pressable>
1385 ) : null}
1386 </View>
1387 </View>
1388 </View>
1389 );
1391​
1392const styles = StyleSheet.create({
1393 threadList: {
1394 flex: 1,
1395 },
1396 threadListContent: {
1397 paddingHorizontal: 8,
1398 },
1399});