The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { useGT, useMessages } from "gt-react-native"; |
| 2 | import { useActiveNewTask } from "../../state/active-new-task"; |
| 3 | import { ThreadUndoNotice } from "../home/ThreadUndoNotice"; |
| 4 | import { useAndroidControlSizing } from "../../components/ui/useAndroidControlSizing"; |
| 5 | import { pickableProjectGroups } from "@t3tools/client-runtime/state/project-grouping"; |
| 6 | import { |
| 7 | useAppearancePreferences, |
| 8 | useAndroidFloatingTabs, |
| 9 | } from "../settings/appearance/AppearancePreferencesProvider"; |
| 10 | import type { |
| 11 | EnvironmentProject, |
| 12 | EnvironmentThreadShell, |
| 13 | } from "@t3tools/client-runtime/state/shell"; |
| 14 | import { threadSearchMatchKey } from "@t3tools/client-runtime/state/thread-search"; |
| 15 | import { AnimatedLegendList } from "@legendapp/list/reanimated"; |
| 16 | import { THREAD_LIST_ROW_LAYOUT } from "./threadListAnimations"; |
| 17 | import { useAtomValue } from "@effect/atom-react"; |
| 18 | import { useMemo, useRef, useState } from "react"; |
| 19 | import { Platform, StyleSheet, View } from "react-native"; |
| 20 | import { GestureDetector, useNativeGesture } from "react-native-gesture-handler"; |
| 21 | import type { SwipeableMethods } from "react-native-gesture-handler/ReanimatedSwipeable"; |
| 22 | import { FLOATING_TABS } from "../layout/workspace/floating-workspace-tabs"; |
| 23 | import { useSafeAreaInsets } from "react-native-safe-area-context"; |
| 24 | |
| 25 | import { AppText as Text } from "../../components/ui/AppText"; |
| 26 | import { Button } from "../../components/ui/Button"; |
| 27 | import { scopedProjectKey, scopedThreadKey } from "../../lib/scopedEntities"; |
| 28 | import { useProjects } from "../../state/entities"; |
| 29 | import { steadyNavigationThreadShellsAtom } from "../../state/threads"; |
| 30 | import { useThreadSearch } from "../../state/queries"; |
| 31 | import { useThreadListV2ShelfPreferences } from "./use-thread-list-v2-shelf-preferences"; |
| 32 | import { useThreadListNow } from "./use-thread-list-now"; |
| 33 | import { usePendingThreadOrder } from "../../state/thread-order"; |
| 34 | import { threadListEnvironmentsAtom } from "../../state/presentation"; |
| 35 | import { |
| 36 | useLaunchingThreads, |
| 37 | usePendingNewTasks, |
| 38 | type PendingNewTask, |
| 39 | } from "../../state/use-pending-new-tasks"; |
| 40 | import { useQueuedThreadKeys } from "../../state/use-thread-outbox"; |
| 41 | import { useWorkspaceState } from "../../state/workspace"; |
| 42 | import { useSavedRemoteConnections } from "../../state/use-remote-environment-registry"; |
| 43 | import { useThreadListV2 } from "./useThreadListV2"; |
| 44 | import { useSidebarRowThreadKey } from "./useSidebarRowThreadKey"; |
| 45 | import { useThreadJumpShortcuts } from "../keyboard/threadKeyboardShortcuts"; |
| 46 | import { requestThreadMessageJump } from "./threadMessageJump"; |
| 47 | import { useThreadListSearchMatches } from "./useThreadListSearchMatches"; |
| 48 | import { useHomeListOptions } from "../home/home-list-options"; |
| 49 | import { |
| 50 | buildHomeListFilterMenuItems, |
| 51 | homeListFilterEnvironments, |
| 52 | } from "../home/home-list-filter-menu"; |
| 53 | import { |
| 54 | buildHomeProjectScopes, |
| 55 | resolveHomeProjectFilterScope, |
| 56 | sortHomeProjectScopes, |
| 57 | } from "../home/homeThreadList"; |
| 58 | import { SwipeableScrollGateProvider, useSwipeableScrollGate } from "../home/thread-swipe-actions"; |
| 59 | import { usePendingTaskListActions } from "../home/usePendingTaskListActions"; |
| 60 | import { useThreadListActions } from "../home/useThreadListActions"; |
| 61 | import { useFabScroll } from "../home/FabScrollContext"; |
| 62 | import { WorkspaceListHeader } from "../layout/workspace/WorkspaceListHeader"; |
| 63 | import { WorkspaceSidebarColumn } from "../layout/workspace/WorkspaceSidebarColumn"; |
| 64 | import { |
| 65 | ThreadListV2PendingRow, |
| 66 | ThreadListV2Row, |
| 67 | ThreadListV2SettledShelfHeader, |
| 68 | ThreadListV2ShowMoreRow, |
| 69 | ThreadListV2SnoozedShelfHeader, |
| 70 | ThreadListV2WorkingShelfHeader, |
| 71 | } from "./thread-list-v2-items"; |
| 72 | import { useThreadRowProviderInstanceResolver } from "./thread-provider-instance"; |
| 73 | import type { ThreadPrPresentation } from "../../state/thread-pr-presentation"; |
| 74 | import { ThreadPrDemandProvider } from "../../state/thread-pr-demand"; |
| 75 | import { |
| 76 | isThreadListV2ListItem, |
| 77 | threadListV2ListItemsAreEqual, |
| 78 | THREAD_LIST_V2_SETTLED_INITIAL_COUNT, |
| 79 | THREAD_LIST_V2_SETTLED_PAGE_COUNT, |
| 80 | type ThreadListV2ListItem, |
| 81 | } from "./threadListV2"; |
| 82 | import { useSelectWorkspaceDetail } from "../layout/workspace/useSelectWorkspaceDetail"; |
| 83 | import { NativeScrollView } from "../../native/NativeScrollViewMarker"; |
| 84 | |
| 85 | type SidebarListItem = |
| 86 | | ThreadListV2ListItem |
| 87 | | { |
| 88 | readonly type: "v2-show-more"; |
| 89 | readonly key: string; |
| 90 | readonly hiddenCount: number; |
| 91 | readonly state?: "loading" | "failed"; |
| 92 | }; |
| 93 | |
| 94 | interface ThreadNavigationSidebarProps { |
| 95 | readonly width: number; |
| 96 | readonly visible: boolean; |
| 97 | readonly selectedThreadKey: string | null; |
| 98 | readonly onOpenSettings: () => void; |
| 99 | readonly onOpenEnvironmentSettings: () => void; |
| 100 | readonly onNewThreadOnBranch: (thread: EnvironmentThreadShell) => void; |
| 101 | readonly onNewThreadInProject: (project: EnvironmentProject) => void; |
| 102 | readonly onOpenPendingTask: (pendingTask: PendingNewTask) => void; |
| 103 | readonly onSearchQueryChange: (query: string) => void; |
| 104 | readonly onSelectThread: (thread: EnvironmentThreadShell) => void; |
| 105 | readonly onOpenThreadPullRequests: ( |
| 106 | thread: EnvironmentThreadShell, |
| 107 | pr: ThreadPrPresentation, |
| 108 | ) => void; |
| 109 | readonly onRequestVisibility: () => void; |
| 110 | readonly searchQuery: string; |
| 111 | } |
| 112 | |
| 113 | export function ThreadNavigationSidebar(props: ThreadNavigationSidebarProps) { |
| 114 | return ( |
| 115 | <ThreadPrDemandProvider visible={props.visible}> |
| 116 | <WorkspaceSidebarColumn width={props.width}> |
| 117 | <ThreadNavigationSidebarPane {...props} /> |
| 118 | </WorkspaceSidebarColumn> |
| 119 | </ThreadPrDemandProvider> |
| 120 | ); |
| 121 | } |
| 122 | |
| 123 | function ThreadNavigationSidebarPane(props: ThreadNavigationSidebarProps) { |
| 124 | const gt = useGT(); |
| 125 | const messages = useMessages(); |
| 126 | const floatingTabsEnabled = useAndroidFloatingTabs(); |
| 127 | const { themeVariables: materialTheme } = useAppearancePreferences(); |
| 128 | const drawerColor = materialTheme["--color-drawer"]; |
| 129 | |
| 130 | const insets = useSafeAreaInsets(); |
| 131 | const { fabClearance, fabSize } = useAndroidControlSizing(); |
| 132 | const projects = useProjects(); |
| 133 | const threads = useAtomValue(steadyNavigationThreadShellsAtom); |
| 134 | const selectedThreadKey = useSidebarRowThreadKey(props.selectedThreadKey); |
| 135 | const { environments: workspaceEnvironments, state: catalogState } = useWorkspaceState(); |
| 136 | const { savedConnectionsById } = useSavedRemoteConnections(); |
| 137 | const openSwipeableRef = useRef<SwipeableMethods | null>(null); |
| 138 | const sidebarScrollGesture = useNativeGesture(); |
| 139 | const { |
| 140 | archiveThread, |
| 141 | confirmDeleteThread, |
| 142 | settleThread, |
| 143 | snoozeThread, |
| 144 | unsnoozeThread, |
| 145 | unsettleThread, |
| 146 | pinThread, |
| 147 | unpinThread, |
| 148 | setThreadAutoSettle, |
| 149 | moveThread, |
| 150 | renameThread, |
| 151 | regenerateThreadTitle, |
| 152 | } = useThreadListActions(); |
| 153 | const pendingTasks = usePendingNewTasks(); |
| 154 | const launchingThreads = useLaunchingThreads(threads); |
| 155 | const activeNewTask = useActiveNewTask(); |
| 156 | const queuedThreadKeys = useQueuedThreadKeys(); |
| 157 | const selectDetail = useSelectWorkspaceDetail(); |
| 158 | const { confirmDeletePendingTask } = usePendingTaskListActions((params) => |
| 159 | selectDetail({ name: "Thread", params }), |
| 160 | ); |
| 161 | const environments = homeListFilterEnvironments(workspaceEnvironments); |
| 162 | const availableEnvironmentIds = new Set( |
| 163 | environments.map((environment) => environment.environmentId), |
| 164 | ); |
| 165 | const { options, setSelectedEnvironmentId, setSelectedProjectKey } = |
| 166 | useHomeListOptions(availableEnvironmentIds); |
| 167 | const searchEnvironmentIds = |
| 168 | options.selectedEnvironmentId === null |
| 169 | ? workspaceEnvironments |
| 170 | .filter((environment) => environment.connectionState === "connected") |
| 171 | .map((environment) => environment.environmentId) |
| 172 | : workspaceEnvironments.some( |
| 173 | (environment) => |
| 174 | environment.environmentId === options.selectedEnvironmentId && |
| 175 | environment.connectionState === "connected", |
| 176 | ) |
| 177 | ? [options.selectedEnvironmentId] |
| 178 | : []; |
| 179 | const projectScopes = useMemo( |
| 180 | () => |
| 181 | buildHomeProjectScopes( |
| 182 | { |
| 183 | projects, |
| 184 | environmentId: options.selectedEnvironmentId, |
| 185 | projectGroupingMode: options.projectGroupingMode, |
| 186 | }, |
| 187 | messages, |
| 188 | ), |
| 189 | [projects, options.selectedEnvironmentId, options.projectGroupingMode, messages], |
| 190 | ); |
| 191 | const projectFilterOptions = pickableProjectGroups( |
| 192 | sortHomeProjectScopes({ |
| 193 | scopes: projectScopes, |
| 194 | threads, |
| 195 | pendingTasks: [], |
| 196 | projectSortOrder: "updated_at", |
| 197 | }), |
| 198 | ).map((scope) => ({ |
| 199 | key: scope.key, |
| 200 | label: scope.title, |
| 201 | })); |
| 202 | const projectTitleByProjectKey = useMemo( |
| 203 | () => |
| 204 | new Map( |
| 205 | projectScopes.flatMap((scope) => |
| 206 | scope.projectRefs.map( |
| 207 | (projectRef) => |
| 208 | [ |
| 209 | scopedProjectKey(projectRef.environmentId, projectRef.projectId), |
| 210 | scope.title, |
| 211 | ] as const, |
| 212 | ), |
| 213 | ), |
| 214 | ), |
| 215 | [projectScopes], |
| 216 | ); |
| 217 | const selectedProjectScope = resolveHomeProjectFilterScope(projectScopes, projects, options); |
| 218 | const threadSearch = useThreadSearch( |
| 219 | searchEnvironmentIds, |
| 220 | props.searchQuery, |
| 221 | selectedProjectScope === null |
| 222 | ? {} |
| 223 | : { projectIds: selectedProjectScope.projectRefs.map((ref) => ref.projectId) }, |
| 224 | ); |
| 225 | // This map reaches LegendList's extraData, which re-renders every row whenever it changes |
| 226 | // identity; the hook keeps it stable. |
| 227 | const threadSearchMatchByKey = useThreadListSearchMatches(threads, threadSearch); |
| 228 | const selectedProjectKey = selectedProjectScope?.key ?? null; |
| 229 | const projectByKey = useMemo(() => { |
| 230 | const map = new Map<string, EnvironmentProject>(); |
| 231 | for (const project of projects) { |
| 232 | map.set(scopedProjectKey(project.environmentId, project.id), project); |
| 233 | } |
| 234 | return map; |
| 235 | }, [projects]); |
| 236 | |
| 237 | const [settledVisibleCount, setSettledVisibleCount] = useState( |
| 238 | THREAD_LIST_V2_SETTLED_INITIAL_COUNT, |
| 239 | ); |
| 240 | const settledResetKey = `${options.selectedEnvironmentId ?? "all"}:${selectedProjectKey ?? "all"}:${props.searchQuery.trim()}`; |
| 241 | const [lastSettledResetKey, setLastSettledResetKey] = useState(settledResetKey); |
| 242 | if (lastSettledResetKey !== settledResetKey) { |
| 243 | setLastSettledResetKey(settledResetKey); |
| 244 | setSettledVisibleCount(THREAD_LIST_V2_SETTLED_INITIAL_COUNT); |
| 245 | } |
| 246 | const showMoreSettled = () => |
| 247 | setSettledVisibleCount((count) => count + THREAD_LIST_V2_SETTLED_PAGE_COUNT); |
| 248 | const { |
| 249 | loaded: shelfPreferencesLoaded, |
| 250 | settledShelfExpanded, |
| 251 | snoozedShelfExpanded, |
| 252 | workingShelfEnabled, |
| 253 | workingShelfExpanded, |
| 254 | toggleSettledShelf, |
| 255 | toggleSnoozedShelf, |
| 256 | toggleWorkingShelf, |
| 257 | } = useThreadListV2ShelfPreferences(); |
| 258 | const now = useThreadListNow(threads); |
| 259 | const listEnvironments = useAtomValue(threadListEnvironmentsAtom); |
| 260 | const { |
| 261 | providersByEnvironmentId, |
| 262 | machineByEnvironmentId, |
| 263 | settlementEnvironmentIds, |
| 264 | snoozeEnvironmentIds, |
| 265 | snoozePresetsByEnvironmentId, |
| 266 | pinningEnvironmentIds, |
| 267 | autoSettleOptOutEnvironmentIds, |
| 268 | pinReorderEnvironmentIds, |
| 269 | activeReorderEnvironmentIds, |
| 270 | titleRegenerationEnvironmentIds, |
| 271 | } = listEnvironments; |
| 272 | const resolveProviderInstance = useThreadRowProviderInstanceResolver(providersByEnvironmentId); |
| 273 | const pendingOrder = usePendingThreadOrder(); |
| 274 | const { |
| 275 | layout: threadListV2Layout, |
| 276 | items: threadListV2Items, |
| 277 | contentOnlyThreadKeys, |
| 278 | olderSettledShelf, |
| 279 | } = useThreadListV2({ |
| 280 | threads: launchingThreads, |
| 281 | pendingTasks, |
| 282 | environmentId: options.selectedEnvironmentId, |
| 283 | projectRefs: selectedProjectScope === null ? null : selectedProjectScope.projectRefs, |
| 284 | searchQuery: props.searchQuery, |
| 285 | searchMatches: threadSearchMatchByKey, |
| 286 | settlementEnvironmentIds, |
| 287 | snoozeEnvironmentIds, |
| 288 | pinReorderEnvironmentIds, |
| 289 | activeReorderEnvironmentIds, |
| 290 | queuedThreadKeys, |
| 291 | settledLimit: settledVisibleCount, |
| 292 | now, |
| 293 | pendingOrder, |
| 294 | shelfPreferencesLoaded, |
| 295 | workingShelfEnabled, |
| 296 | workingShelfExpanded, |
| 297 | snoozedShelfExpanded, |
| 298 | settledShelfExpanded, |
| 299 | selectedThreadKey, |
| 300 | }); |
| 301 | const listItems: readonly SidebarListItem[] = |
| 302 | settledShelfExpanded && threadListV2Layout.hiddenSettledCount > 0 |
| 303 | ? [ |
| 304 | ...threadListV2Items, |
| 305 | { |
| 306 | type: "v2-show-more", |
| 307 | key: "v2-show-more", |
| 308 | hiddenCount: threadListV2Layout.hiddenSettledCount, |
| 309 | ...(olderSettledShelf.loading |
| 310 | ? { state: "loading" as const } |
| 311 | : olderSettledShelf.failed |
| 312 | ? { state: "failed" as const } |
| 313 | : {}), |
| 314 | }, |
| 315 | ] |
| 316 | : threadListV2Items; |
| 317 | |
| 318 | const handleSwipeableWillOpen = (methods: SwipeableMethods) => { |
| 319 | if (openSwipeableRef.current !== methods) { |
| 320 | openSwipeableRef.current?.close(); |
| 321 | openSwipeableRef.current = methods; |
| 322 | } |
| 323 | }; |
| 324 | const handleSwipeableClose = (methods: SwipeableMethods) => { |
| 325 | if (openSwipeableRef.current === methods) { |
| 326 | openSwipeableRef.current = null; |
| 327 | } |
| 328 | }; |
| 329 | // Destructure callback props; capturing all props would invalidate these row-closing handlers on unrelated changes. |
| 330 | const { onSelectThread, onOpenThreadPullRequests } = props; |
| 331 | // A row listed for a message match opens the thread at that message, by |
| 332 | // tap or by shortcut. |
| 333 | const handleSelectThread = (thread: EnvironmentThreadShell) => { |
| 334 | const key = threadSearchMatchKey({ environmentId: thread.environmentId, threadId: thread.id }); |
| 335 | const messageId = contentOnlyThreadKeys.has(key) |
| 336 | ? threadSearchMatchByKey.get(key)?.messageId |
| 337 | : undefined; |
| 338 | if (messageId) { |
| 339 | requestThreadMessageJump(scopedThreadKey(thread.environmentId, thread.id), messageId); |
| 340 | } |
| 341 | onSelectThread(thread); |
| 342 | openSwipeableRef.current?.close(); |
| 343 | }; |
| 344 | const handleOpenThreadPullRequests = ( |
| 345 | thread: EnvironmentThreadShell, |
| 346 | pr: ThreadPrPresentation, |
| 347 | ) => { |
| 348 | onOpenThreadPullRequests(thread, pr); |
| 349 | openSwipeableRef.current?.close(); |
| 350 | }; |
| 351 | const handleScrollBeginDrag = () => { |
| 352 | openSwipeableRef.current?.close(); |
| 353 | }; |
| 354 | const onFabScroll = useFabScroll(); |
| 355 | const { swipeEnabled, scrollGateHandlers } = useSwipeableScrollGate({ |
| 356 | onScroll: onFabScroll, |
| 357 | onScrollBeginDrag: handleScrollBeginDrag, |
| 358 | }); |
| 359 | // Recycle equality needs project/search data for titles and favicons; keep the minute clock on items to limit updates. |
| 360 | const listExtraData = { |
| 361 | activeNewTask, |
| 362 | selectedThreadKey: selectedThreadKey ?? "", |
| 363 | projectByKey, |
| 364 | projectTitleByProjectKey, |
| 365 | savedConnectionsById, |
| 366 | listEnvironments, |
| 367 | threadSearchMatchByKey, |
| 368 | workingShelfEnabled, |
| 369 | }; |
| 370 | useThreadJumpShortcuts(listItems, handleSelectThread); |
| 371 | const sidebarItemsAreEqual = (previous: SidebarListItem, item: SidebarListItem): boolean => { |
| 372 | if (isThreadListV2ListItem(previous) && isThreadListV2ListItem(item)) { |
| 373 | return threadListV2ListItemsAreEqual(previous, item); |
| 374 | } |
| 375 | if (previous.type === "v2-show-more" && item.type === "v2-show-more") { |
| 376 | return previous.hiddenCount === item.hiddenCount && previous.state === item.state; |
| 377 | } |
| 378 | return false; |
| 379 | }; |
| 380 | const renderListItem = ({ item }: { readonly item: SidebarListItem }) => { |
| 381 | switch (item.type) { |
| 382 | case "v2-pending": { |
| 383 | const pendingScopeKey = scopedProjectKey( |
| 384 | item.pendingTask.environmentId, |
| 385 | item.pendingTask.projectId, |
| 386 | ); |
| 387 | return ( |
| 388 | <ThreadListV2PendingRow |
| 389 | pendingTask={item.pendingTask} |
| 390 | selected={ |
| 391 | activeNewTask?.pendingKey === item.pendingTask.key || |
| 392 | (item.pendingTask.kind === "pending" && |
| 393 | scopedThreadKey( |
| 394 | item.pendingTask.environmentId, |
| 395 | item.pendingTask.message.threadId, |
| 396 | ) === selectedThreadKey) |
| 397 | } |
| 398 | project={projectByKey.get(pendingScopeKey) ?? null} |
| 399 | environmentLabel={ |
| 400 | Object.keys(savedConnectionsById).length > 1 |
| 401 | ? (savedConnectionsById[item.pendingTask.environmentId]?.environmentLabel ?? null) |
| 402 | : null |
| 403 | } |
| 404 | environmentMachine={machineByEnvironmentId.get(item.pendingTask.environmentId)} |
| 405 | pane="sidebar" |
| 406 | showPendingDivider={item.showPendingDivider} |
| 407 | onSelectPendingTask={props.onOpenPendingTask} |
| 408 | onDeletePendingTask={confirmDeletePendingTask} |
| 409 | fullSwipeWidth={props.width - 20} |
| 410 | onSwipeableClose={handleSwipeableClose} |
| 411 | onSwipeableWillOpen={handleSwipeableWillOpen} |
| 412 | simultaneousSwipeGesture={sidebarScrollGesture} |
| 413 | /> |
| 414 | ); |
| 415 | } |
| 416 | case "v2-thread": { |
| 417 | const thread = item.item.thread; |
| 418 | const scopeKey = scopedProjectKey(thread.environmentId, thread.projectId); |
| 419 | return ( |
| 420 | <ThreadListV2Row |
| 421 | onNewThreadOnBranch={props.onNewThreadOnBranch} |
| 422 | thread={thread} |
| 423 | variant={item.item.variant} |
| 424 | hasQueuedMessages={item.hasQueuedMessages} |
| 425 | snoozed={item.item.snoozed} |
| 426 | pinned={item.item.pinned} |
| 427 | wokeAt={item.item.wokeAt} |
| 428 | snoozePresetMinute={item.snoozePresetMinute ?? ""} |
| 429 | snoozeWakeLabelText={item.snoozeWakeLabelText} |
| 430 | timeLabel={item.timeLabel} |
| 431 | project={projectByKey.get(scopeKey) ?? null} |
| 432 | providerInstance={resolveProviderInstance(thread)} |
| 433 | providers={providersByEnvironmentId.get(thread.environmentId)} |
| 434 | environmentLabel={ |
| 435 | Object.keys(savedConnectionsById).length > 1 |
| 436 | ? (savedConnectionsById[thread.environmentId]?.environmentLabel ?? null) |
| 437 | : null |
| 438 | } |
| 439 | environmentMachine={machineByEnvironmentId.get(thread.environmentId)} |
| 440 | searchMatch={ |
| 441 | // Only rows listed for their messages show one and open at it. |
| 442 | contentOnlyThreadKeys.has( |
| 443 | threadSearchMatchKey({ environmentId: thread.environmentId, threadId: thread.id }), |
| 444 | ) |
| 445 | ? threadSearchMatchByKey.get( |
| 446 | threadSearchMatchKey({ |
| 447 | environmentId: thread.environmentId, |
| 448 | threadId: thread.id, |
| 449 | }), |
| 450 | ) |
| 451 | : undefined |
| 452 | } |
| 453 | searchQuery={threadSearch.query} |
| 454 | pane="sidebar" |
| 455 | selected={ |
| 456 | !activeNewTask && |
| 457 | scopedThreadKey(thread.environmentId, thread.id) === selectedThreadKey |
| 458 | } |
| 459 | fullSwipeWidth={props.width - 20} |
| 460 | onSelectThread={handleSelectThread} |
| 461 | onOpenThreadPullRequests={handleOpenThreadPullRequests} |
| 462 | onDeleteThread={confirmDeleteThread} |
| 463 | onArchiveThread={archiveThread} |
| 464 | onRenameThread={renameThread} |
| 465 | onRegenerateThreadTitle={regenerateThreadTitle} |
| 466 | titleRegenerationSupported={titleRegenerationEnvironmentIds.has(thread.environmentId)} |
| 467 | settlementSupported={settlementEnvironmentIds.has(thread.environmentId)} |
| 468 | onSettleThread={settleThread} |
| 469 | snoozeSupported={snoozeEnvironmentIds.has(thread.environmentId)} |
| 470 | snoozePresets={snoozePresetsByEnvironmentId.get(thread.environmentId)} |
| 471 | pinningSupported={pinningEnvironmentIds.has(thread.environmentId)} |
| 472 | autoSettleOptOutSupported={autoSettleOptOutEnvironmentIds.has(thread.environmentId)} |
| 473 | reorderSupported={ |
| 474 | item.item.pinned |
| 475 | ? pinReorderEnvironmentIds.has(thread.environmentId) |
| 476 | : !workingShelfEnabled && activeReorderEnvironmentIds.has(thread.environmentId) |
| 477 | } |
| 478 | canMoveUp={item.canMoveUp} |
| 479 | canMoveDown={item.canMoveDown} |
| 480 | onSnoozeThread={snoozeThread} |
| 481 | onUnsnoozeThread={unsnoozeThread} |
| 482 | onUnsettleThread={unsettleThread} |
| 483 | onPinThread={pinThread} |
| 484 | onUnpinThread={unpinThread} |
| 485 | onSetThreadAutoSettle={setThreadAutoSettle} |
| 486 | onMoveThread={moveThread} |
| 487 | onSwipeableClose={handleSwipeableClose} |
| 488 | onSwipeableWillOpen={handleSwipeableWillOpen} |
| 489 | simultaneousSwipeGesture={sidebarScrollGesture} |
| 490 | /> |
| 491 | ); |
| 492 | } |
| 493 | case "v2-working-shelf": |
| 494 | return ( |
| 495 | <ThreadListV2WorkingShelfHeader |
| 496 | count={item.count} |
| 497 | disabled={item.disabled} |
| 498 | expanded={item.expanded} |
| 499 | onToggle={toggleWorkingShelf} |
| 500 | pane="sidebar" |
| 501 | /> |
| 502 | ); |
| 503 | case "v2-snoozed-shelf": |
| 504 | return ( |
| 505 | <ThreadListV2SnoozedShelfHeader |
| 506 | count={item.count} |
| 507 | disabled={item.disabled} |
| 508 | expanded={item.expanded} |
| 509 | onToggle={toggleSnoozedShelf} |
| 510 | pane="sidebar" |
| 511 | /> |
| 512 | ); |
| 513 | case "v2-settled-shelf": |
| 514 | return ( |
| 515 | <ThreadListV2SettledShelfHeader |
| 516 | count={item.count} |
| 517 | disabled={item.disabled} |
| 518 | expanded={item.expanded} |
| 519 | onToggle={toggleSettledShelf} |
| 520 | pane="sidebar" |
| 521 | /> |
| 522 | ); |
| 523 | case "v2-show-more": |
| 524 | return ( |
| 525 | <ThreadListV2ShowMoreRow |
| 526 | pane="sidebar" |
| 527 | hiddenCount={item.hiddenCount} |
| 528 | {...(item.state === undefined ? {} : { state: item.state })} |
| 529 | onPress={() => { |
| 530 | olderSettledShelf.retry(); |
| 531 | showMoreSettled(); |
| 532 | }} |
| 533 | /> |
| 534 | ); |
| 535 | } |
| 536 | }; |
| 537 | const header = ( |
| 538 | <WorkspaceListHeader |
| 539 | accessibilityLabel={gt("{appName}, Threads", { appName: "T3 Code" })} |
| 540 | onOpenEnvironments={props.onOpenEnvironmentSettings} |
| 541 | onOpenSettings={props.onOpenSettings} |
| 542 | search={{ |
| 543 | value: props.searchQuery, |
| 544 | onChangeText: props.onSearchQueryChange, |
| 545 | placeholder: gt("Search", { $context: "search field placeholder" }), |
| 546 | accessibilityLabel: gt("Search threads"), |
| 547 | }} |
| 548 | filter={{ |
| 549 | customized: options.selectedEnvironmentId !== null || selectedProjectKey !== null, |
| 550 | items: buildHomeListFilterMenuItems( |
| 551 | { |
| 552 | environments, |
| 553 | projects: projectFilterOptions, |
| 554 | selectedEnvironmentId: options.selectedEnvironmentId, |
| 555 | selectedProjectKey, |
| 556 | onEnvironmentChange: setSelectedEnvironmentId, |
| 557 | onProjectChange: setSelectedProjectKey, |
| 558 | }, |
| 559 | messages, |
| 560 | ), |
| 561 | }} |
| 562 | sidebar={{ |
| 563 | width: props.width, |
| 564 | visible: props.visible, |
| 565 | onRequestVisibility: props.onRequestVisibility, |
| 566 | }} |
| 567 | /> |
| 568 | ); |
| 569 | const showAddEnvironment = |
| 570 | !catalogState.isLoadingConnections && |
| 571 | !catalogState.hasReadyEnvironment && |
| 572 | !catalogState.hasConnectingEnvironment; |
| 573 | const listEmpty = ( |
| 574 | <View> |
| 575 | <Text |
| 576 | className={ |
| 577 | Platform.OS === "android" |
| 578 | ? "px-4 py-4 text-center text-sm text-drawer-foreground-muted" |
| 579 | : "px-2 py-4 text-sm text-drawer-foreground-muted" |
| 580 | } |
| 581 | > |
| 582 | {catalogState.isLoadingConnections |
| 583 | ? gt("Loading threads…") |
| 584 | : showAddEnvironment |
| 585 | ? gt("No environments connected") |
| 586 | : props.searchQuery.trim().length > 0 |
| 587 | ? threadSearch.isPending |
| 588 | ? gt("Searching thread messages…") |
| 589 | : threadSearch.failed |
| 590 | ? gt("Couldn't search thread messages") |
| 591 | : gt("No matching threads") |
| 592 | : selectedProjectScope !== null |
| 593 | ? gt("No threads in {project}", { project: selectedProjectScope.title }) |
| 594 | : gt("No threads yet")} |
| 595 | </Text> |
| 596 | {showAddEnvironment ? ( |
| 597 | <View className={Platform.OS === "android" ? "self-center" : "px-2"}> |
| 598 | <Button |
| 599 | tone="primary" |
| 600 | size="compact" |
| 601 | icon="plus" |
| 602 | label={gt("Add environment")} |
| 603 | onPress={props.onOpenEnvironmentSettings} |
| 604 | /> |
| 605 | </View> |
| 606 | ) : null} |
| 607 | </View> |
| 608 | ); |
| 609 | |
| 610 | if (Platform.OS === "ios") { |
| 611 | return ( |
| 612 | <> |
| 613 | {header} |
| 614 | <View className="flex-1"> |
| 615 | <SwipeableScrollGateProvider enabled={swipeEnabled}> |
| 616 | <GestureDetector gesture={sidebarScrollGesture}> |
| 617 | <AnimatedLegendList |
| 618 | renderScrollComponent={NativeScrollView} |
| 619 | itemLayoutAnimation={THREAD_LIST_ROW_LAYOUT} |
| 620 | data={listItems} |
| 621 | drawDistance={500} |
| 622 | estimatedItemSize={64} |
| 623 | extraData={listExtraData} |
| 624 | getItemType={(item) => item.type} |
| 625 | itemsAreEqual={sidebarItemsAreEqual} |
| 626 | keyExtractor={(item) => item.key} |
| 627 | renderItem={renderListItem} |
| 628 | automaticallyAdjustsScrollIndicatorInsets |
| 629 | // The column lays the list under its bar, glass or solid; UIKit insets it past both. |
| 630 | contentInsetAdjustmentBehavior="automatic" |
| 631 | contentContainerStyle={[ |
| 632 | styles.threadListContent, |
| 633 | { |
| 634 | paddingBottom: Math.max(insets.bottom, 16) + 16, |
| 635 | paddingTop: 6, |
| 636 | }, |
| 637 | ]} |
| 638 | keyboardDismissMode="on-drag" |
| 639 | keyboardShouldPersistTaps="handled" |
| 640 | {...scrollGateHandlers} |
| 641 | recycleItems |
| 642 | scrollEventThrottle={16} |
| 643 | showsVerticalScrollIndicator={false} |
| 644 | style={styles.threadList} |
| 645 | ListEmptyComponent={listEmpty} |
| 646 | /> |
| 647 | </GestureDetector> |
| 648 | </SwipeableScrollGateProvider> |
| 649 | <ThreadUndoNotice visible={props.visible} /> |
| 650 | </View> |
| 651 | </> |
| 652 | ); |
| 653 | } |
| 654 | |
| 655 | // Android: the bar floats below the list. |
| 656 | return ( |
| 657 | <View testID="thread-navigation-sidebar" className="flex-1 bg-header"> |
| 658 | <View |
| 659 | className="flex-1" |
| 660 | style={{ |
| 661 | marginHorizontal: 4, |
| 662 | paddingBottom: insets.bottom, |
| 663 | backgroundColor: drawerColor, |
| 664 | borderTopLeftRadius: 28, |
| 665 | borderTopRightRadius: 28, |
| 666 | overflow: "hidden", |
| 667 | }} |
| 668 | > |
| 669 | {listItems.length === 0 ? ( |
| 670 | <View className="flex-1 items-center justify-center">{listEmpty}</View> |
| 671 | ) : ( |
| 672 | <SwipeableScrollGateProvider enabled={swipeEnabled}> |
| 673 | <GestureDetector gesture={sidebarScrollGesture}> |
| 674 | {/* oxlint-disable-next-line t3code/require-registered-list-scroll -- The Android sidebar has no native header to register with. */} |
| 675 | <AnimatedLegendList |
| 676 | itemLayoutAnimation={THREAD_LIST_ROW_LAYOUT} |
| 677 | data={listItems} |
| 678 | drawDistance={500} |
| 679 | estimatedItemSize={64} |
| 680 | extraData={listExtraData} |
| 681 | getItemType={(item) => item.type} |
| 682 | itemsAreEqual={sidebarItemsAreEqual} |
| 683 | keyExtractor={(item) => item.key} |
| 684 | renderItem={renderListItem} |
| 685 | contentContainerStyle={{ |
| 686 | paddingBottom: floatingTabsEnabled |
| 687 | ? FLOATING_TABS.bottom + FLOATING_TABS.edge + fabSize |
| 688 | : Math.max(insets.bottom, 16) + fabClearance - insets.bottom, |
| 689 | paddingTop: 6, |
| 690 | }} |
| 691 | keyboardDismissMode="on-drag" |
| 692 | keyboardShouldPersistTaps="handled" |
| 693 | {...scrollGateHandlers} |
| 694 | recycleItems |
| 695 | scrollEventThrottle={16} |
| 696 | showsVerticalScrollIndicator={false} |
| 697 | style={styles.threadList} |
| 698 | ListEmptyComponent={listEmpty} |
| 699 | /> |
| 700 | </GestureDetector> |
| 701 | </SwipeableScrollGateProvider> |
| 702 | )} |
| 703 | </View> |
| 704 | {header} |
| 705 | <ThreadUndoNotice visible={props.visible} /> |
| 706 | </View> |
| 707 | ); |
| 708 | } |
| 709 | |
| 710 | const styles = StyleSheet.create({ |
| 711 | threadList: { |
| 712 | flex: 1, |
| 713 | }, |
| 714 | threadListContent: { |
| 715 | paddingHorizontal: 8, |
| 716 | }, |
| 717 | }); |