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