Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ReviewSheet.tsx

884 lines32.9 KB

1import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
2import type { MenuAction } from "@react-native-menu/menu";
3import { useNavigation, type StaticScreenProps } from "@react-navigation/native";
4import {
5 NativeHeaderToolbar,
6 NativeStackScreenOptions,
7 nativeHeaderScrollEdgeEffects,
8} from "../../native/StackHeader";
9import { Screen, ScreenStack, ScreenStackHeaderConfig } from "react-native-screens";
10import {
11 memo,
12 type Ref,
13 type ReactElement,
14 useCallback,
15 useEffect,
16 useImperativeHandle,
17 useMemo,
18 useRef,
19 useState,
20} from "react";
21import {
22 ActivityIndicator,
23 FlatList,
24 Platform,
25 Pressable,
26 ScrollView,
27 type NativeSyntheticEvent,
28 StyleSheet,
29 View,
30} from "react-native";
31import { useSafeAreaInsets } from "react-native-safe-area-context";
32​
33import { AppText as Text } from "../../components/AppText";
34import { SymbolView } from "../../components/AppSymbol";
35import { AndroidHeaderIconButton, AndroidScreenHeader } from "../../components/AndroidScreenHeader";
36import { ControlPillMenu } from "../../components/ControlPill";
37import { environmentCatalog } from "../../connection/catalog";
38import { useEnvironmentPresentation } from "../../state/presentation";
39import { useAtomCommand } from "../../state/use-atom-command";
40import { useUniwindTheme } from "../../lib/useUniwindTheme";
41import { IOS_NAV_BAR_HEIGHT } from "../../lib/layoutMetrics";
42import { useThreadDraftForThread } from "../../state/use-thread-composer-state";
43import { EnvironmentConnectionNotice } from "../connection/EnvironmentConnectionNotice";
44import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
45import {
46 useAdaptiveWorkspaceLayout,
47 useAdaptiveWorkspacePaneRole,
48 useRegisterWorkspaceInspector,
49} from "../layout/AdaptiveWorkspaceLayout";
50import { useEnvironmentQuery } from "../../state/query";
51import { useSelectedThreadGitActions } from "../../state/use-selected-thread-git-actions";
52import { useSelectedThreadGitState } from "../../state/use-selected-thread-git-state";
53import { useSelectedThreadWorktree } from "../../state/use-selected-thread-worktree";
54import { useThreadSelection } from "../../state/use-thread-selection";
55import { vcsEnvironment } from "../../state/vcs";
56import { WorkspaceSidebarToolbar } from "../layout/workspace-sidebar-toolbar";
57import { ThreadGitMenu } from "../threads/ThreadGitControls";
58import { useReviewCacheForThread } from "./reviewState";
59import {
60 isNativeReviewDiffDrawEvent,
61 type NativeReviewDiffViewHandle,
62 resolveNativeReviewDiffView,
63} from "../diffs/nativeReviewDiffSurface";
64import { NATIVE_REVIEW_DIFF_CONTENT_WIDTH } from "./nativeReviewDiffAdapter";
65import { useAppearanceCodeSurface } from "../settings/appearance/useAppearanceCodeSurface";
66import { useReviewDiffData } from "./useReviewDiffData";
67import { useReviewDiffPrewarming } from "./useReviewDiffPrewarming";
68import { useReviewFileVisibility } from "./reviewFileVisibility";
69import { useReviewSections } from "./useReviewSections";
70import { useNativeReviewDiffBridge } from "./useNativeReviewDiffBridge";
71import { useReviewCommentSelectionController } from "./useReviewCommentSelectionController";
72import { resolveReviewAvailability } from "./reviewAvailability";
73import { resolveSelectedReviewFileId } from "./reviewPaneSelection";
74import { buildReviewSectionMenu } from "./review-section-menu";
75import type { ReviewSectionItem } from "./reviewModel";
76import { reportShowcaseSceneRendered } from "../showcase/showcaseRenderSignal";
77​
78const REVIEW_HEADER_SPACING = 0;
79const SHOWCASE_ENABLED = process.env.EXPO_PUBLIC_SHOWCASE === "1";
80​
81const ReviewNotice = memo(function ReviewNotice(props: { readonly notice: string }) {
82 return (
83 <View className="border-b border-adaptive-amber-200-900-a60 bg-adaptive-amber-50-950-a40 px-4 py-3">
84 <Text className="text-xs font-t3-bold uppercase text-adaptive-amber-700-300">
85 Partial diff
86 </Text>
87 <Text className="text-xs leading-normal text-adaptive-amber-800-200">{props.notice}</Text>
88 </View>
89 );
90});
91​
92function ReviewSelectionActionBar(props: {
93 readonly bottomInset: number;
94 readonly title: string | null;
95 readonly onOpenComment: (() => void) | null;
96 readonly onClear: () => void;
97}) {
98 if (!props.title) {
99 return null;
100 }
101​
102 const content = (
103 <>
104 <SymbolView
105 name={props.onOpenComment ? "text.bubble" : "line.3.horizontal.decrease.circle"}
106 size={16}
107 tintColorClassName={"accent-primary-foreground"}
108 type="monochrome"
109 />
110 <Text className="text-base font-t3-bold text-primary-foreground">{props.title}</Text>
111 </>
112 );
113​
114 return (
115 <View
116 pointerEvents="box-none"
117 style={{
118 position: "absolute",
119 left: 18,
120 right: 18,
121 bottom: Math.max(props.bottomInset, 10) + 18,
122 flexDirection: "row",
123 justifyContent: "center",
124 gap: 10,
125 }}
126 >
127 {props.onOpenComment ? (
128 <Pressable
129 className="h-12 flex-1 flex-row items-center justify-center gap-2 rounded-full bg-primary px-5"
130 onPress={props.onOpenComment}
131 >
132 {content}
133 </Pressable>
134 ) : (
135 <View className="h-12 flex-1 flex-row items-center justify-center gap-2 rounded-full bg-primary px-5">
136 {content}
137 </View>
138 )}
139​
140 <Pressable
141 className="h-12 w-12 items-center justify-center rounded-full bg-primary"
142 onPress={props.onClear}
143 >
144 <SymbolView
145 name="xmark"
146 size={16}
147 tintColorClassName={"accent-primary-foreground"}
148 type="monochrome"
149 />
150 </Pressable>
151 </View>
152 );
154​
155interface ReviewNavigatorFile {
156 readonly id: string;
157 readonly path: string;
158 readonly additions: number;
159 readonly deletions: number;
161​
162const ReviewFileNavigatorRow = memo(function ReviewFileNavigatorRow(props: {
163 readonly file: ReviewNavigatorFile;
164 readonly selected: boolean;
165 readonly onSelectFile: (fileId: string | null) => void;
166}) {
167 const { file, selected, onSelectFile } = props;
168 // Tapping the selected file again returns to the all-files diff.
169 const handlePress = useCallback(() => {
170 onSelectFile(selected ? null : file.id);
171 }, [file.id, onSelectFile, selected]);
172​
173 return (
174 <Pressable
175 accessibilityRole="button"
176 accessibilityState={{ selected }}
177 className={
178 selected
179 ? "mt-1 min-h-12 justify-center rounded-xl bg-subtle-strong px-3 py-2"
180 : "mt-1 min-h-12 justify-center rounded-xl px-3 py-2 active:bg-subtle"
181 }
182 onPress={handlePress}
183 >
184 <Text
185 className={
186 selected
187 ? "text-xs font-t3-bold text-foreground"
188 : "text-xs font-t3-medium text-foreground-secondary"
189 }
190 numberOfLines={2}
191 >
192 {file.path}
193 </Text>
194 <View className="mt-1 flex-row gap-2">
195 <Text className="text-2xs font-t3-bold text-emerald-600">+{file.additions}</Text>
196 <Text className="text-2xs font-t3-bold text-rose-600">-{file.deletions}</Text>
197 </View>
198 </Pressable>
199 );
200});
201​
202interface ReviewFileNavigatorHandle {
203 readonly setVisibleFile: (fileId: string | null) => void;
205​
206interface ReviewFileNavigatorProps {
207 readonly files: ReadonlyArray<ReviewNavigatorFile>;
208 readonly headerInset: number;
209 readonly sectionId: string | null;
210 readonly onSelectFile: (fileId: string | null) => void;
211 readonly ref?: Ref<ReviewFileNavigatorHandle>;
213​
214function ReviewFileNavigator({
215 files,
216 headerInset,
217 sectionId,
218 onSelectFile,
219 ref,
220}: ReviewFileNavigatorProps) {
221 const insets = useSafeAreaInsets();
222 const theme = useUniwindTheme();
223 const sheetColor = theme["--color-sheet"];
224 const foregroundColor = theme["--color-foreground"];
225 const headerScrollEdgeEffects = nativeHeaderScrollEdgeEffects(Platform.OS, Platform.Version);
226 const [fileSelection, setFileSelection] = useState<{
227 readonly sectionId: string | null;
228 readonly fileId: string | null;
229 }>({ sectionId: null, fileId: null });
230 const availableFileIds = useMemo(() => files.map((file) => file.id), [files]);
231 const selectedFileId = resolveSelectedReviewFileId({
232 selection: fileSelection,
233 sectionId,
234 availableFileIds,
235 });
236​
237 useImperativeHandle(
238 ref,
239 () => ({
240 setVisibleFile: (fileId) => {
241 if (fileId !== null && !availableFileIds.includes(fileId)) {
242 return;
243 }
244 setFileSelection((current) => {
245 if (current.sectionId === sectionId && current.fileId === fileId) {
246 return current;
247 }
248 return { sectionId, fileId };
249 });
250 },
251 }),
252 [availableFileIds, sectionId],
253 );
254​
255 const handleSelectFile = useCallback(
256 (fileId: string | null) => {
257 setFileSelection({ sectionId, fileId });
258 onSelectFile(fileId);
259 },
260 [onSelectFile, sectionId],
261 );
262​
263 const renderFile = useCallback(
264 ({ item }: { readonly item: ReviewNavigatorFile }) => (
265 <ReviewFileNavigatorRow
266 file={item}
267 selected={selectedFileId === item.id}
268 onSelectFile={handleSelectFile}
269 />
270 ),
271 [handleSelectFile, selectedFileId],
272 );
273​
274 const fileList = (
275 <FlatList
276 data={files}
277 extraData={selectedFileId}
278 keyExtractor={(file) => file.id}
279 contentContainerStyle={{
280 paddingHorizontal: 8,
281 paddingBottom: 8,
282 // The nested native header is translucent; start the list below it so
283 // the scroll-edge effect can sample the content (same treatment as
284 // FileTreeBrowser in the Files pane).
285 paddingTop: Platform.OS === "ios" ? insets.top + IOS_NAV_BAR_HEIGHT + 8 : 8,
286 }}
287 scrollIndicatorInsets={
288 Platform.OS === "ios" ? { top: insets.top + IOS_NAV_BAR_HEIGHT } : undefined
289 }
290 renderItem={renderFile}
291 />
292 );
293​
294 if (Platform.OS === "ios") {
295 return (
296 <View className="flex-1 border-l border-border bg-sheet">
297 <ScreenStack style={{ flex: 1 }}>
298 <Screen
299 activityState={2}
300 enabled
301 isNativeStack
302 screenId="review-file-navigator-native"
303 scrollEdgeEffects={headerScrollEdgeEffects}
304 style={{ backgroundColor: sheetColor, flex: 1 }}
305 >
306 {fileList}
307 <ScreenStackHeaderConfig
308 backgroundColor="rgba(0,0,0,0)"
309 color={foregroundColor}
310 hideBackButton
311 hideShadow={false}
312 navigationItemStyle="editor"
313 subtitle={`${files.length} ${files.length === 1 ? "file" : "files"}`}
314 title="Changed files"
315 titleColor={foregroundColor}
316 titleFontSize={17}
317 titleFontWeight="700"
318 translucent
319 />
320 </Screen>
321 </ScreenStack>
322 </View>
323 );
324 }
325​
326 return (
327 <View className="flex-1 border-l border-border bg-sheet">
328 <View className="border-b border-border" style={{ paddingTop: headerInset }}>
329 <View className="px-4 py-3">
330 <Text className="text-sm font-t3-bold text-foreground">Changed files</Text>
331 <Text className="text-xs text-foreground-muted">
332 {files.length} {files.length === 1 ? "file" : "files"}
333 </Text>
334 </View>
335 </View>
336 {fileList}
337 </View>
338 );
340​
341type ReviewSheetProps = StaticScreenProps<{
342 readonly environmentId: EnvironmentId;
343 readonly threadId: ThreadId;
344}>;
345​
346export function ReviewSheet(props: ReviewSheetProps) {
347 const isAndroid = Platform.OS === "android";
348 const { nativeReviewDiffStyle } = useAppearanceCodeSurface();
349 useAdaptiveWorkspacePaneRole("inspector");
350 const { panes, showAuxiliaryPane, toggleAuxiliaryPane } = useAdaptiveWorkspaceLayout();
351 const navigation = useNavigation();
352 const insets = useSafeAreaInsets();
353 const { themeAppearance: selectedTheme } = useAppearancePreferences();
354 const headerIcon = String(useUniwindTheme()["--color-icon"]);
355 const { environmentId, threadId } = props.route.params;
356 const environment = useEnvironmentPresentation(environmentId);
357 const retryEnvironment = useAtomCommand(environmentCatalog.retryNow, "environment retry");
358 const isEnvironmentReady = environment.presentation?.connection.phase === "connected";
359 const { draftMessage } = useThreadDraftForThread({ environmentId, threadId });
360 const reviewCache = useReviewCacheForThread({ environmentId, threadId });
361 /* ─── Git actions for the toolbar menu (commit/push without leaving review) ── */
362 const { selectedThread } = useThreadSelection();
363 const { selectedThreadCwd } = useSelectedThreadWorktree();
364 const gitState = useSelectedThreadGitState();
365 const gitActions = useSelectedThreadGitActions();
366 const gitStatusQuery = useEnvironmentQuery(
367 selectedThread !== null && selectedThreadCwd !== null
368 ? vcsEnvironment.status({
369 environmentId: selectedThread.environmentId,
370 input: { cwd: selectedThreadCwd },
371 })
372 : null,
373 );
374 // The selection-based git hooks only apply when this review belongs to the
375 // selected thread (it always does when reached from the thread's toolbar).
376 const gitMenuAvailable =
377 selectedThread !== null && String(selectedThread.id) === String(threadId);
378 // With a solid (non-overlay) header the content lays out below the header
379 // natively, so no manual top inset is needed. (Android renders its own
380 // in-flow AndroidScreenHeader, so it needs no inset either.)
381 const topContentInset = 0;
382​
383 useEffect(() => {
384 showAuxiliaryPane("inspector");
385 }, [environmentId, showAuxiliaryPane, threadId]);
386 const { error, reviewSections, selectedSection, refreshSelectedSection, selectSection } =
387 useReviewSections({
388 enabled: isEnvironmentReady,
389 environmentId,
390 threadId,
391 reviewCache,
392 });
393 useReviewDiffPrewarming({
394 threadKey: reviewCache.threadKey,
395 sections: reviewSections,
396 selectedSectionId: selectedSection?.id ?? null,
397 });
398 const { headerDiffSummary, nativeReviewDiffData, parsedDiff, pendingReviewCommentCount } =
399 useReviewDiffData({
400 threadKey: reviewCache.threadKey,
401 selectedSection,
402 draftMessage,
403 });
404 const NativeReviewDiffView = resolveNativeReviewDiffView()!;
405 const nativeReviewDiffViewRef = useRef<NativeReviewDiffViewHandle>(null);
406 const showcasedReviewDrawRef = useRef<string | null>(null);
407 // Native pull-to-refresh on the diff surface (replaces the old Refresh menu item).
408 const [isPullRefreshing, setIsPullRefreshing] = useState(false);
409 const handlePullToRefresh = useCallback(async () => {
410 setIsPullRefreshing(true);
411 try {
412 await refreshSelectedSection();
413 } finally {
414 setIsPullRefreshing(false);
415 }
416 }, [refreshSelectedSection]);
417 const reviewFileNavigatorRef = useRef<ReviewFileNavigatorHandle>(null);
418 const reviewFiles = parsedDiff.kind === "files" ? parsedDiff.files : [];
419 const fileVisibility = useReviewFileVisibility({
420 threadKey: reviewCache.threadKey,
421 sectionId: selectedSection?.id ?? null,
422 files: reviewFiles,
423 cachedExpandedFileIds: selectedSection?.id
424 ? reviewCache.expandedFileIdsBySection[selectedSection.id]
425 : undefined,
426 cachedViewedFileIds: selectedSection?.id
427 ? reviewCache.viewedFileIdsBySection[selectedSection.id]
428 : undefined,
429 });
430 const { collapsedFileIds, toggleExpandedFile, toggleViewedFile, viewedFileIds } = fileVisibility;
431 const commentSelection = useReviewCommentSelectionController({
432 environmentId,
433 threadId,
434 selectedSection,
435 nativeReviewDiffData,
436 });
437 const nativeBridge = useNativeReviewDiffBridge({
438 threadKey: reviewCache.threadKey,
439 sectionId: selectedSection?.id ?? null,
440 diff: selectedSection?.diff,
441 data: nativeReviewDiffData,
442 collapsedFileIds,
443 viewedFileIds,
444 selectedRowIds: commentSelection.selectedRowIds,
445 canHighlight: parsedDiff.kind === "files",
446 });
447 const showcaseReviewKey =
448 SHOWCASE_ENABLED && parsedDiff.kind === "files" && selectedSection
449 ? `${reviewCache.threadKey}:${selectedSection.id}:${nativeBridge.tokensResetKey}:${nativeBridge.themeId}`
450 : null;
451 const handleNativeDebug = useCallback(
452 (event: NativeSyntheticEvent<Record<string, unknown>>) => {
453 nativeBridge.onDebug(event);
454 if (
455 showcaseReviewKey === null ||
456 showcasedReviewDrawRef.current === showcaseReviewKey ||
457 !isNativeReviewDiffDrawEvent(event.nativeEvent)
458 ) {
459 return;
460 }
461 showcasedReviewDrawRef.current = showcaseReviewKey;
462 reportShowcaseSceneRendered({ scene: "review", themeId: nativeBridge.themeId });
463 },
464 [nativeBridge.onDebug, nativeBridge.themeId, showcaseReviewKey],
465 );
466​
467 const handleSelectFile = useCallback(
468 (fileId: string | null) => {
469 commentSelection.clearSelection();
470 if (fileId !== null && collapsedFileIds.includes(fileId)) {
471 toggleExpandedFile(fileId);
472 }
473 const navigation =
474 fileId === null
475 ? nativeReviewDiffViewRef.current?.scrollToTop(true)
476 : nativeReviewDiffViewRef.current?.scrollToFile(fileId, true);
477 void navigation?.catch((error: unknown) => {
478 console.error("[review] Failed to navigate to diff file", error);
479 });
480 },
481 [collapsedFileIds, commentSelection, toggleExpandedFile],
482 );
483 const handleVisibleFileChange = useCallback(
484 (event: NativeSyntheticEvent<{ readonly fileId?: string | null }>) => {
485 reviewFileNavigatorRef.current?.setVisibleFile(event.nativeEvent.fileId ?? null);
486 },
487 [],
488 );
489 const renderInspector = useCallback(
490 () => (
491 <ReviewFileNavigator
492 ref={reviewFileNavigatorRef}
493 files={nativeReviewDiffData.files}
494 // The workspace inspector column spans the full window height, so the
495 // pane clears the status bar itself.
496 headerInset={insets.top}
497 sectionId={selectedSection?.id ?? null}
498 onSelectFile={handleSelectFile}
499 />
500 ),
501 [handleSelectFile, insets.top, nativeReviewDiffData.files, selectedSection?.id],
502 );
503​
504 const handleNativeToggleFile = useCallback(
505 (event: NativeSyntheticEvent<{ readonly fileId?: string }>) => {
506 const { fileId } = event.nativeEvent;
507 if (fileId) {
508 toggleExpandedFile(fileId);
509 }
510 },
511 [toggleExpandedFile],
512 );
513​
514 const handleNativeToggleViewedFile = useCallback(
515 (event: NativeSyntheticEvent<{ readonly fileId?: string }>) => {
516 const { fileId } = event.nativeEvent;
517 if (fileId) {
518 toggleViewedFile(fileId);
519 }
520 },
521 [toggleViewedFile],
522 );
523​
524 const parsedDiffNotice =
525 parsedDiff.kind === "files" || parsedDiff.kind === "raw" ? parsedDiff.notice : null;
526 const hasCachedSelectedDiff = selectedSection?.diff != null;
527 const hasAnyCachedDiff = reviewSections.some((section) => section.diff != null);
528 const sectionMenu = useMemo(() => buildReviewSectionMenu(reviewSections), [reviewSections]);
529 const { showConnectionNotice, showSectionToolbar } = resolveReviewAvailability({
530 hasEnvironmentPresentation: environment.isReady,
531 isEnvironmentConnected: isEnvironmentReady,
532 hasCachedSelectedDiff,
533 hasAnyCachedDiff,
534 });
535 const androidSectionMenuActions = useMemo<MenuAction[]>(() => {
536 const sectionAction = (section: ReviewSectionItem | null, title: string): MenuAction => ({
537 id: section ? `section:${section.id}` : `unavailable:${title}`,
538 title: section?.id === selectedSection?.id ? `${title} (selected)` : title,
539 attributes: section ? undefined : { disabled: true },
540 });
541 const actions: MenuAction[] = [
542 sectionAction(sectionMenu.workingTree, "Working tree"),
543 sectionAction(sectionMenu.branchChanges, "Branch changes"),
544 sectionAction(sectionMenu.latestTurn, "Latest turn"),
545 ];
546​
547 if (sectionMenu.turns.length > 0) {
548 actions.push({
549 id: "turns",
550 title: "Turn",
551 subactions: sectionMenu.turns.map((section) => ({
552 id: `section:${section.id}`,
553 title: section.id === selectedSection?.id ? `${section.title} (selected)` : section.title,
554 subtitle: section.subtitle ?? undefined,
555 })),
556 });
557 }
558​
559 // The Android native diff surface has no pull-to-refresh, so refresh
560 // stays a menu action there (iOS refreshes via pull-to-refresh instead).
561 actions.push({
562 id: "refresh",
563 title: "Refresh current diff",
564 attributes: {
565 disabled: !selectedSection || selectedSection.isLoading,
566 },
567 });
568 return actions;
569 }, [sectionMenu, selectedSection]);
570 const handleAndroidSectionMenuAction = useCallback(
571 (event: { nativeEvent: { event: string } }) => {
572 const id = event.nativeEvent.event;
573 if (id === "refresh") {
574 void refreshSelectedSection();
575 } else if (id.startsWith("section:")) {
576 selectSection(id.slice("section:".length));
577 }
578 },
579 [refreshSelectedSection, selectSection],
580 );
581 const handleRetryEnvironment = useCallback(() => {
582 void retryEnvironment(environmentId);
583 }, [environmentId, retryEnvironment]);
584 const handleReturnToThread = useCallback(() => {
585 if (navigation.canGoBack()) {
586 navigation.goBack();
587 return;
588 }
589 navigation.navigate("Thread", {
590 environmentId: String(environmentId),
591 threadId: String(threadId),
592 });
593 }, [environmentId, navigation, threadId]);
594 const androidHeaderSubtitle = [
595 selectedSection?.title,
596 headerDiffSummary.additions,
597 headerDiffSummary.deletions,
598 ]
599 .filter((part): part is string => Boolean(part))
600 .join(" · ");
601​
602 // The changed-files navigator lives in the workspace inspector column —
603 // the single right-hand pane per route — instead of an in-screen panel.
604 const showChangedFilesPane =
605 !showConnectionNotice && selectedSection !== null && parsedDiff.kind === "files";
606 useRegisterWorkspaceInspector(showChangedFilesPane ? renderInspector : undefined);
607​
608 const listHeader = useMemo(() => {
609 const children: ReactElement[] = [];
610​
611 if (error) {
612 children.push(
613 <View key="review-error" className="border-b border-border bg-card px-4 py-3">
614 <Text className="text-sm font-t3-bold text-foreground">Review unavailable</Text>
615 <Text className="text-xs leading-normal text-foreground-muted">{error}</Text>
616 </View>,
617 );
618 }
619​
620 if (parsedDiffNotice) {
621 children.push(<ReviewNotice key="review-notice" notice={parsedDiffNotice} />);
622 }
623​
624 if (children.length === 0) {
625 return null;
626 }
627​
628 return <>{children}</>;
629 }, [error, parsedDiffNotice]);
630 const headerSubtitle = [
631 headerDiffSummary.additions,
632 headerDiffSummary.deletions,
633 pendingReviewCommentCount > 0
634 ? `${pendingReviewCommentCount} comment${pendingReviewCommentCount === 1 ? "" : "s"}`
635 : null,
636 ]
637 .filter(Boolean)
638 .join(" · ");
639 const headerTitleText = selectedSection?.title ?? "Review changes";
640​
641 return (
642 <>
643 <NativeStackScreenOptions
644 options={
645 isAndroid
646 ? // Android draws its own in-flow header (AndroidScreenHeader below).
647 { headerShown: false }
648 : {
649 // Static header config lives in Stack.tsx (SOLID_HEADER_OPTIONS — the native
650 // diff scrolls internally, nothing for glass to sample). Only dynamic values
651 // here.
652 headerTintColor: headerIcon,
653 headerTitle: headerTitleText,
654 title: headerTitleText,
655 unstable_headerSubtitle:
656 Platform.OS === "ios" && headerSubtitle.length > 0 ? headerSubtitle : undefined,
657 }
658 }
659 />
660​
661 {isAndroid ? (
662 <AndroidScreenHeader
663 title="Review changes"
664 subtitle={androidHeaderSubtitle || "Select a diff"}
665 onBack={handleReturnToThread}
666 trailing={
667 showSectionToolbar ? (
668 <ControlPillMenu
669 actions={androidSectionMenuActions}
670 isAnchoredToRight
671 onPressAction={handleAndroidSectionMenuAction}
672 >
673 <AndroidHeaderIconButton
674 accessibilityLabel="Select review diff"
675 icon="ellipsis.circle"
676 />
677 </ControlPillMenu>
678 ) : null
679 }
680 />
681 ) : null}
682​
683 <WorkspaceSidebarToolbar>
684 <NativeHeaderToolbar.Button
685 accessibilityLabel="Back to chat"
686 icon="chevron.left"
687 onPress={handleReturnToThread}
688 />
689 </WorkspaceSidebarToolbar>
690​
691 {!isAndroid && (showSectionToolbar || panes.supportsAuxiliaryPane || gitMenuAvailable) ? (
692 <NativeHeaderToolbar placement="right">
693 {panes.supportsAuxiliaryPane ? (
694 <NativeHeaderToolbar.Button
695 accessibilityLabel={
696 panes.auxiliaryPaneVisible ? "Hide changed files" : "Show changed files"
697 }
698 icon="sidebar.right"
699 onPress={toggleAuxiliaryPane}
700 separateBackground
701 />
702 ) : null}
703 {gitMenuAvailable && selectedThread !== null ? (
704 <ThreadGitMenu
705 environmentId={environmentId}
706 threadId={threadId}
707 currentBranch={selectedThread.branch ?? null}
708 gitStatus={gitStatusQuery.data}
709 gitOperationLabel={gitState.gitOperationLabel}
710 onPull={gitActions.onPullSelectedThreadBranch}
711 onRunAction={gitActions.onRunSelectedThreadGitAction}
712 />
713 ) : null}
714 {showSectionToolbar ? (
715 <NativeHeaderToolbar.Menu icon="ellipsis" title="Select diff" separateBackground>
716 <NativeHeaderToolbar.Menu inline>
717 <NativeHeaderToolbar.MenuAction
718 disabled={sectionMenu.workingTree === null}
719 isOn={selectedSection?.id === sectionMenu.workingTree?.id}
720 onPress={() => {
721 if (sectionMenu.workingTree) {
722 selectSection(sectionMenu.workingTree.id);
723 }
724 }}
725 >
726 <NativeHeaderToolbar.Label>Working tree</NativeHeaderToolbar.Label>
727 </NativeHeaderToolbar.MenuAction>
728 <NativeHeaderToolbar.MenuAction
729 disabled={sectionMenu.branchChanges === null}
730 isOn={selectedSection?.id === sectionMenu.branchChanges?.id}
731 onPress={() => {
732 if (sectionMenu.branchChanges) {
733 selectSection(sectionMenu.branchChanges.id);
734 }
735 }}
736 >
737 <NativeHeaderToolbar.Label>Branch changes</NativeHeaderToolbar.Label>
738 </NativeHeaderToolbar.MenuAction>
739 <NativeHeaderToolbar.MenuAction
740 disabled={sectionMenu.latestTurn === null}
741 isOn={selectedSection?.id === sectionMenu.latestTurn?.id}
742 onPress={() => {
743 if (sectionMenu.latestTurn) {
744 selectSection(sectionMenu.latestTurn.id);
745 }
746 }}
747 >
748 <NativeHeaderToolbar.Label>Latest turn</NativeHeaderToolbar.Label>
749 </NativeHeaderToolbar.MenuAction>
750 {sectionMenu.turns.length > 0 ? (
751 <NativeHeaderToolbar.Menu title="Turn">
752 {sectionMenu.turns.map((section) => (
753 <NativeHeaderToolbar.MenuAction
754 key={section.id}
755 isOn={section.id === selectedSection?.id}
756 onPress={() => selectSection(section.id)}
757 subtitle={section.subtitle ?? undefined}
758 >
759 <NativeHeaderToolbar.Label>{section.title}</NativeHeaderToolbar.Label>
760 </NativeHeaderToolbar.MenuAction>
761 ))}
762 </NativeHeaderToolbar.Menu>
763 ) : null}
764 </NativeHeaderToolbar.Menu>
765 </NativeHeaderToolbar.Menu>
766 ) : null}
767 </NativeHeaderToolbar>
768 ) : null}
769​
770 <View className="flex-1 bg-sheet">
771 {showConnectionNotice ? (
772 <View className="flex-1" style={{ paddingTop: topContentInset }}>
773 <EnvironmentConnectionNotice
774 environmentLabel={environment.presentation?.entry.target.label ?? "Environment"}
775 connection={
776 environment.presentation?.connection ?? {
777 phase: "available",
778 error: null,
779 traceId: null,
780 }
781 }
782 resourceName="review"
783 onRetry={handleRetryEnvironment}
784 />
785 </View>
786 ) : selectedSection && parsedDiff.kind === "files" ? (
787 <View
788 className="flex-1"
789 style={{
790 backgroundColor: nativeBridge.theme.background,
791 }}
792 >
793 <View
794 className="min-w-0 flex-1"
795 style={{ paddingTop: topContentInset + REVIEW_HEADER_SPACING }}
796 >
797 {listHeader}
798 <View className="min-w-0 flex-1" collapsable={false}>
799 <NativeReviewDiffView
800 collapsable={false}
801 testID="review-native-diff-view"
802 refreshing={isPullRefreshing}
803 onPullToRefresh={() => void handlePullToRefresh()}
804 style={StyleSheet.absoluteFill}
805 appearanceScheme={selectedTheme}
806 collapsedFileIdsJson={nativeBridge.collapsedFileIdsJson}
807 collapsedCommentIdsJson={nativeBridge.collapsedCommentIdsJson}
808 contentResetKey={`${reviewCache.threadKey}:${selectedSection.id}`}
809 contentWidth={NATIVE_REVIEW_DIFF_CONTENT_WIDTH}
810 nativeViewRef={nativeReviewDiffViewRef}
811 rowHeight={nativeReviewDiffStyle.rowHeight}
812 rowsJson={nativeBridge.rowsJson}
813 selectedRowIdsJson={nativeBridge.selectedRowIdsJson}
814 styleJson={nativeBridge.styleJson}
815 themeJson={nativeBridge.themeJson}
816 tokensPatchJson={nativeBridge.tokensPatchJson}
817 tokensResetKey={nativeBridge.tokensResetKey}
818 viewedFileIdsJson={nativeBridge.viewedFileIdsJson}
819 onDebug={handleNativeDebug}
820 onPressLine={commentSelection.onPressLine}
821 onVisibleFileChange={handleVisibleFileChange}
822 onToggleComment={nativeBridge.onToggleComment}
823 onToggleFile={handleNativeToggleFile}
824 onToggleViewedFile={handleNativeToggleViewedFile}
825 />
826 </View>
827 </View>
828 </View>
829 ) : (
830 <ScrollView
831 contentInsetAdjustmentBehavior="never"
832 contentInset={{ top: topContentInset, bottom: Math.max(insets.bottom, 18) + 18 }}
833 contentOffset={{ x: 0, y: -topContentInset }}
834 scrollIndicatorInsets={{
835 top: topContentInset,
836 bottom: Math.max(insets.bottom, 18) + 18,
837 }}
838 showsVerticalScrollIndicator={false}
839 className="flex-1"
840 >
841 {listHeader}
842 {!selectedSection ? (
843 <View className="border-b border-border bg-card px-4 py-5">
844 <Text className="text-sm font-t3-bold text-foreground">No review diffs</Text>
845 <Text className="text-xs leading-normal text-foreground-muted">
846 This thread has no ready turn diffs and the worktree diff is empty.
847 </Text>
848 </View>
849 ) : selectedSection.isLoading && selectedSection.diff === null ? (
850 <View className="items-center gap-3 border-b border-border bg-card px-4 py-6">
851 <ActivityIndicator size="small" />
852 <Text className="text-xs text-foreground-muted">Loading diff…</Text>
853 </View>
854 ) : parsedDiff.kind === "empty" ? (
855 <View className="border-b border-border bg-card px-4 py-5">
856 <Text className="text-sm font-t3-bold text-foreground">No changes</Text>
857 <Text className="text-xs leading-normal text-foreground-muted">
858 {selectedSection.subtitle ?? "This diff is empty."}
859 </Text>
860 </View>
861 ) : parsedDiff.kind === "raw" ? (
862 <View className="gap-3 border-b border-border bg-card px-4 py-4">
863 <Text className="text-xs leading-normal text-foreground-muted">
864 {parsedDiff.reason}
865 </Text>
866 <ScrollView horizontal showsHorizontalScrollIndicator={false} bounces={false}>
867 <Text selectable className="font-mono text-xs leading-relaxed text-foreground">
868 {parsedDiff.text}
869 </Text>
870 </ScrollView>
871 </View>
872 ) : null}
873 </ScrollView>
874 )}
875 <ReviewSelectionActionBar
876 bottomInset={insets.bottom}
877 title={commentSelection.selectionAction?.title ?? null}
878 onOpenComment={commentSelection.selectionAction?.onOpenComment ?? null}
879 onClear={commentSelection.clearSelection}
880 />
881 </View>
882 </>
883 );