diff --git a/apps/mobile/src/Stack.tsx b/apps/mobile/src/Stack.tsx index 601f51008393e..c95e0864ca687 100644 --- a/apps/mobile/src/Stack.tsx +++ b/apps/mobile/src/Stack.tsx @@ -488,7 +488,6 @@ export function workspaceLocationFromState(state: NavigationState) { pathname: path.startsWith("/") ? path : `/${path}`, routeKey: route?.key, routeName: route?.name, - routeKeys: effectiveState.routes.map((stackRoute) => stackRoute.key), }; } @@ -536,7 +535,6 @@ function RootStackLayout(props: { pathname={workspaceLocation.pathname} workspaceRouteKey={workspaceLocation.routeKey} workspaceRouteName={workspaceLocation.routeName} - workspaceRouteKeys={workspaceLocation.routeKeys} selectedPullRequestKey={selectedPullRequestKey(props.state)} > {props.children} diff --git a/apps/mobile/src/features/files/ThreadFilesRouteScreen.tsx b/apps/mobile/src/features/files/ThreadFilesRouteScreen.tsx index 4844063f5d16a..f383c0558ae02 100644 --- a/apps/mobile/src/features/files/ThreadFilesRouteScreen.tsx +++ b/apps/mobile/src/features/files/ThreadFilesRouteScreen.tsx @@ -4,7 +4,7 @@ import { resolveFilesystemReadAccess } from "@t3tools/client-runtime/state/files import { environmentSession } from "../../state/session"; import { NativeStackScreenOptions } from "../../native/StackHeader"; import { StackActions, useNavigation, type StaticScreenProps } from "@react-navigation/native"; -import { useId, useState } from "react"; +import { type ReactNode, useId, useState } from "react"; import { Platform, View } from "react-native"; import { useSafeAreaInsets } from "react-native-safe-area-context"; import Svg, { Defs, LinearGradient, Rect, Stop } from "react-native-svg"; @@ -37,11 +37,7 @@ import { useEnvironmentQuery } from "../../state/query"; import { useEnvironmentPresentation } from "../../state/presentation"; import { projectEnvironment } from "../../state/projects"; import type { AssetUrlFailureReason } from "../../state/asset-url-state"; -import { - useAdaptiveWorkspaceLayout, - useAdaptiveWorkspacePaneRole, - useRegisterWorkspaceInspector, -} from "../layout/AdaptiveWorkspaceLayout"; +import { Inspector, useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout"; import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider"; import { ThreadRouteScreen } from "../threads/ThreadRouteScreen"; import { FilePreviewLoading, FilePreviewNotice } from "./FilePreviewFeedback"; @@ -432,7 +428,6 @@ function FilesToolbarBottomFade() { } export function ThreadFilesTreeScreen(props: ThreadFilesRouteScreenProps) { - useAdaptiveWorkspacePaneRole("inspector"); const navigation = useNavigation(); const { fileInspector, layout } = useAdaptiveWorkspaceLayout(); const [searchQuery, setSearchQuery] = useState(""); @@ -589,7 +584,6 @@ export function ThreadFilesTreeScreen(props: ThreadFilesRouteScreenProps) { } export function ThreadFileScreen(props: ThreadFileRouteScreenProps) { - useAdaptiveWorkspacePaneRole("inspector"); const navigation = useNavigation(); const { fileInspector } = useAdaptiveWorkspaceLayout(); const { appearance, setCodeWordBreak } = useAppearancePreferences(); @@ -778,7 +772,15 @@ export function ThreadFileScreen(props: ThreadFileRouteScreenProps) { renderFiles={() => renderInspector(inspectorHeaderInset)} /> ); - useRegisterWorkspaceInspector(fileInspector.supported ? renderWorkspaceInspector : undefined); + const inspector = fileInspector.supported ? ( + {renderWorkspaceInspector()} + ) : null; + const withInspector = (content: ReactNode) => ( + <> + {inspector} + {content} + + ); const fileMenuActions = (() => { if (relativePath === null) return []; @@ -904,35 +906,41 @@ export function ThreadFileScreen(props: ThreadFileRouteScreenProps) { }; if (environmentId === null || (threadId !== null && selectedThread === null)) { - return ; + return withInspector( + , + ); } if (!canReadFiles) { if (fileAccess.isPending) { - return ; + return withInspector( + , + ); } - return ( - + return withInspector( + , ); } if (cwd === null) { - return ; + return withInspector(); } if (relativePath === null) { - return ( + return withInspector( - + , ); } if (metadataPending) { - return ; + return withInspector( + , + ); } if (directoryPath !== null) { - return ( + return withInspector( - + , ); } const headerSubtitle = fileHeaderSubtitle(projectName, relativePath); - return ( + return withInspector( setFullScreenPreview(null)} /> - + , ); } diff --git a/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx b/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx index 09e7f8a8c449c..6a04f3b6869fc 100644 --- a/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx +++ b/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx @@ -13,7 +13,6 @@ import type { } from "@t3tools/client-runtime/state/shell"; import { EnvironmentId, ThreadId, type SidebarProjectGroupingMode } from "@t3tools/contracts"; import { useAtomValue } from "@effect/atom-react"; -import { useFocusEffect } from "@react-navigation/native"; import { NavigationContext, NavigationRouteContext, useNavigation } from "@react-navigation/native"; import { use, @@ -44,13 +43,11 @@ import { deriveWorkspacePaneLayout, isPrimarySidebarPinned, isWorkspaceListPath, - type WorkspaceAuxiliaryPaneRole, } from "../../lib/layout"; import { scopedThreadKey } from "../../lib/scopedEntities"; import type { ThreadListFilters } from "../../persistence/mobile-preferences"; import { appAtomRegistry } from "../../state/atom-registry"; import { useProjects } from "../../state/entities"; -import { useThreadCwd } from "../../state/use-selected-thread-worktree"; import { environmentThreadShells } from "../../state/threads"; import { mobilePreferencesAtom } from "../../state/preferences"; import { @@ -115,38 +112,39 @@ import { SettingsWorkspaceLayout } from "../settings/SettingsWorkspaceLayout"; export { useAdaptiveWorkspaceLayout }; -export function useAdaptiveWorkspacePaneRole(role: WorkspaceAuxiliaryPaneRole) { - const { activateAuxiliaryPaneRole } = useAdaptiveWorkspaceLayout(); - - useFocusEffect(() => activateAuxiliaryPaneRole(role)); -} - -/** Capture inspector navigation contexts. Register on focus events because frozen blurred screens may never clean up. */ -export function useRegisterWorkspaceInspector(render: (() => ReactNode) | undefined) { +/** + * Shows its children in the workspace's inspector column while this screen is focused. Register on + * focus events because frozen blurred screens may never clean up. + */ +export function Inspector(props: { + readonly children: ReactNode; + /** Opens the column the first time this key registers while its route stays on the stack. */ + readonly revealKey?: string; +}) { const { registerWorkspaceInspector } = useAdaptiveWorkspaceLayout(); const navigation = use(NavigationContext); const route = use(NavigationRouteContext); - - const wrappedRender = (() => { - if (render === undefined) { - return undefined; - } - return () => ( - - {render()} - - ); - })(); + const render = () => ( + + + {props.children} + + + ); + const reveal = + props.revealKey === undefined || route === undefined + ? undefined + : { routeKey: route.key, key: props.revealKey }; const focusedRef = useRef(false); const deactivateRef = useRef<(() => void) | null>(null); const syncRegistration = useEffectEvent(() => { - if (!focusedRef.current || wrappedRender === undefined) { + if (!focusedRef.current) { deactivateRef.current?.(); return; } - deactivateRef.current = registerWorkspaceInspector(wrappedRender); + deactivateRef.current = registerWorkspaceInspector(render, reveal); }); // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- Navigation focus events own the inspector registration lifetime. @@ -173,13 +171,14 @@ export function useRegisterWorkspaceInspector(render: (() => ReactNode) | undefi }; }, [navigation]); - // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- Changed pane content replaces the focused inspector registration. + // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- Changed column content replaces the focused inspector registration. useEffect(() => { if (focusedRef.current) { syncRegistration(); } - // oxlint-disable-next-line react/exhaustive-effect-dependencies -- Changed pane content replaces its existing native workspace registration. - }, [wrappedRender]); + // oxlint-disable-next-line react/exhaustive-effect-dependencies -- Changed column content replaces its existing native workspace registration. + }, [props.children, props.revealKey]); + return null; } export function AdaptiveWorkspaceLayout(props: { @@ -187,7 +186,6 @@ export function AdaptiveWorkspaceLayout(props: { readonly pathname: string; readonly workspaceRouteKey: string | undefined; readonly workspaceRouteName: string | undefined; - readonly workspaceRouteKeys: ReadonlyArray; readonly selectedPullRequestKey?: string | null; }) { const preferencesResult = useAtomValue(mobilePreferencesAtom); @@ -215,7 +213,6 @@ function AdaptiveWorkspaceLayoutContent( readonly pathname: string; readonly workspaceRouteKey: string | undefined; readonly workspaceRouteName: string | undefined; - readonly workspaceRouteKeys: ReadonlyArray; readonly selectedPullRequestKey?: string | null; } & { readonly projectGroupingMode: SidebarProjectGroupingMode; @@ -237,20 +234,13 @@ function AdaptiveWorkspaceLayoutContent( const workspacePage = Platform.OS === "android" && (androidSettingsOpen || workspace?.state.selectedTab === "usage"); const navigation = useNavigation(); - const activeRoleOwner = useRef(null); const [primarySidebarPreferredVisible, setPrimarySidebarPreferredVisible] = useState(true); - const [supplementaryPanePreferredVisible, setSupplementaryPanePreferredVisible] = useState(true); - const [supplementaryPanePreferredWidth, setSupplementaryPanePreferredWidth] = useState< - number | null - >(null); const [fileInspectorPreferredVisible, setFileInspectorPreferredVisible] = useState(true); const [fileInspectorPreferredWidth, setFileInspectorPreferredWidth] = useState( null, ); const [primarySidebarSearchQuery, setPrimarySidebarSearchQuery] = useState(""); const [railOverlay, setRailOverlay] = useState(false); - const [focusedAuxiliaryPaneRole, setFocusedAuxiliaryPaneRole] = - useState(null); // The compiler can't memoize these derivations: they stay live across later hook calls. Fresh // objects here change the workspace context on every render, so every workspace screen // re-renders on any layout state change, and the inspector registration then loops: each @@ -356,17 +346,11 @@ function AdaptiveWorkspaceLayoutContent( }), [fileInspectorPreferredWidth, layout, showPrimarySidebar, shouldRenderPrimarySidebar, width], ); - const auxiliaryPaneRole: WorkspaceAuxiliaryPaneRole = - focusedAuxiliaryPaneRole ?? (/\/files(?:\/|$)/.test(pathname) ? "inspector" : "supplementary"); - const auxiliaryPanePreferredVisible = - !workspacePage && - (auxiliaryPaneRole === "inspector" - ? fileInspectorPreferredVisible - : supplementaryPanePreferredVisible); - const auxiliaryPanePreferredWidth = - auxiliaryPaneRole === "inspector" - ? fileInspectorPreferredWidth - : supplementaryPanePreferredWidth; + const [workspaceInspector, setWorkspaceInspector] = useState<{ + readonly render: () => ReactNode; + readonly active: boolean; + } | null>(null); + const inspectorActive = workspaceInspector?.active ?? false; const panes = useMemo( () => deriveWorkspacePaneLayout({ @@ -374,18 +358,20 @@ function AdaptiveWorkspaceLayoutContent( viewportWidth: width, nativeWorkspace, primarySidebarPreferredVisible: showPrimarySidebar, - auxiliaryPanePreferredVisible, - auxiliaryPaneRole, - auxiliaryPanePreferredWidth: auxiliaryPanePreferredWidth ?? undefined, + // Only a column a screen fills makes room, so a stale preference can't hide the sidebar. + auxiliaryPanePreferredVisible: + !workspacePage && inspectorActive && fileInspectorPreferredVisible, + auxiliaryPanePreferredWidth: fileInspectorPreferredWidth ?? undefined, }), [ - auxiliaryPanePreferredVisible, - auxiliaryPaneRole, - auxiliaryPanePreferredWidth, + fileInspectorPreferredVisible, + fileInspectorPreferredWidth, + inspectorActive, layout, nativeWorkspace, showPrimarySidebar, width, + workspacePage, ], ); const activeThread = parseActiveThreadPath(pathname); @@ -408,44 +394,26 @@ function AdaptiveWorkspaceLayoutContent( selectedThreadRef === null ? null : scopedThreadKey(selectedThreadRef.environmentId, selectedThreadRef.threadId); - const isFilesRoute = props.workspaceRouteName === "ThreadFiles"; - // Same resolution the Files screen uses: without a cwd it shows "Files unavailable" and - // registers no inspector, so revealing would only hide the sidebar beside that screen. - const filesCwd = useThreadCwd(isFilesRoute && fileInspector.supported ? selectedThreadRef : null); - // Opening a review or the files route reveals its inspector once per route and thread. // Routes still on the stack remember their reveal, so going back to one keeps the user's choice. - const revealsInspector = - props.workspaceRouteName === "ThreadReview" || (isFilesRoute && filesCwd !== null); - const [revealedInspectors, setRevealedInspectors] = useState>( - () => new Map(), - ); - if ( - revealsInspector && - props.workspaceRouteKey !== undefined && - selectedThreadKey !== null && - revealedInspectors.get(props.workspaceRouteKey) !== selectedThreadKey - ) { - const next = new Map(); - for (const routeKey of props.workspaceRouteKeys) { - const revealedThreadKey = revealedInspectors.get(routeKey); - if (revealedThreadKey !== undefined) { - next.set(routeKey, revealedThreadKey); - } - } - next.set(props.workspaceRouteKey, selectedThreadKey); - setRevealedInspectors(next); - setFocusedAuxiliaryPaneRole("inspector"); - setFileInspectorPreferredVisible(true); - } - const [workspaceInspector, setWorkspaceInspector] = useState<{ - readonly render: () => ReactNode; - readonly active: boolean; - } | null>(null); + const revealedInspectors = useRef>(new Map()); const workspaceInspectorOwner = useRef(null); - const registerWorkspaceInspector = (render: () => ReactNode) => { + const registerWorkspaceInspector = ( + render: () => ReactNode, + reveal?: { readonly routeKey: string; readonly key: string }, + ) => { const owner = Symbol("workspace-inspector"); workspaceInspectorOwner.current = owner; setWorkspaceInspector({ render, active: true }); + if (reveal && revealedInspectors.current.get(reveal.routeKey) !== reveal.key) { + const state = rootStackState(navigation); + const live = new Set(state?.routes.slice(0, state.index + 1).map((route) => route.key)); + revealedInspectors.current = new Map( + [...revealedInspectors.current, [reveal.routeKey, reveal.key] as const].filter( + ([routeKey]) => live.has(routeKey) || routeKey === reveal.routeKey, + ), + ); + setFileInspectorPreferredVisible(true); + } return () => { // Outgoing screens deactivate after incoming registration; only the current owner may deactivate. @@ -458,19 +426,6 @@ function AdaptiveWorkspaceLayoutContent( const handleWorkspaceInspectorClosed = () => { setWorkspaceInspector((current) => (current !== null && !current.active ? null : current)); }; - const activateAuxiliaryPaneRole = (role: WorkspaceAuxiliaryPaneRole) => { - const owner = Symbol(role); - activeRoleOwner.current = owner; - setFocusedAuxiliaryPaneRole(role); - - return () => { - if (activeRoleOwner.current !== owner) { - return; - } - activeRoleOwner.current = null; - setFocusedAuxiliaryPaneRole(null); - }; - }; const setPrimarySidebarVisible = (visible: boolean) => { if (layout.primarySidebarOverlaysContent) { setOverlaySidebar((current) => ({ ...current, visible })); @@ -508,42 +463,21 @@ function AdaptiveWorkspaceLayoutContent( }; const sidebarCommands = primarySidebarPinned ? [] : (["toggleSidebar"] as const); useHardwareKeyboardCommand(sidebarCommands, handleToggleSidebarCommand); - const showAuxiliaryPane = (role: WorkspaceAuxiliaryPaneRole) => { - if (role === "inspector") { - setFocusedAuxiliaryPaneRole("inspector"); - setFileInspectorPreferredVisible(true); - return; - } - setFocusedAuxiliaryPaneRole("supplementary"); - setSupplementaryPanePreferredVisible(true); - }; + const showInspector = () => setFileInspectorPreferredVisible(true); const handleOpenFilesCommand = () => { const activeThread = parseActiveThreadPath(pathname); if (!layout.usesSplitView || !fileInspector.supported || activeThread === null) { return false; } - showAuxiliaryPane("inspector"); - if (/\/files(?:\/|$)/.test(pathname)) { + showInspector(); + if (props.workspaceRouteName === "ThreadFiles" || props.workspaceRouteName === "ThreadFile") { return true; } navigation.navigate("ThreadFiles", activeThread); return true; }; useHardwareKeyboardCommand("files", handleOpenFilesCommand); - const toggleAuxiliaryPane = () => { - if (auxiliaryPaneRole === "inspector") { - setFileInspectorPreferredVisible((current) => !current); - return; - } - setSupplementaryPanePreferredVisible((current) => !current); - }; - const setAuxiliaryPaneWidth = (nextWidth: number) => { - if (auxiliaryPaneRole === "inspector") { - setFileInspectorPreferredWidth(nextWidth); - return; - } - setSupplementaryPanePreferredWidth(nextWidth); - }; + const toggleAuxiliaryPane = () => setFileInspectorPreferredVisible((current) => !current); /** * The one way to open a workspace tab: replaces the workspace with the tab's list and, when the * window has columns, the page it last showed, keeping any sheet on top. An overlay sidebar @@ -667,10 +601,9 @@ function AdaptiveWorkspaceLayoutContent( }); }; - const inspectorColumnTargetWidth = - workspaceInspector !== null && workspaceInspector.active && panes.auxiliaryPaneVisible - ? (panes.auxiliaryPaneWidth ?? 0) - : 0; + const inspectorColumnTargetWidth = panes.auxiliaryPaneVisible + ? (panes.auxiliaryPaneWidth ?? 0) + : 0; // Android's split content is a rounded card: keep it off the screen edge like the list card. const contentEndGap = Platform.OS === "android" && layout.usesSplitView ? 4 : 0; const contentTargetWidth = layout.usesSplitView @@ -874,15 +807,14 @@ function AdaptiveWorkspaceLayoutContent( primarySidebarSearchQuery, startNewTask: handleStartNewTask, selectDetail: handleSelectDetail, - activateAuxiliaryPaneRole, registerWorkspaceInspector, setPrimarySidebarSearchQuery, - showAuxiliaryPane, + showInspector, toggleAuxiliaryPane, togglePrimarySidebar, setPrimarySidebarVisible, openWorkspaceTab, - setAuxiliaryPaneWidth, + setAuxiliaryPaneWidth: setFileInspectorPreferredWidth, composerKeyboardActive, setComposerEditing, sidebarByOrientation, @@ -1050,7 +982,7 @@ function AdaptiveWorkspaceLayoutContent( active={workspaceInspector?.active ?? false} panes={panes} renderInspector={workspaceInspector?.render} - setAuxiliaryPaneWidth={setAuxiliaryPaneWidth} + setAuxiliaryPaneWidth={setFileInspectorPreferredWidth} onClosed={handleWorkspaceInspectorClosed} /> {shouldRenderNavigationRail && navigationRailWidth > 0 ? ( diff --git a/apps/mobile/src/features/layout/adaptive-workspace-context.ts b/apps/mobile/src/features/layout/adaptive-workspace-context.ts index a22459e6ecdb4..2974633b73a42 100644 --- a/apps/mobile/src/features/layout/adaptive-workspace-context.ts +++ b/apps/mobile/src/features/layout/adaptive-workspace-context.ts @@ -10,7 +10,6 @@ import { deriveWorkspacePaneLayout, type FileInspectorPaneLayout, type Layout, - type WorkspaceAuxiliaryPaneRole, type WorkspacePaneLayout, } from "../../lib/layout"; @@ -22,10 +21,12 @@ interface AdaptiveWorkspaceContextValue { readonly startNewTask: () => void; /** Use `useSelectWorkspaceDetail`, which also works outside the layout. */ readonly selectDetail?: (detail: WorkspaceDetail, sheet?: WorkspaceDetailSheet) => void; - readonly activateAuxiliaryPaneRole: (role: WorkspaceAuxiliaryPaneRole) => () => void; - readonly registerWorkspaceInspector: (render: () => ReactNode) => () => void; + readonly registerWorkspaceInspector: ( + render: () => ReactNode, + reveal?: { readonly routeKey: string; readonly key: string }, + ) => () => void; readonly setPrimarySidebarSearchQuery: (query: string) => void; - readonly showAuxiliaryPane: (role: WorkspaceAuxiliaryPaneRole) => void; + readonly showInspector: () => void; readonly toggleAuxiliaryPane: () => void; readonly togglePrimarySidebar: () => void; readonly setPrimarySidebarVisible: (visible: boolean) => void; @@ -66,10 +67,9 @@ export const AdaptiveWorkspaceContext = createContext undefined, - activateAuxiliaryPaneRole: () => () => undefined, registerWorkspaceInspector: () => () => undefined, setPrimarySidebarSearchQuery: () => undefined, - showAuxiliaryPane: () => undefined, + showInspector: () => undefined, toggleAuxiliaryPane: () => undefined, togglePrimarySidebar: () => undefined, setPrimarySidebarVisible: () => undefined, diff --git a/apps/mobile/src/features/review/ReviewSheet.tsx b/apps/mobile/src/features/review/ReviewSheet.tsx index 05706adf828d8..6d591f7796101 100644 --- a/apps/mobile/src/features/review/ReviewSheet.tsx +++ b/apps/mobile/src/features/review/ReviewSheet.tsx @@ -37,11 +37,7 @@ import { useUniwindTheme } from "../../lib/useUniwindTheme"; import { useThreadDraftForThread } from "../../state/use-thread-composer-state"; import { EnvironmentConnectionNotice } from "../connection/EnvironmentConnectionNotice"; import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider"; -import { - useAdaptiveWorkspaceLayout, - useAdaptiveWorkspacePaneRole, - useRegisterWorkspaceInspector, -} from "../layout/AdaptiveWorkspaceLayout"; +import { Inspector, useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout"; import { useSelectedThreadWorktree } from "../../state/use-selected-thread-worktree"; import { useReviewCacheForThread } from "./reviewState"; import { @@ -427,7 +423,6 @@ type ReviewSheetProps = StaticScreenProps<{ export function ReviewSheet(props: ReviewSheetProps) { const reduceMotion = useReduceMotionEnabled(); const { nativeReviewDiffStyle } = useAppearanceCodeSurface(); - useAdaptiveWorkspacePaneRole("inspector"); const { panes } = useAdaptiveWorkspaceLayout(); const navigation = useNavigation(); const selectDetail = useSelectWorkspaceDetail(); @@ -634,7 +629,6 @@ export function ReviewSheet(props: ReviewSheetProps) { selectedSection !== null && parsedDiff.kind === "files" && NativeReviewDiffView !== null; - useRegisterWorkspaceInspector(showChangedFilesPane ? renderInspector : undefined); const showChangedFilesToggle = panes.supportsAuxiliaryPane && showChangedFilesPane; const listHeader = (() => { @@ -678,6 +672,9 @@ export function ReviewSheet(props: ReviewSheetProps) { return ( <> + {showChangedFilesPane ? ( + {renderInspector()} + ) : null} { - if ( - props.inspectorPresentation === undefined && - fileInspector.supported && - selectedThreadCwd === null && - inspectorMode === null && - panes.auxiliaryPaneVisible - ) { - toggleAuxiliaryPane(); - } - }, [ - fileInspector.supported, - inspectorMode, - panes.auxiliaryPaneVisible, - props.inspectorPresentation, - selectedThreadCwd, - toggleAuxiliaryPane, - ]); - - const revealPreview = useEffectEvent(() => showAuxiliaryPane("inspector")); + const revealPreview = useEffectEvent(() => showInspector()); // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- opens the workspace navigator's inspector pane when route params bring a preview target useEffect(() => { if (previewTarget) revealPreview(); @@ -588,7 +559,7 @@ function ThreadRouteContent( } navigation.setParams({ inspector: undefined }); setChosenInspectorMode("git"); - showAuxiliaryPane("inspector"); + showInspector(); }; const handleOpenFilesInspector = () => { if (selectedThread === null || selectedThreadCwd === null) { @@ -603,7 +574,7 @@ function ThreadRouteContent( } navigation.setParams({ inspector: undefined }); setChosenInspectorMode(props.renderInspector === undefined ? "files" : "route"); - showAuxiliaryPane("inspector"); + showInspector(); }; const handleToggleInspector = () => { if (inspectorMode === null) { @@ -678,9 +649,7 @@ function ThreadRouteContent( renderRoute={props.renderInspector ? renderRouteInspector : undefined} /> ); - const activeInspectorRenderer = - props.inspectorPresentation || inspectorMode === null ? undefined : renderInspectorStack; - useRegisterWorkspaceInspector(activeInspectorRenderer); + const showsInspector = !props.inspectorPresentation && inspectorMode !== null; const handleOpenConnectionEditor = () => { void navigation.navigate("Connections"); @@ -1128,7 +1097,18 @@ function ThreadRouteContent( return ( <> - {activeInspectorRenderer ? : null} + {showsInspector ? ( + + {renderInspectorStack()} + + ) : null} {renderThreadRouteBody()} diff --git a/apps/mobile/src/features/threads/thread-inspector-navigation.test.tsx b/apps/mobile/src/features/threads/thread-inspector-navigation.test.tsx index cd148bff2d969..0f7e45ca4ca28 100644 --- a/apps/mobile/src/features/threads/thread-inspector-navigation.test.tsx +++ b/apps/mobile/src/features/threads/thread-inspector-navigation.test.tsx @@ -221,7 +221,7 @@ it("keeps a focused inspector registered across renders and updates its content" }, ); const exports: { - useRegisterWorkspaceInspector?: (render: (() => React.ReactNode) | undefined) => void; + Inspector?: (props: { readonly children: React.ReactNode }) => null; } = {}; const load = (name: string) => { if (name === "react" || name.startsWith("react/")) return requireMobile(name); @@ -233,22 +233,19 @@ it("keeps a focused inspector registered across renders and updates its content" return { NavigationContext: navigationContext, NavigationRouteContext: routeContext, - useFocusEffect: (callback: () => (() => void) | undefined) => - React.useEffect(callback, [callback]), }; return {}; }; new Function("require", "exports", compiled.code)(load, exports); - const useRegisterWorkspaceInspector = exports.useRegisterWorkspaceInspector!; - function Screen({ render }: { render: (() => React.ReactNode) | undefined }) { - useRegisterWorkspaceInspector(render); - return null; + const Inspector = exports.Inspector!; + function Screen({ content }: { content: string | undefined }) { + return content === undefined ? null : {content}; } const root = createRoot(document.createElement("div")); using _root = { [Symbol.dispose]: () => act(() => root.unmount()) }; - const render = (content: (() => React.ReactNode) | undefined) => - act(() => root.render()); - const first = () => "first"; + const render = (content: string | undefined) => + act(() => root.render()); + const first = "first"; render(first); registerWorkspaceInspector.mockClear(); deactivate.mockClear(); @@ -256,7 +253,7 @@ it("keeps a focused inspector registered across renders and updates its content" render(first); expect(registerWorkspaceInspector).not.toHaveBeenCalled(); expect(deactivate).not.toHaveBeenCalled(); - const second = () => "second"; + const second = "second"; render(second); expect(registerWorkspaceInspector).toHaveBeenCalledTimes(1); const paneContainer = document.createElement("div"); diff --git a/apps/mobile/src/lib/layout.test.ts b/apps/mobile/src/lib/layout.test.ts index 0eaed72c1979e..76583340aba6f 100644 --- a/apps/mobile/src/lib/layout.test.ts +++ b/apps/mobile/src/lib/layout.test.ts @@ -151,7 +151,6 @@ describe("deriveWorkspacePaneLayout", () => { nativeWorkspace: true, primarySidebarPreferredVisible, auxiliaryPanePreferredVisible: true, - auxiliaryPaneRole: "inspector", }), ).toMatchObject({ primarySidebarVisible: primarySidebarPreferredVisible, @@ -170,7 +169,6 @@ describe("deriveWorkspacePaneLayout", () => { viewportWidth: 1_024, primarySidebarPreferredVisible: false, auxiliaryPanePreferredVisible: true, - auxiliaryPaneRole: "inspector", }), ).toMatchObject({ primarySidebarVisible: false, diff --git a/apps/mobile/src/lib/layout.ts b/apps/mobile/src/lib/layout.ts index 4155d834ba24d..e41ade6e7f59b 100644 --- a/apps/mobile/src/lib/layout.ts +++ b/apps/mobile/src/lib/layout.ts @@ -12,7 +12,6 @@ const SPLIT_LAYOUT_MIN_HEIGHT = 600; const SPLIT_SIDEBAR_MIN_WIDTH = 280; const SPLIT_SIDEBAR_DEFAULT_MAX_WIDTH = 380; -const AUXILIARY_PANE_MIN_CONTENT_WIDTH = 960; export const CHAT_CONTENT_MAX_WIDTH = 960; // Limit Android reading width for wide foldables and keyboard-open split views. export const ANDROID_READING_MAX_WIDTH = 640; @@ -98,8 +97,6 @@ export function deriveThreadFeedInitialContentInset(input: { return { bottom: Math.max(0, input.bottomContentInset) }; } -export type WorkspaceAuxiliaryPaneRole = "supplementary" | "inspector"; - export function deriveLayout(input: { readonly width: number; readonly height: number; @@ -207,76 +204,46 @@ export function deriveWorkspacePaneLayout(input: { readonly nativeWorkspace?: boolean; readonly primarySidebarPreferredVisible: boolean; readonly auxiliaryPanePreferredVisible: boolean; - readonly auxiliaryPaneRole?: WorkspaceAuxiliaryPaneRole; readonly auxiliaryPanePreferredWidth?: number; }): WorkspacePaneLayout { const viewportWidth = Math.max(0, input.viewportWidth); - const auxiliaryPaneRole = input.auxiliaryPaneRole ?? "supplementary"; const preferredPrimarySidebarVisible = input.layout.usesSplitView && input.primarySidebarPreferredVisible; const preferredPrimarySidebarWidth = preferredPrimarySidebarVisible && !input.layout.primarySidebarOverlaysContent ? (input.layout.listPaneWidth ?? 0) + (input.layout.listPaneGap ?? 0) : 0; - - if (auxiliaryPaneRole === "inspector") { - const fileInspector = deriveFileInspectorPaneLayout({ - layout: input.layout, - viewportWidth, - preferredWidth: input.auxiliaryPanePreferredWidth, - reservedLeadingWidth: preferredPrimarySidebarWidth, - }); - const auxiliaryPaneVisible = fileInspector.supported && input.auxiliaryPanePreferredVisible; - const primarySidebarSuppressedByAuxiliary = - !input.nativeWorkspace && - preferredPrimarySidebarVisible && - !input.layout.primarySidebarOverlaysContent && - auxiliaryPaneVisible && - fileInspector.width !== null && - input.layout.listPaneWidth !== null && - viewportWidth - - input.layout.listPaneWidth - - (input.layout.listPaneGap ?? 0) - - fileInspector.width < - FILE_INSPECTOR_MIN_MAIN_WIDTH; - const primarySidebarVisible = - preferredPrimarySidebarVisible && !primarySidebarSuppressedByAuxiliary; - const primarySidebarWidth = primarySidebarVisible ? preferredPrimarySidebarWidth : 0; - - return { - primarySidebarVisible, - primarySidebarWhenExpanded: input.primarySidebarPreferredVisible, - primarySidebarSuppressedByAuxiliary, - contentPaneWidth: Math.max(0, viewportWidth - primarySidebarWidth), - supportsAuxiliaryPane: fileInspector.supported, - auxiliaryPaneVisible, - auxiliaryPaneWidth: fileInspector.width, - }; - } - - const contentPaneWidth = Math.max(0, viewportWidth - preferredPrimarySidebarWidth); - const supportsAuxiliaryPane = - input.layout.usesSplitView && contentPaneWidth >= AUXILIARY_PANE_MIN_CONTENT_WIDTH; - const auxiliaryPaneVisible = supportsAuxiliaryPane && input.auxiliaryPanePreferredVisible; - const defaultAuxiliaryPaneWidth = clamp( - Math.round(contentPaneWidth * 0.28), - AUXILIARY_PANE_MIN_WIDTH, - AUXILIARY_PANE_DEFAULT_MAX_WIDTH, - ); + const fileInspector = deriveFileInspectorPaneLayout({ + layout: input.layout, + viewportWidth, + preferredWidth: input.auxiliaryPanePreferredWidth, + reservedLeadingWidth: preferredPrimarySidebarWidth, + }); + const auxiliaryPaneVisible = fileInspector.supported && input.auxiliaryPanePreferredVisible; + const primarySidebarSuppressedByAuxiliary = + !input.nativeWorkspace && + preferredPrimarySidebarVisible && + !input.layout.primarySidebarOverlaysContent && + auxiliaryPaneVisible && + fileInspector.width !== null && + input.layout.listPaneWidth !== null && + viewportWidth - + input.layout.listPaneWidth - + (input.layout.listPaneGap ?? 0) - + fileInspector.width < + FILE_INSPECTOR_MIN_MAIN_WIDTH; + const primarySidebarVisible = + preferredPrimarySidebarVisible && !primarySidebarSuppressedByAuxiliary; + const primarySidebarWidth = primarySidebarVisible ? preferredPrimarySidebarWidth : 0; return { - primarySidebarVisible: preferredPrimarySidebarVisible, + primarySidebarVisible, primarySidebarWhenExpanded: input.primarySidebarPreferredVisible, - primarySidebarSuppressedByAuxiliary: false, - contentPaneWidth, - supportsAuxiliaryPane, + primarySidebarSuppressedByAuxiliary, + contentPaneWidth: Math.max(0, viewportWidth - primarySidebarWidth), + supportsAuxiliaryPane: fileInspector.supported, auxiliaryPaneVisible, - auxiliaryPaneWidth: supportsAuxiliaryPane - ? constrainAuxiliaryPaneWidth({ - preferredWidth: input.auxiliaryPanePreferredWidth ?? defaultAuxiliaryPaneWidth, - availableWidth: contentPaneWidth, - }) - : null, + auxiliaryPaneWidth: fileInspector.width, }; }