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