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

ThreadNavigationSidebar.tsx

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