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

ThreadNavigationSidebar.tsx

1,399 lines51.5 KB

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