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

ThreadNavigationSidebar.tsx

1,347 lines49.8 KB

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