Skip to content
TypeScript

refactor(mobile): thread inspector mode is derived, not synced (#25682)

Julius Marmingea2398c2ce33c
diff --git a/apps/mobile/src/features/threads/ThreadRouteScreen.tsx b/apps/mobile/src/features/threads/ThreadRouteScreen.tsx
index 0287a6975f7..4fe22d6cd5f 100644
--- a/apps/mobile/src/features/threads/ThreadRouteScreen.tsx
+++ b/apps/mobile/src/features/threads/ThreadRouteScreen.tsx
@@ -111,11 +111,6 @@ import {
import type { ThreadInspectorTarget } from "./thread-inspector-navigation";
import { useSelectWorkspaceDetail } from "../workspace/useSelectWorkspaceDetail";
-interface ThreadInspectorSelection {
- readonly routeThreadIdentity: string | null;
- readonly mode: ThreadInspectorMode;
-}
-
function InspectorPaneRoleActivation() {
useAdaptiveWorkspacePaneRole("inspector");
return null;
@@ -435,19 +430,21 @@ function ThreadRouteContent(
const threadId = firstRouteParam(params.threadId);
const routeThreadIdentity =
environmentIdRaw !== null && threadId !== null ? `${environmentIdRaw}:${threadId}` : null;
- const [inspectorSelection, setInspectorSelection] = useState<ThreadInspectorSelection | null>(
- () => (props.renderInspector ? { routeThreadIdentity, mode: "route" } : null),
- );
+ // The chosen mode survives thread switches; "route" only applies while the route
+ // supplies an inspector, which is also the default whenever it does.
+ const [chosenInspectorMode, setChosenInspectorMode] = useState<ThreadInspectorMode | null>(null);
const previewTarget = props.inspectorPresentation ? undefined : params.inspector;
const inspectorMode = (() => {
if (previewTarget) return "preview";
- if (inspectorSelection?.routeThreadIdentity === routeThreadIdentity) {
- if (inspectorSelection.mode === "files" && selectedThreadCwd === null) {
- return null;
- }
- return inspectorSelection.mode;
- }
- return null;
+ const mode =
+ props.renderInspector === undefined
+ ? chosenInspectorMode === "route"
+ ? null
+ : chosenInspectorMode
+ : chosenInspectorMode === null || chosenInspectorMode === "route"
+ ? "route"
+ : chosenInspectorMode;
+ return mode === "files" && selectedThreadCwd === null ? null : mode;
})();
useEffect(() => {
if (
@@ -468,24 +465,6 @@ function ThreadRouteContent(
toggleAuxiliaryPane,
]);
- useEffect(() => {
- // oxlint-disable-next-line react/set-state-in-effect -- Inspector selection follows route ownership but keeps an inspector the user opened.
- setInspectorSelection((current) => {
- if (props.renderInspector === undefined) {
- if (current === null || current.mode === "route") {
- return null;
- }
- return { ...current, routeThreadIdentity };
- }
-
- if (current === null || current.mode === "route") {
- return { routeThreadIdentity, mode: "route" };
- }
-
- return { ...current, routeThreadIdentity };
- });
- }, [props.renderInspector, routeThreadIdentity]);
-
const revealPreview = useEffectEvent(() => showAuxiliaryPane("inspector"));
useEffect(() => {
if (previewTarget) revealPreview();
@@ -552,7 +531,7 @@ function ThreadRouteContent(
return;
}
navigation.setParams({ inspector: undefined });
- setInspectorSelection({ routeThreadIdentity, mode: "git" });
+ setChosenInspectorMode("git");
showAuxiliaryPane("inspector");
};
const handleOpenFilesInspector = () => {
@@ -567,10 +546,7 @@ function ThreadRouteContent(
return;
}
navigation.setParams({ inspector: undefined });
- setInspectorSelection({
- routeThreadIdentity,
- mode: props.renderInspector === undefined ? "files" : "route",
- });
+ setChosenInspectorMode(props.renderInspector === undefined ? "files" : "route");
showAuxiliaryPane("inspector");
};
const handleToggleInspector = () => {