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