GeezerVison is showing github.com — refactor(mobile): opening Review or Files shows the inspector in the … · pingdotgg/t3code@28286d5
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/Stack.tsx +6-1Lines changed: 6 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -482,9 +482,12 @@ export function workspaceLocationFromState(state: NavigationState) { | 482 | 482 | ? ({ ...state, routes, index: routes.length - 1 } as NavigationState) | 483 | 483 | : state; | 484 | 484 | const path = getPathFromState(effectiveState, navigationPathConfig); | | 485 | + const route = effectiveState.routes[effectiveState.index]; | 485 | 486 | return { | 486 | 487 | pathname: path.startsWith("/") ? path : `/${path}`, | 487 | | - routeKey: effectiveState.routes[effectiveState.index]?.key, | | 488 | + routeKey: route?.key, | | 489 | + routeName: route?.name, | | 490 | + routeKeys: effectiveState.routes.map((stackRoute) => stackRoute.key), | 488 | 491 | }; | 489 | 492 | } | 490 | 493 |
| @@ -518,6 +521,8 @@ function RootStackLayout(props: { | 518 | 521 | <AdaptiveWorkspaceLayout | 519 | 522 | pathname={workspaceLocation.pathname} | 520 | 523 | workspaceRouteKey={workspaceLocation.routeKey} | | 524 | + workspaceRouteName={workspaceLocation.routeName} | | 525 | + workspaceRouteKeys={workspaceLocation.routeKeys} | 521 | 526 | selectedPullRequestKey={selectedPullRequestKey(props.state)} | 522 | 527 | > | 523 | 528 | {props.children} | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/files/ThreadFilesRouteScreen.tsx +2-10Lines changed: 2 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4,7 +4,7 @@ import { resolveFilesystemReadAccess } from "@t3tools/client-runtime/state/files | 4 | 4 | import { environmentSession } from "../../state/session"; | 5 | 5 | import { NativeStackScreenOptions } from "../../native/StackHeader"; | 6 | 6 | import { StackActions, useNavigation, type StaticScreenProps } from "@react-navigation/native"; | 7 | | -import { useEffect, useId, useRef, useState } from "react"; | | 7 | +import { useId, useState } from "react"; | 8 | 8 | import { Platform, View } from "react-native"; | 9 | 9 | import { useSafeAreaInsets } from "react-native-safe-area-context"; | 10 | 10 | import Svg, { Defs, LinearGradient, Rect, Stop } from "react-native-svg"; | @@ -431,14 +431,13 @@ function FilesToolbarBottomFade() { | 431 | 431 | export function ThreadFilesTreeScreen(props: ThreadFilesRouteScreenProps) { | 432 | 432 | useAdaptiveWorkspacePaneRole("inspector"); | 433 | 433 | const navigation = useNavigation(); | 434 | | - const { fileInspector, layout, showAuxiliaryPane } = useAdaptiveWorkspaceLayout(); | | 434 | + const { fileInspector, layout } = useAdaptiveWorkspaceLayout(); | 435 | 435 | const [searchQuery, setSearchQuery] = useState(""); | 436 | 436 | const { themeAppearance: highlightTheme } = useAppearancePreferences(); | 437 | 437 | const { cwd, environmentId, projectName, selectedThread, threadId } = useThreadFilesWorkspace( | 438 | 438 | props.route.params, | 439 | 439 | ); | 440 | 440 | const hasFileInspector = fileInspector.supported && threadId !== null; | 441 | | - const revealedInspectorRef = useRef(false); | 442 | 441 | const fileAccessSession = useEnvironmentQuery( | 443 | 442 | environmentId !== null ? environmentSession.sessionStateAtom(environmentId) : null, | 444 | 443 | ); | @@ -511,13 +510,6 @@ export function ThreadFilesTreeScreen(props: ThreadFilesRouteScreenProps) { | 511 | 510 | theme: highlightTheme, | 512 | 511 | }); | 513 | 512 | }; | 514 | | - useEffect(() => { | 515 | | - if (hasFileInspector && cwd !== null && !revealedInspectorRef.current) { | 516 | | - revealedInspectorRef.current = true; | 517 | | - showAuxiliaryPane("inspector"); | 518 | | - } | 519 | | - }, [cwd, hasFileInspector, showAuxiliaryPane]); | 520 | | - | 521 | 513 | if (environmentId === null || (threadId !== null && selectedThread === null)) { | 522 | 514 | if (hasFileInspector) { | 523 | 515 | return ( | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx +49-45Lines changed: 49 additions & 45 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,16 +10,7 @@ import { EnvironmentId, ThreadId, type SidebarProjectGroupingMode } from "@t3too | 10 | 10 | import { useAtomValue } from "@effect/atom-react"; | 11 | 11 | import { useFocusEffect } from "@react-navigation/native"; | 12 | 12 | import { NavigationContext, NavigationRouteContext, useNavigation } from "@react-navigation/native"; | 13 | | -import { | 14 | | - use, | 15 | | - useDeferredValue, | 16 | | - useEffect, | 17 | | - useEffectEvent, | 18 | | - useMemo, | 19 | | - useRef, | 20 | | - useState, | 21 | | - type ReactNode, | 22 | | -} from "react"; | | 13 | +import { use, useDeferredValue, useEffect, useMemo, useRef, useState, type ReactNode } from "react"; | 23 | 14 | import { Keyboard, Platform, useWindowDimensions, View } from "react-native"; | 24 | 15 | import { KeyboardController, useKeyboardState } from "react-native-keyboard-controller"; | 25 | 16 | import Animated, { | @@ -45,6 +36,7 @@ import { scopedThreadKey } from "../../lib/scopedEntities"; | 45 | 36 | import type { ThreadListFilters } from "../../persistence/mobile-preferences"; | 46 | 37 | import { appAtomRegistry } from "../../state/atom-registry"; | 47 | 38 | import { useProjects } from "../../state/entities"; | | 39 | +import { useThreadCwd } from "../../state/use-selected-thread-worktree"; | 48 | 40 | import { environmentThreadShells } from "../../state/threads"; | 49 | 41 | import { mobilePreferencesAtom } from "../../state/preferences"; | 50 | 42 | import { | @@ -128,46 +120,20 @@ export function useRegisterWorkspaceInspector(render: (() => ReactNode) | undefi | 128 | 120 | ); | 129 | 121 | })(); | 130 | 122 |
| 131 | | - const focusedRef = useRef(false); | 132 | | - const deactivateRef = useRef<(() => void) | null>(null); | 133 | | - | 134 | | - const syncRegistration = useEffectEvent(() => { | 135 | | - if (!focusedRef.current || wrappedRender === undefined) { | 136 | | - deactivateRef.current?.(); | 137 | | - return; | 138 | | - } | 139 | | - deactivateRef.current = registerWorkspaceInspector(wrappedRender); | 140 | | - }); | 141 | | - | 142 | | - useFocusEffect(() => { | 143 | | - focusedRef.current = true; | 144 | | - syncRegistration(); | 145 | | - return () => { | 146 | | - focusedRef.current = false; | 147 | | - syncRegistration(); | 148 | | - }; | 149 | | - }); | 150 | | - | 151 | | - useEffect(() => { | 152 | | - if (focusedRef.current) { | 153 | | - syncRegistration(); | 154 | | - } | 155 | | - // oxlint-disable-next-line react/exhaustive-effect-dependencies -- Changed pane content replaces its existing native workspace registration. | 156 | | - }, [wrappedRender]); | 157 | | - | 158 | | - useEffect( | 159 | | - () => () => { | 160 | | - deactivateRef.current?.(); | 161 | | - deactivateRef.current = null; | 162 | | - }, | 163 | | - [], | | 123 | + // useFocusEffect re-runs when the renderer changes while focused, so the | | 124 | + // pane always shows this render's content, and its cleanup deactivates on | | 125 | + // blur and unmount. | | 126 | + useFocusEffect(() => | | 127 | + wrappedRender === undefined ? undefined : registerWorkspaceInspector(wrappedRender), | 164 | 128 | ); | 165 | 129 | } | 166 | 130 |
| 167 | 131 | export function AdaptiveWorkspaceLayout(props: { | 168 | 132 | readonly children: ReactNode; | 169 | 133 | readonly pathname: string; | 170 | 134 | readonly workspaceRouteKey: string | undefined; | | 135 | + readonly workspaceRouteName: string | undefined; | | 136 | + readonly workspaceRouteKeys: ReadonlyArray<string>; | 171 | 137 | readonly selectedPullRequestKey?: string | null; | 172 | 138 | }) { | 173 | 139 | const preferencesResult = useAtomValue(mobilePreferencesAtom); | @@ -194,6 +160,8 @@ function AdaptiveWorkspaceLayoutContent( | 194 | 160 | readonly children: ReactNode; | 195 | 161 | readonly pathname: string; | 196 | 162 | readonly workspaceRouteKey: string | undefined; | | 163 | + readonly workspaceRouteName: string | undefined; | | 164 | + readonly workspaceRouteKeys: ReadonlyArray<string>; | 197 | 165 | readonly selectedPullRequestKey?: string | null; | 198 | 166 | } & { | 199 | 167 | readonly projectGroupingMode: SidebarProjectGroupingMode; | @@ -348,16 +316,52 @@ function AdaptiveWorkspaceLayoutContent( | 348 | 316 | const activeThread = parseActiveThreadPath(pathname); | 349 | 317 | const environmentId = activeThread?.environmentId ?? null; | 350 | 318 | const threadId = activeThread?.threadId ?? null; | 351 | | - const selectedThreadKey = (() => { | | 319 | + const selectedThreadRef = (() => { | 352 | 320 | if (environmentId === null || threadId === null) { | 353 | 321 | return null; | 354 | 322 | } | 355 | 323 | try { | 356 | | - return scopedThreadKey(EnvironmentId.make(environmentId), ThreadId.make(threadId)); | | 324 | + return { | | 325 | + environmentId: EnvironmentId.make(environmentId), | | 326 | + threadId: ThreadId.make(threadId), | | 327 | + }; | 357 | 328 | } catch { | 358 | 329 | return null; | 359 | 330 | } | 360 | 331 | })(); | | 332 | + const selectedThreadKey = | | 333 | + selectedThreadRef === null | | 334 | + ? null | | 335 | + : scopedThreadKey(selectedThreadRef.environmentId, selectedThreadRef.threadId); | | 336 | + const isFilesRoute = props.workspaceRouteName === "ThreadFiles"; | | 337 | + // Same resolution the Files screen uses: without a cwd it shows "Files unavailable" and | | 338 | + // registers no inspector, so revealing would only hide the sidebar beside that screen. | | 339 | + const filesCwd = useThreadCwd(isFilesRoute && fileInspector.supported ? selectedThreadRef : null); | | 340 | + // Opening a review or the files route reveals its inspector once per route and thread. | | 341 | + // Routes still on the stack remember their reveal, so going back to one keeps the user's choice. | | 342 | + const revealsInspector = | | 343 | + props.workspaceRouteName === "ThreadReview" || (isFilesRoute && filesCwd !== null); | | 344 | + const [revealedInspectors, setRevealedInspectors] = useState<ReadonlyMap<string, string>>( | | 345 | + () => new Map(), | | 346 | + ); | | 347 | + if ( | | 348 | + revealsInspector && | | 349 | + props.workspaceRouteKey !== undefined && | | 350 | + selectedThreadKey !== null && | | 351 | + revealedInspectors.get(props.workspaceRouteKey) !== selectedThreadKey | | 352 | + ) { | | 353 | + const next = new Map<string, string>(); | | 354 | + for (const routeKey of props.workspaceRouteKeys) { | | 355 | + const revealedThreadKey = revealedInspectors.get(routeKey); | | 356 | + if (revealedThreadKey !== undefined) { | | 357 | + next.set(routeKey, revealedThreadKey); | | 358 | + } | | 359 | + } | | 360 | + next.set(props.workspaceRouteKey, selectedThreadKey); | | 361 | + setRevealedInspectors(next); | | 362 | + setFocusedAuxiliaryPaneRole("inspector"); | | 363 | + setFileInspectorPreferredVisible(true); | | 364 | + } | 361 | 365 | const [workspaceInspector, setWorkspaceInspector] = useState<{ | 362 | 366 | readonly render: () => ReactNode; | 363 | 367 | readonly active: boolean; | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/review/ReviewSheet.tsx +2-13Lines changed: 2 additions & 13 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,14 +10,7 @@ import type { AppBarMenuItem } from "../../components/ui/AppBar.types"; | 10 | 10 | import type { ReviewSectionItem } from "./reviewModel"; | 11 | 11 | import { useReviewHeaderPresentation } from "./useReviewHeaderPresentation"; | 12 | 12 | import { Screen, ScreenStack, ScreenStackHeaderConfig } from "react-native-screens"; | 13 | | -import { | 14 | | - type Ref, | 15 | | - type ReactElement, | 16 | | - useEffect, | 17 | | - useImperativeHandle, | 18 | | - useRef, | 19 | | - useState, | 20 | | -} from "react"; | | 13 | +import { type Ref, type ReactElement, useImperativeHandle, useRef, useState } from "react"; | 21 | 14 | import { | 22 | 15 | FlatList, | 23 | 16 | Platform, | @@ -432,7 +425,7 @@ type ReviewSheetProps = StaticScreenProps<{ | 432 | 425 | export function ReviewSheet(props: ReviewSheetProps) { | 433 | 426 | const { nativeReviewDiffStyle } = useAppearanceCodeSurface(); | 434 | 427 | useAdaptiveWorkspacePaneRole("inspector"); | 435 | | - const { panes, showAuxiliaryPane } = useAdaptiveWorkspaceLayout(); | | 428 | + const { panes } = useAdaptiveWorkspaceLayout(); | 436 | 429 | const navigation = useNavigation(); | 437 | 430 | const selectDetail = useSelectWorkspaceDetail(); | 438 | 431 | const insets = useSafeAreaInsets(); | @@ -451,10 +444,6 @@ export function ReviewSheet(props: ReviewSheetProps) { | 451 | 444 | const bottomContentInset = | 452 | 445 | Platform.OS === "ios" ? safeArea.bottom + 8 : Math.max(insets.bottom, 18) + 18; | 453 | 446 |
| 454 | | - useEffect(() => { | 455 | | - showAuxiliaryPane("inspector"); | 456 | | - // oxlint-disable-next-line react/exhaustive-effect-dependencies -- Opening review for another thread reselects its inspector pane. | 457 | | - }, [environmentId, showAuxiliaryPane, threadId]); | 458 | 447 | const { | 459 | 448 | error, | 460 | 449 | reviewSections, | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/reactCompilerCoverage.test.ts +10Lines changed: 10 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -182,6 +182,16 @@ describe("React Compiler coverage", () => { | 182 | 182 | ).toEqual([true]); | 183 | 183 | }); | 184 | 184 |
| | 185 | + // An uncached registration would re-register the workspace inspector on every render. | | 186 | + it("registers the workspace inspector only when its renderer changes", () => { | | 187 | + expect( | | 188 | + compilerCachedCalls( | | 189 | + "src/features/layout/AdaptiveWorkspaceLayout.tsx", | | 190 | + "registerWorkspaceInspector", | | 191 | + ), | | 192 | + ).toEqual([true]); | | 193 | + }); | | 194 | + | 185 | 195 | it("lists only files that exist", () => { | 186 | 196 | expect(Object.keys(KNOWN_BAILOUTS).filter((file) => !sourceFiles.includes(file))).toEqual([]); | 187 | 197 | }); | |
Collapse file Copy file name to clipboard +55Lines changed: 55 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { EnvironmentId, ProjectId, ThreadId } from "@t3tools/contracts"; | | 2 | +import { describe, expect, it, vi } from "vite-plus/test"; | | 3 | + | | 4 | +const state = vi.hoisted(() => ({ | | 5 | + shell: null as { projectId: string; worktreePath: string | null } | null, | | 6 | + detail: null as { thread: { projectId: string } } | null, | | 7 | + detailWorktreePath: null as string | null, | | 8 | + projects: new Map<string, { workspaceRoot: string }>(), | | 9 | +})); | | 10 | + | | 11 | +vi.mock("./entities", () => ({ | | 12 | + useQuietThreadShell: (ref: unknown) => (ref === null ? null : state.shell), | | 13 | + useProject: (ref: { projectId: string } | null) => | | 14 | + ref === null ? null : (state.projects.get(ref.projectId) ?? null), | | 15 | +})); | | 16 | +vi.mock("./threads", async () => { | | 17 | + const { some, none } = await import("effect/Option"); | | 18 | + return { | | 19 | + useEnvironmentThread: (environmentId: unknown, threadId: unknown) => ({ | | 20 | + data: | | 21 | + environmentId !== null && threadId !== null && state.detail ? some(state.detail) : none(), | | 22 | + }), | | 23 | + }; | | 24 | +}); | | 25 | +vi.mock("./use-thread-detail", () => ({ | | 26 | + useThreadWorktreePath: (ref: unknown) => (ref === null ? null : state.detailWorktreePath), | | 27 | + useSelectedThreadWorktreePath: () => null, | | 28 | +})); | | 29 | +vi.mock("./use-thread-selection", () => ({ useThreadSelection: () => ({}) })); | | 30 | + | | 31 | +const { useThreadCwd } = await import("./use-selected-thread-worktree"); | | 32 | + | | 33 | +const ref = { environmentId: EnvironmentId.make("env"), threadId: ThreadId.make("thread") }; | | 34 | + | | 35 | +function setup(input: Partial<Omit<typeof state, "projects">>) { | | 36 | + Object.assign(state, { shell: null, detail: null, detailWorktreePath: null }, input); | | 37 | + state.projects = new Map([[ProjectId.make("project"), { workspaceRoot: "/repo" }]]); | | 38 | +} | | 39 | + | | 40 | +describe("useThreadCwd", () => { | | 41 | + it("falls back to the project root from the loaded detail when the shell is missing", () => { | | 42 | + setup({ detail: { thread: { projectId: "project" } } }); | | 43 | + expect(useThreadCwd(ref)).toBe("/repo"); | | 44 | + }); | | 45 | + | | 46 | + it("prefers the thread worktree over the project root", () => { | | 47 | + setup({ shell: { projectId: "project", worktreePath: "/repo/.worktrees/a" } }); | | 48 | + expect(useThreadCwd(ref)).toBe("/repo/.worktrees/a"); | | 49 | + }); | | 50 | + | | 51 | + it("is null without a thread", () => { | | 52 | + setup({ detail: { thread: { projectId: "project" } } }); | | 53 | + expect(useThreadCwd(null)).toBeNull(); | | 54 | + }); | | 55 | +}); |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/state/use-selected-thread-worktree.ts +31-1Lines changed: 31 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import type { ScopedThreadRef } from "@t3tools/contracts"; | | 2 | +import * as Option from "effect/Option"; | 1 | 3 | import { useMemo } from "react"; | 2 | 4 |
| 3 | | -import { useSelectedThreadWorktreePath } from "./use-thread-detail"; | | 5 | +import { useProject, useQuietThreadShell } from "./entities"; | | 6 | +import { useEnvironmentThread } from "./threads"; | | 7 | +import { useSelectedThreadWorktreePath, useThreadWorktreePath } from "./use-thread-detail"; | 4 | 8 | import { useThreadSelection } from "./use-thread-selection"; | 5 | 9 | import { resolvePreferredThreadWorktreePath } from "../features/terminal/terminalLaunchContext"; | 6 | 10 |
| @@ -22,3 +26,29 @@ export function useSelectedThreadWorktree() { | 22 | 26 | selectedThreadCwd: selectedThreadWorktreePath ?? selectedThreadProject?.workspaceRoot ?? null, | 23 | 27 | }; | 24 | 28 | } | | 29 | + | | 30 | +/** | | 31 | + * Resolves a thread's cwd the way the selected thread's does, for a thread that is not the | | 32 | + * current route's: the shell, or the loaded detail when the shell is missing, picks the project. | | 33 | + */ | | 34 | +export function useThreadCwd(ref: ScopedThreadRef | null): string | null { | | 35 | + const shell = useQuietThreadShell(ref); | | 36 | + const detailState = useEnvironmentThread( | | 37 | + shell === null ? (ref?.environmentId ?? null) : null, | | 38 | + shell === null ? (ref?.threadId ?? null) : null, | | 39 | + ); | | 40 | + const detailThread = Option.getOrNull(detailState.data)?.thread ?? null; | | 41 | + const detailWorktreePath = useThreadWorktreePath(ref); | | 42 | + const projectId = shell?.projectId ?? detailThread?.projectId ?? null; | | 43 | + const project = useProject( | | 44 | + ref === null || projectId === null ? null : { environmentId: ref.environmentId, projectId }, | | 45 | + ); | | 46 | + return ( | | 47 | + resolvePreferredThreadWorktreePath({ | | 48 | + threadShellWorktreePath: shell?.worktreePath ?? null, | | 49 | + threadDetailWorktreePath: detailWorktreePath, | | 50 | + }) ?? | | 51 | + project?.workspaceRoot ?? | | 52 | + null | | 53 | + ); | | 54 | +} |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/state/use-thread-detail.ts +7-5Lines changed: 7 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -92,15 +92,17 @@ export function useSelectedThreadVisibleTurnItems(): OrchestrationV2ThreadProjec | 92 | 92 | const EMPTY_WORKTREE_PATH_ATOM = Atom.make<string | null>(null); | 93 | 93 | const EMPTY_PENDING_REQUESTS_ATOM = Atom.make<PendingThreadRequests | null>(null); | 94 | 94 |
| 95 | | -export function useSelectedThreadWorktreePath() { | 96 | | - const { selectedThreadDetailRef } = useThreadSelection(); | | 95 | +export function useThreadWorktreePath(ref: ScopedThreadRef | null) { | 97 | 96 | return useAtomValue( | 98 | | - selectedThreadDetailRef === null | 99 | | - ? EMPTY_WORKTREE_PATH_ATOM | 100 | | - : environmentThreadDetails.worktreePathAtom(selectedThreadDetailRef), | | 97 | + ref === null ? EMPTY_WORKTREE_PATH_ATOM : environmentThreadDetails.worktreePathAtom(ref), | 101 | 98 | ); | 102 | 99 | } | 103 | 100 |
| | 101 | +export function useSelectedThreadWorktreePath() { | | 102 | + const { selectedThreadDetailRef } = useThreadSelection(); | | 103 | + return useThreadWorktreePath(selectedThreadDetailRef); | | 104 | +} | | 105 | + | 104 | 106 | export function useSelectedThreadPendingRequests() { | 105 | 107 | const { selectedThreadDetailRef } = useThreadSelection(); | 106 | 108 | return useAtomValue( | |
|