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

ThreadNavigationSidebar.tsx

1,361 lines50.2 KB

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