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