|
1 | 1 | import type { NavigationState } from "@react-navigation/native"; |
2 | 2 | import { resetRootStack, type RootStackNavigation } from "./root-stack-reset"; |
3 | 3 |
|
4 | | -const detailIdentity = { |
5 | | - Thread: ["environmentId", "threadId"], |
6 | | - PullRequest: ["environmentId", "projectId", "repository", "number", "host"], |
7 | | -} as const; |
8 | | - |
9 | | -// Back returns to the detail a chat, PR, or subagent was opened from. A copy of the current |
10 | | -// detail directly below it, which confirming a Git action from the inline inspector can leave, |
11 | | -// is not a destination, so Back returns to the list instead. |
12 | 4 | function androidWorkspaceBackReturnsToDetail(state: NavigationState) { |
13 | 5 | const current = state.routes[state.index]; |
14 | 6 | const previous = state.routes[state.index - 1]; |
15 | 7 | if (current?.name !== "Thread" && current?.name !== "PullRequest") return false; |
16 | | - if (previous?.name === "PullRequestFile") return true; |
17 | | - if (previous?.name !== "Thread" && previous?.name !== "PullRequest") return false; |
18 | | - if (current.name !== previous.name) return true; |
19 | | - const currentParams = current.params as Readonly<Record<string, unknown>> | undefined; |
20 | | - const previousParams = previous.params as Readonly<Record<string, unknown>> | undefined; |
21 | | - return detailIdentity[previous.name].some( |
22 | | - (key) => currentParams?.[key] !== previousParams?.[key], |
23 | | - ); |
| 8 | + if (previous?.name === "PullRequest" || previous?.name === "PullRequestFile") return true; |
| 9 | + if (previous?.name !== "Thread") return false; |
| 10 | + if (current.name === "PullRequest") return true; |
| 11 | + // Git actions can leave a duplicate Thread route that should return to its list. |
| 12 | + const params = current.params as ReactNavigation.RootParamList["Thread"] | undefined; |
| 13 | + return params !== undefined && !parentThreadIsBelow(state, params); |
24 | 14 | } |
25 | 15 |
|
26 | 16 | /** The root stack with only the workspace list. */ |
|
0 commit comments