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

ThreadNavigationSidebar.tsx

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