GeezerVison is showing github.com — fix(mobile): Back from a sub-agent opened from its delegator returns … · only21mil/t3code@d53873b
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/components/ComposerEditor.tsx +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,7 +3,6 @@ import { ComposerContextId } from "@t3tools/contracts"; | 3 | 3 | import { useAtomValue } from "@effect/atom-react"; | 4 | 4 | import { AsyncResult } from "effect/reactivity"; | 5 | 5 | import { settlePromise, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime"; | 6 | | -import { useNavigation } from "@react-navigation/native"; | 7 | 6 | import { useEffect, useRef, useState } from "react"; | 8 | 7 | import type { EnvironmentId } from "@t3tools/contracts"; | 9 | 8 | import { encodeComposerContextFragment } from "@t3tools/shared/composerContextClipboard"; | @@ -24,6 +23,7 @@ import { | 24 | 23 | } from "../state/use-composer-drafts"; | 25 | 24 | import { importComposerContextClipboard } from "../lib/composerContextClipboard"; | 26 | 25 | import { mobilePreferencesAtom } from "../state/preferences"; | | 26 | +import { useOpenLinkedThread } from "../features/threads/useOpenLinkedThread"; | 27 | 27 | import { ComposerContextSheet } from "./ComposerContextSheet"; | 28 | 28 | import { AppText as Text } from "./ui/AppText"; | 29 | 29 | import { | @@ -154,7 +154,7 @@ export function ComposerEditor({ | 154 | 154 | }), | 155 | 155 | }) | 156 | 156 | : ""; | 157 | | - const navigation = useNavigation(); | | 157 | + const openLinkedThread = useOpenLinkedThread(); | 158 | 158 | const selectedReference = selected | 159 | 159 | ? collectComposerContextReferences(selected.source)[0] | 160 | 160 | : undefined; | @@ -236,7 +236,7 @@ export function ComposerEditor({ | 236 | 236 | : {})} | 237 | 237 | onOpenThread={(thread) => { | 238 | 238 | setSelected(null); | 239 | | - navigation.navigate("Thread", { | | 239 | + openLinkedThread({ | 240 | 240 | environmentId: String(thread.environmentId), | 241 | 241 | threadId: String(thread.threadId), | 242 | 242 | }); | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/ThreadDetailScreen.tsx +5-10Lines changed: 5 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -147,7 +147,6 @@ import { | 147 | 147 | pendingThreadMessageJump, | 148 | 148 | subscribeThreadMessageJump, | 149 | 149 | } from "./threadMessageJump"; | 150 | | -import { parentThreadIsBelow } from "../../lib/android-workspace-navigation"; | 151 | 150 | import { | 152 | 151 | clearThreadComposerError, | 153 | 152 | threadComposerErrorsAtom, | @@ -191,6 +190,7 @@ import { ComposerQueuedEditBanner } from "./ComposerQueuedEdit"; | 191 | 190 | import { useThreadQueuedCount } from "./ThreadQueueControl"; | 192 | 191 | import type { ThreadContentPresentation } from "./threadContentPresentation"; | 193 | 192 | import { resolveThreadFeedSubmissionAnchor } from "./thread-feed-live-follow"; | | 193 | +import { useOpenLinkedThread } from "./useOpenLinkedThread"; | 194 | 194 | import { useGlobalVoiceInput } from "../voice-input/VoiceInputProvider"; | 195 | 195 |
| 196 | 196 | export interface ThreadDetailScreenProps { | @@ -513,6 +513,7 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai | 513 | 513 | const [composerOwnsKeyboard, setComposerOwnsKeyboard] = useState(false); | 514 | 514 | if (sidebarSearchActive && composerOwnsKeyboard) setComposerOwnsKeyboard(false); | 515 | 515 | const navigation = useNavigation(); | | 516 | + const openLinkedThread = useOpenLinkedThread(); | 516 | 517 | const { session: voiceInputSession } = useGlobalVoiceInput(); | 517 | 518 | const reportedModelSelection = useThreadReportedModelSelection(props.selectedThreadDetailRef); | 518 | 519 | const deviceState = useEnvironmentQuery( | @@ -1747,17 +1748,11 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai | 1747 | 1748 | onOpenParent={ | 1748 | 1749 | props.selectedThread.lineage.parentThreadId === null | 1749 | 1750 | ? null | 1750 | | - : () => { | 1751 | | - const parent = { | | 1751 | + : () => | | 1752 | + openLinkedThread({ | 1752 | 1753 | environmentId: String(props.environmentId), | 1753 | 1754 | threadId: String(props.selectedThread.lineage.parentThreadId), | 1754 | | - }; | 1755 | | - navigation.dispatch((state) => | 1756 | | - parentThreadIsBelow(state, parent) | 1757 | | - ? StackActions.pop() | 1758 | | - : StackActions.push("Thread", parent), | 1759 | | - ); | 1760 | | - } | | 1755 | + }) | 1761 | 1756 | } | 1762 | 1757 | /> | 1763 | 1758 | </View> | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/ThreadFeed.tsx +7-4Lines changed: 7 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -270,6 +270,7 @@ import { waitForThreadShellReady } from "./threadForkNavigation"; | 270 | 270 | import { resolveUserMessageIntentBadge } from "./userMessageIntentBadge"; | 271 | 271 | import { fileChipClipboardPath, fileChipMenu, resolveFileChipTarget } from "./fileChipMenu"; | 272 | 272 | import { useFileChipShare } from "./useFileChipShare"; | | 273 | +import { useOpenLinkedThread } from "./useOpenLinkedThread"; | 273 | 274 | import { | 274 | 275 | MarkdownImageAvailableWidthContext, | 275 | 276 | ThreadMarkdownImage, | @@ -1055,13 +1056,13 @@ function OpenSenderThreadButton(props: { | 1055 | 1056 | readonly environmentId: EnvironmentId; | 1056 | 1057 | readonly senderThreadId: ThreadId; | 1057 | 1058 | }) { | 1058 | | - const navigation = useNavigation(); | | 1059 | + const openLinkedThread = useOpenLinkedThread(); | 1059 | 1060 | return ( | 1060 | 1061 | <Pressable | 1061 | 1062 | accessibilityRole="link" | 1062 | 1063 | hitSlop={6} | 1063 | 1064 | onPress={() => | 1064 | | - navigation.navigate("Thread", { | | 1065 | + openLinkedThread({ | 1065 | 1066 | environmentId: String(props.environmentId), | 1066 | 1067 | threadId: String(props.senderThreadId), | 1067 | 1068 | }) | @@ -1797,6 +1798,7 @@ type UserMessageContentProps = { | 1797 | 1798 | function UserMessageContent(props: UserMessageContentProps) { | 1798 | 1799 | const [selected, setSelected] = useState<{ contextId: string; label: string } | null>(null); | 1799 | 1800 | const navigation = useNavigation(); | | 1801 | + const openLinkedThread = useOpenLinkedThread(); | 1800 | 1802 | const { selectedThread } = useThreadSelection(); | 1801 | 1803 | const liveText = useLiveThreadLinkLabels(props.text, props.environmentId); | 1802 | 1804 | const threadIcons = useThreadChipIcons(props.environmentId, liveText, props.context?.records); | @@ -1815,7 +1817,7 @@ function UserMessageContent(props: UserMessageContentProps) { | 1815 | 1817 | return; | 1816 | 1818 | } | 1817 | 1819 | if (record?.kind === "thread" && "threadId" in record) { | 1818 | | - navigation.navigate("Thread", { | | 1820 | + openLinkedThread({ | 1819 | 1821 | environmentId: String(record.environmentId), | 1820 | 1822 | threadId: String(record.threadId), | 1821 | 1823 | }); | @@ -2026,6 +2028,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) { | 2026 | 2028 | const duoColumns = useNativeWorkspaceColumnsSupported() && isDuoDevice(deviceType); | 2027 | 2029 | const openPullRequest = useOpenPullRequest(); | 2028 | 2030 | const navigation = useNavigation(); | | 2031 | + const openLinkedThread = useOpenLinkedThread(); | 2029 | 2032 | const onOpenTurnDiff = useCallback( | 2030 | 2033 | (checkpoint: ThreadCheckpointSummary) => { | 2031 | 2034 | setReviewSelectedSectionId( | @@ -2210,7 +2213,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) { | 2210 | 2213 | } | 2211 | 2214 | const target = resolveLinkedThread(href); | 2212 | 2215 | if (target) { | 2213 | | - navigation.navigate("Thread", { | | 2216 | + openLinkedThread({ | 2214 | 2217 | environmentId: String(target.environmentId), | 2215 | 2218 | threadId: String(target.threadId), | 2216 | 2219 | }); | |
Collapse file Copy file name to clipboard +16Lines changed: 16 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { StackActions, useNavigation } from "@react-navigation/native"; | | 2 | +import { useCallback } from "react"; | | 3 | +import { linkedThreadStep } from "../../lib/android-workspace-navigation"; | | 4 | + | | 5 | +export function useOpenLinkedThread() { | | 6 | + const navigation = useNavigation(); | | 7 | + return useCallback( | | 8 | + (target: { readonly environmentId: string; readonly threadId: string }) => { | | 9 | + const state = navigation.getState(); | | 10 | + const step = state ? linkedThreadStep(state, target) : "push"; | | 11 | + if (step === "pop") navigation.dispatch(StackActions.pop()); | | 12 | + else if (step === "push") navigation.dispatch(StackActions.push("Thread", target)); | | 13 | + }, | | 14 | + [navigation], | | 15 | + ); | | 16 | +} |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/lib/android-workspace-navigation.test.ts +25Lines changed: 25 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 7 | 7 | } from "../features/workspace/android-workspace-tabs"; | 8 | 8 | import { | 9 | 9 | androidWorkspaceNavigationState, | | 10 | + linkedThreadStep, | 10 | 11 | parentThreadIsBelow, | 11 | 12 | resetAndroidWorkspace, | 12 | 13 | returnToAndroidWorkspaceList, | @@ -202,6 +203,30 @@ describe("Android workspace navigation", () => { | 202 | 203 | }); | 203 | 204 | }); | 204 | 205 |
| | 206 | + it("opens a linked thread above the current one so Back returns to it", () => { | | 207 | + const parent = select(router.getInitialState(options), thread); | | 208 | + const child = { ...thread.params, threadId: "child-a" }; | | 209 | + const open = ( | | 210 | + state: ReturnType<typeof router.getInitialState>, | | 211 | + target: ReactNavigation.RootParamList["Thread"], | | 212 | + ) => { | | 213 | + const step = linkedThreadStep(state, target); | | 214 | + if (step === "stay") return state; | | 215 | + return apply( | | 216 | + state, | | 217 | + step === "pop" ? StackActions.pop() : StackActions.push("Thread", target), | | 218 | + ); | | 219 | + }; | | 220 | + | | 221 | + const inChild = open(parent, child); | | 222 | + expect(inChild.routes.map((route) => route.params)).toEqual([undefined, thread.params, child]); | | 223 | + expect(open(inChild, child)).toBe(inChild); | | 224 | + | | 225 | + const backInParent = open(inChild, thread.params); | | 226 | + expect(backInParent.routes).toEqual(parent.routes); | | 227 | + expect(backInParent.index).toBe(parent.index); | | 228 | + }); | | 229 | + | 205 | 230 | it("recognizes a parent only when its environment and thread are immediately below", () => { | 206 | 231 | const parent = select(router.getInitialState(options), thread); | 207 | 232 | const child = apply( | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/lib/android-workspace-navigation.ts +21Lines changed: 21 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -92,6 +92,27 @@ export function parentThreadIsBelow( | 92 | 92 | ); | 93 | 93 | } | 94 | 94 |
| | 95 | +/** | | 96 | + * How a thread link opened from inside a thread reaches its target. `navigate` would reuse the | | 97 | + * current Thread route, so Back would skip the thread the link was in and land on the list. | | 98 | + */ | | 99 | +export function linkedThreadStep( | | 100 | + state: NavigationState, | | 101 | + target: ReactNavigation.RootParamList["Thread"], | | 102 | +): "stay" | "pop" | "push" { | | 103 | + const params = state.routes[state.index]?.params as | | 104 | + | ReactNavigation.RootParamList["Thread"] | | 105 | + | undefined; | | 106 | + if ( | | 107 | + state.routes[state.index]?.name === "Thread" && | | 108 | + params?.environmentId === target?.environmentId && | | 109 | + params?.threadId === target?.threadId | | 110 | + ) { | | 111 | + return "stay"; | | 112 | + } | | 113 | + return parentThreadIsBelow(state, target) ? "pop" : "push"; | | 114 | +} | | 115 | + | 95 | 116 | export function returnToAndroidWorkspaceList( | 96 | 117 | navigation: WorkspaceNavigation & { readonly goBack: () => void }, | 97 | 118 | selectTab: () => void, | |
|