GeezerVison is showing github.com — fix(mobile): a Git confirmation only reuses the thread route that sho… · pingdotgg/t3code@31ff92c
File treeExpand file treeCollapse file tree Open diff view settings apps/mobile/src/features/threads
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/git/GitConfirmSheet.tsx +6-4Lines changed: 6 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,7 +3,7 @@ import { sourceControlClients } from "@t3tools/client-runtime/source-control-cli | 3 | 3 | import { resolveAutoFeatureBranchName } from "@t3tools/shared/git"; | 4 | 4 | import * as Arr from "effect/Array"; | 5 | 5 | import * as Result from "effect/Result"; | 6 | | -import { StackActions, useNavigation, type StaticScreenProps } from "@react-navigation/native"; | | 6 | +import { useNavigation, type StaticScreenProps } from "@react-navigation/native"; | 7 | 7 | import { useGT, useMessages } from "gt-react-native"; | 8 | 8 | import { useCallback, useMemo } from "react"; | 9 | 9 | import { View } from "react-native"; | @@ -20,6 +20,7 @@ import { | 20 | 20 | type GitRepositoryRouteParams, | 21 | 21 | } from "../../../state/thread-git-target"; | 22 | 22 | import { vcsEnvironment } from "../../../state/vcs"; | | 23 | +import { useReturnToThread } from "../thread-inspector-navigation"; | 23 | 24 | import { SheetActionButton } from "./gitSheetComponents"; | 24 | 25 |
| 25 | 26 | type GitConfirmSheetProps = StaticScreenProps< | @@ -38,6 +39,7 @@ export function GitConfirmSheet(props: GitConfirmSheetProps) { | 38 | 39 | const gt = useGT(); | 39 | 40 | const messages = useMessages(); | 40 | 41 | const navigation = useNavigation(); | | 42 | + const returnToThread = useReturnToThread(); | 41 | 43 | const repository = gitRepositoryTargetFromRoute(props.route.params); | 42 | 44 | const gitState = useSelectedThreadGitState(repository); | 43 | 45 | const gitActions = useSelectedThreadGitActions(repository); | @@ -89,7 +91,7 @@ export function GitConfirmSheet(props: GitConfirmSheetProps) { | 89 | 91 |
| 90 | 92 | const continuePendingAction = async () => { | 91 | 93 | if (!canWriteSourceControl || !confirmAction) return; | 92 | | - navigation.dispatch(StackActions.popTo("Thread", { environmentId, threadId }, { merge: true })); | | 94 | + returnToThread({ environmentId, threadId }); | 93 | 95 | await gitActions.onRunSelectedThreadGitAction({ | 94 | 96 | action: confirmAction, | 95 | 97 | ...(params.commitMessage ? { commitMessage: params.commitMessage } : {}), | @@ -99,7 +101,7 @@ export function GitConfirmSheet(props: GitConfirmSheetProps) { | 99 | 101 |
| 100 | 102 | const movePendingActionToFeatureBranch = useCallback(async () => { | 101 | 103 | if (!canCreateFeatureBranch || !confirmAction) return; | 102 | | - navigation.dispatch(StackActions.popTo("Thread", { environmentId, threadId }, { merge: true })); | | 104 | + returnToThread({ environmentId, threadId }); | 103 | 105 |
| 104 | 106 | if (includesCommit) { | 105 | 107 | await gitActions.onRunSelectedThreadGitAction({ | @@ -131,7 +133,7 @@ export function GitConfirmSheet(props: GitConfirmSheetProps) { | 131 | 133 | gitState.selectedThreadBranches, | 132 | 134 | includesCommit, | 133 | 135 | params, | 134 | | - navigation, | | 136 | + returnToThread, | 135 | 137 | environmentId, | 136 | 138 | threadId, | 137 | 139 | ]); | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/thread-inspector-navigation.test.tsx +39-2Lines changed: 39 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -29,7 +29,7 @@ vi.mock("@react-navigation/native", async () => { | 29 | 29 | }; | 30 | 30 | }); | 31 | 31 |
| 32 | | -import { useOpenThreadInspector } from "./thread-inspector-navigation"; | | 32 | +import { useOpenThreadInspector, useReturnToThread } from "./thread-inspector-navigation"; | 33 | 33 | import { useOpenLinkedThread, useOpenLinkedThreadRead } from "./useOpenLinkedThread"; | 34 | 34 |
| 35 | 35 | const requireNavigation = NodeModule.createRequire( | @@ -45,7 +45,15 @@ function setup(fromAgents: boolean, fullscreen = false, inspectorSupported = tru | 45 | 45 | (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true; | 46 | 46 | const router = StackRouter({}); | 47 | 47 | const options = { | 48 | | - routeNames: ["Home", "Thread", "ThreadAgents", "ThreadInspectorFullscreen", "LinkedThread"], | | 48 | + routeNames: [ | | 49 | + "Home", | | 50 | + "Thread", | | 51 | + "ThreadAgents", | | 52 | + "ThreadInspectorFullscreen", | | 53 | + "LinkedThread", | | 54 | + "ThreadReview", | | 55 | + "GitConfirm", | | 56 | + ], | 49 | 57 | routeParamList: {}, | 50 | 58 | routeGetIdList: {}, | 51 | 59 | }; | @@ -70,14 +78,17 @@ function setup(fromAgents: boolean, fullscreen = false, inspectorSupported = tru | 70 | 78 | let openInspector: ReturnType<typeof useOpenThreadInspector>; | 71 | 79 | let openLinkedThread: ReturnType<typeof useOpenLinkedThread>; | 72 | 80 | let openLinkedThreadRead: ReturnType<typeof useOpenLinkedThreadRead>; | | 81 | + let returnToThread: ReturnType<typeof useReturnToThread>; | 73 | 82 | function Probe() { | 74 | 83 | const open = useOpenThreadInspector(); | 75 | 84 | const openLinked = useOpenLinkedThread(); | 76 | 85 | const openLinkedRead = useOpenLinkedThreadRead(); | | 86 | + const returnTo = useReturnToThread(); | 77 | 87 | useLayoutEffect(() => { | 78 | 88 | openInspector = open; | 79 | 89 | openLinkedThread = openLinked; | 80 | 90 | openLinkedThreadRead = openLinkedRead; | | 91 | + returnToThread = returnTo; | 81 | 92 | }); | 82 | 93 | return null; | 83 | 94 | } | @@ -103,6 +114,9 @@ function setup(fromAgents: boolean, fullscreen = false, inspectorSupported = tru | 103 | 114 | openLinkedRead(...input: Parameters<typeof openLinkedThreadRead>) { | 104 | 115 | act(() => openLinkedThreadRead(...input)); | 105 | 116 | }, | | 117 | + returnTo(thread: Parameters<typeof returnToThread>[0]) { | | 118 | + act(() => returnToThread(thread)); | | 119 | + }, | 106 | 120 | [Symbol.dispose]() { | 107 | 121 | act(() => root.unmount()); | 108 | 122 | }, | @@ -190,6 +204,29 @@ it.each([ | 190 | 204 | }, | 191 | 205 | ); | 192 | 206 |
| | 207 | +it.each([ | | 208 | + { confirmFrom: "parent", routes: ["Home", "Thread"] }, | | 209 | + // A side thread's review, opened from the parent's inspector, sits above the parent's route. | | 210 | + { confirmFrom: "child", routes: ["Home", "Thread", "ThreadReview", "Thread"] }, | | 211 | +])( | | 212 | + "returns from a Git confirmation to the $confirmFrom thread without replacing another", | | 213 | + ({ confirmFrom, routes }) => { | | 214 | + using screen = setup(false); | | 215 | + const inspector = { type: "device", ...screen.source } as const; | | 216 | + screen.open(inspector); | | 217 | + const thread = { ...screen.source, threadId: confirmFrom }; | | 218 | + if (confirmFrom !== "parent") screen.dispatch(StackActions.push("ThreadReview", thread)); | | 219 | + screen.dispatch(StackActions.push("GitConfirm", thread)); | | 220 | + screen.returnTo(thread); | | 221 | + expect(screen.state.routes.map((route) => route.name)).toEqual(routes); | | 222 | + expect(screen.state.routes[1]).toMatchObject({ | | 223 | + key: screen.parentKey, | | 224 | + params: { ...screen.source, prompt: "retained prompt", inspector }, | | 225 | + }); | | 226 | + expect(screen.state.routes.at(-1)?.params).toMatchObject(thread); | | 227 | + }, | | 228 | +); | | 229 | + | 193 | 230 | it("switches between subagents and devices in the same parent route", () => { | 194 | 231 | using screen = setup(false); | 195 | 232 | screen.open({ type: "thread", environmentId: screen.source.environmentId, threadId: "child" }); | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/thread-inspector-navigation.ts +29-9Lines changed: 29 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -41,19 +41,39 @@ export function useOpenThreadInspector() { | 41 | 41 | if (presentation === "full-screen") return false; | 42 | 42 | if (openInInspector) openInInspector(target); | 43 | 43 | else { | 44 | | - const parent = navigation.getState()?.routes.findLast((route) => route.name === "Thread"); | 45 | | - if ( | 46 | | - !parent?.params || | 47 | | - !("environmentId" in parent.params) || | 48 | | - parent.params.environmentId !== source.environmentId || | 49 | | - !("threadId" in parent.params) || | 50 | | - parent.params.threadId !== source.threadId | 51 | | - ) | 52 | | - return false; | | 44 | + if (!isNearestThreadRoute(navigation.getState(), source)) return false; | 53 | 45 | navigation.dispatch( | 54 | 46 | StackActions.popTo("Thread", { ...source, inspector: target }, { merge: true }), | 55 | 47 | ); | 56 | 48 | } | 57 | 49 | return true; | 58 | 50 | }; | 59 | 51 | } | | 52 | + | | 53 | +/** Closes the screens above `thread`, or opens it when the nearest thread route is another one. */ | | 54 | +export function useReturnToThread() { | | 55 | + const navigation = useNavigation(); | | 56 | + return (thread: { readonly environmentId: string; readonly threadId: string }) => | | 57 | + navigation.dispatch( | | 58 | + isNearestThreadRoute(navigation.getState(), thread) | | 59 | + ? StackActions.popTo("Thread", thread, { merge: true }) | | 60 | + : StackActions.replace("Thread", thread), | | 61 | + ); | | 62 | +} | | 63 | + | | 64 | +// `Thread` has no `getId`, so `popTo("Thread")` lands on the nearest one whatever thread it shows. | | 65 | +function isNearestThreadRoute( | | 66 | + state: | | 67 | + | { readonly routes: ReadonlyArray<{ readonly name: string; readonly params?: object }> } | | 68 | + | undefined, | | 69 | + thread: { readonly environmentId: string; readonly threadId: string }, | | 70 | +) { | | 71 | + const params = state?.routes.findLast((route) => route.name === "Thread")?.params; | | 72 | + return ( | | 73 | + params !== undefined && | | 74 | + "environmentId" in params && | | 75 | + params.environmentId === thread.environmentId && | | 76 | + "threadId" in params && | | 77 | + params.threadId === thread.threadId | | 78 | + ); | | 79 | +} |
|