Skip to content

Commit 73664cd

Browse files
Merge main into fix/issue-23919
2 parents 626f19c + d53873b commit 73664cd

16 files changed

Lines changed: 332 additions & 54 deletions

‎apps/mobile/src/components/ComposerEditor.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { ComposerContextId } from "@t3tools/contracts";
33
import { useAtomValue } from "@effect/atom-react";
44
import { AsyncResult } from "effect/reactivity";
55
import { settlePromise, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
6-
import { useNavigation } from "@react-navigation/native";
76
import { useEffect, useRef, useState } from "react";
87
import type { EnvironmentId } from "@t3tools/contracts";
98
import { encodeComposerContextFragment } from "@t3tools/shared/composerContextClipboard";
@@ -24,6 +23,7 @@ import {
2423
} from "../state/use-composer-drafts";
2524
import { importComposerContextClipboard } from "../lib/composerContextClipboard";
2625
import { mobilePreferencesAtom } from "../state/preferences";
26+
import { useOpenLinkedThread } from "../features/threads/useOpenLinkedThread";
2727
import { ComposerContextSheet } from "./ComposerContextSheet";
2828
import { AppText as Text } from "./ui/AppText";
2929
import {
@@ -154,7 +154,7 @@ export function ComposerEditor({
154154
}),
155155
})
156156
: "";
157-
const navigation = useNavigation();
157+
const openLinkedThread = useOpenLinkedThread();
158158
const selectedReference = selected
159159
? collectComposerContextReferences(selected.source)[0]
160160
: undefined;
@@ -236,7 +236,7 @@ export function ComposerEditor({
236236
: {})}
237237
onOpenThread={(thread) => {
238238
setSelected(null);
239-
navigation.navigate("Thread", {
239+
openLinkedThread({
240240
environmentId: String(thread.environmentId),
241241
threadId: String(thread.threadId),
242242
});

‎apps/mobile/src/features/threads/ThreadDetailScreen.tsx‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ import {
147147
pendingThreadMessageJump,
148148
subscribeThreadMessageJump,
149149
} from "./threadMessageJump";
150-
import { parentThreadIsBelow } from "../../lib/android-workspace-navigation";
151150
import {
152151
clearThreadComposerError,
153152
threadComposerErrorsAtom,
@@ -191,6 +190,7 @@ import { ComposerQueuedEditBanner } from "./ComposerQueuedEdit";
191190
import { useThreadQueuedCount } from "./ThreadQueueControl";
192191
import type { ThreadContentPresentation } from "./threadContentPresentation";
193192
import { resolveThreadFeedSubmissionAnchor } from "./thread-feed-live-follow";
193+
import { useOpenLinkedThread } from "./useOpenLinkedThread";
194194
import { useGlobalVoiceInput } from "../voice-input/VoiceInputProvider";
195195

196196
export interface ThreadDetailScreenProps {
@@ -513,6 +513,7 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
513513
const [composerOwnsKeyboard, setComposerOwnsKeyboard] = useState(false);
514514
if (sidebarSearchActive && composerOwnsKeyboard) setComposerOwnsKeyboard(false);
515515
const navigation = useNavigation();
516+
const openLinkedThread = useOpenLinkedThread();
516517
const { session: voiceInputSession } = useGlobalVoiceInput();
517518
const reportedModelSelection = useThreadReportedModelSelection(props.selectedThreadDetailRef);
518519
const deviceState = useEnvironmentQuery(
@@ -1747,17 +1748,11 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
17471748
onOpenParent={
17481749
props.selectedThread.lineage.parentThreadId === null
17491750
? null
1750-
: () => {
1751-
const parent = {
1751+
: () =>
1752+
openLinkedThread({
17521753
environmentId: String(props.environmentId),
17531754
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+
})
17611756
}
17621757
/>
17631758
</View>

‎apps/mobile/src/features/threads/ThreadFeed.tsx‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ import { waitForThreadShellReady } from "./threadForkNavigation";
270270
import { resolveUserMessageIntentBadge } from "./userMessageIntentBadge";
271271
import { fileChipClipboardPath, fileChipMenu, resolveFileChipTarget } from "./fileChipMenu";
272272
import { useFileChipShare } from "./useFileChipShare";
273+
import { useOpenLinkedThread } from "./useOpenLinkedThread";
273274
import {
274275
MarkdownImageAvailableWidthContext,
275276
ThreadMarkdownImage,
@@ -1055,13 +1056,13 @@ function OpenSenderThreadButton(props: {
10551056
readonly environmentId: EnvironmentId;
10561057
readonly senderThreadId: ThreadId;
10571058
}) {
1058-
const navigation = useNavigation();
1059+
const openLinkedThread = useOpenLinkedThread();
10591060
return (
10601061
<Pressable
10611062
accessibilityRole="link"
10621063
hitSlop={6}
10631064
onPress={() =>
1064-
navigation.navigate("Thread", {
1065+
openLinkedThread({
10651066
environmentId: String(props.environmentId),
10661067
threadId: String(props.senderThreadId),
10671068
})
@@ -1797,6 +1798,7 @@ type UserMessageContentProps = {
17971798
function UserMessageContent(props: UserMessageContentProps) {
17981799
const [selected, setSelected] = useState<{ contextId: string; label: string } | null>(null);
17991800
const navigation = useNavigation();
1801+
const openLinkedThread = useOpenLinkedThread();
18001802
const { selectedThread } = useThreadSelection();
18011803
const liveText = useLiveThreadLinkLabels(props.text, props.environmentId);
18021804
const threadIcons = useThreadChipIcons(props.environmentId, liveText, props.context?.records);
@@ -1815,7 +1817,7 @@ function UserMessageContent(props: UserMessageContentProps) {
18151817
return;
18161818
}
18171819
if (record?.kind === "thread" && "threadId" in record) {
1818-
navigation.navigate("Thread", {
1820+
openLinkedThread({
18191821
environmentId: String(record.environmentId),
18201822
threadId: String(record.threadId),
18211823
});
@@ -2026,6 +2028,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
20262028
const duoColumns = useNativeWorkspaceColumnsSupported() && isDuoDevice(deviceType);
20272029
const openPullRequest = useOpenPullRequest();
20282030
const navigation = useNavigation();
2031+
const openLinkedThread = useOpenLinkedThread();
20292032
const onOpenTurnDiff = useCallback(
20302033
(checkpoint: ThreadCheckpointSummary) => {
20312034
setReviewSelectedSectionId(
@@ -2210,7 +2213,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
22102213
}
22112214
const target = resolveLinkedThread(href);
22122215
if (target) {
2213-
navigation.navigate("Thread", {
2216+
openLinkedThread({
22142217
environmentId: String(target.environmentId),
22152218
threadId: String(target.threadId),
22162219
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
}

‎apps/mobile/src/lib/android-workspace-navigation.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from "../features/workspace/android-workspace-tabs";
88
import {
99
androidWorkspaceNavigationState,
10+
linkedThreadStep,
1011
parentThreadIsBelow,
1112
resetAndroidWorkspace,
1213
returnToAndroidWorkspaceList,
@@ -202,6 +203,30 @@ describe("Android workspace navigation", () => {
202203
});
203204
});
204205

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+
205230
it("recognizes a parent only when its environment and thread are immediately below", () => {
206231
const parent = select(router.getInitialState(options), thread);
207232
const child = apply(

‎apps/mobile/src/lib/android-workspace-navigation.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,27 @@ export function parentThreadIsBelow(
9292
);
9393
}
9494

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+
95116
export function returnToAndroidWorkspaceList(
96117
navigation: WorkspaceNavigation & { readonly goBack: () => void },
97118
selectTab: () => void,

‎apps/web/src/components/chat/ChatComposer.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3765,7 +3765,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
37653765
<ComposerContextActionsContext value={composerContextActions}>
37663766
<ComposerPromptEditor
37673767
draftKey={composerDraftTargetKey}
3768-
ariaLabel="Message"
3768+
// Switching threads lands focus here, so the label names the thread.
3769+
ariaLabel={activeThread ? `Message ${activeThread.title}` : "Message"}
37693770
suggestionListId={composerSuggestionListId}
37703771
activeSuggestionId={
37713772
composerSuggestionListVisible && activeComposerMenuItem

‎apps/web/src/components/chat/ModelPickerContent.tsx‎

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import {
5252
useEnvironmentModelPreferences,
5353
useToggleEnvironmentModelFavorite,
5454
} from "~/hooks/useSettings";
55+
import { announce } from "~/lib/announce";
5556
import { cn } from "~/lib/utils";
5657
import { getVirtualizedScrollFadeClassName } from "../ui/scroll-area";
5758
import { TooltipProvider } from "../ui/tooltip";
@@ -485,26 +486,26 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
485486
modelSlug: string,
486487
instanceId: ProviderInstanceId,
487488
additive = false,
488-
) => {
489+
): string | null => {
489490
if (getModelDisabledReason?.(instanceId, modelSlug)) {
490-
return;
491+
return null;
491492
}
492493
const options = modelOptionsByInstance.get(instanceId);
493494
if (!options) {
494-
return;
495+
return null;
495496
}
496497
const entry = instanceEntries.find((candidate) => candidate.instanceId === instanceId);
497498
if (!entry) {
498-
return;
499+
return null;
499500
}
500501
const resolvedModel = resolveSelectableModel(entry.driverKind, modelSlug, options);
501-
if (resolvedModel) {
502-
if (additive && onToggleModel) {
503-
onToggleModel(instanceId, resolvedModel);
504-
} else {
505-
onInstanceModelChange(instanceId, resolvedModel);
506-
}
502+
if (!resolvedModel) return null;
503+
if (additive && onToggleModel) {
504+
onToggleModel(instanceId, resolvedModel);
505+
} else {
506+
onInstanceModelChange(instanceId, resolvedModel);
507507
}
508+
return resolvedModel;
508509
};
509510

510511
const modelJumpShortcutContext = {
@@ -773,6 +774,10 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
773774
});
774775
setSearchQuery("");
775776
handleSelectInstance(next);
777+
announce(
778+
next === "favorites" ? "Favorites" : (entryByInstanceId.get(next)?.displayName ?? next),
779+
"model-picker",
780+
);
776781
return;
777782
}
778783
const jumpIndex = modelPickerJumpIndexFromCommand(command ?? "");
@@ -790,7 +795,12 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
790795
if (!model) {
791796
return;
792797
}
793-
handleModelSelect(model.slug, model.instanceId);
798+
const selectedSlug = handleModelSelect(model.slug, model.instanceId);
799+
if (selectedSlug === null) return;
800+
const name = flatModels.find(
801+
(item) => item.slug === selectedSlug && item.instanceId === model.instanceId,
802+
)?.name;
803+
announce(`Model: ${name ?? selectedSlug}`, "model-picker");
794804
};
795805

796806
return (

‎apps/web/src/components/chat/OpenInPicker.browser.test.tsx‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { AuthOrchestrationOperateScope, EnvironmentId, type EditorId } from "@t3tools/contracts";
22
import { DEFAULT_RESOLVED_KEYBINDINGS } from "@t3tools/shared/keybindings";
3+
import { Cause } from "effect";
34
import { AsyncResult } from "effect/reactivity";
45
import { describe, expect, it, vi } from "vite-plus/test";
56

6-
import { act, render as renderUi } from "../../../test/render";
7+
import { act, fakeTimers, render as renderUi } from "../../../test/render";
78
import type { RemoteOpenState } from "../../remoteOpen";
89

910
const state = vi.hoisted(() => ({
@@ -181,3 +182,36 @@ describe("host editor access", () => {
181182
expect((await pressOpenFavorite()).defaultPrevented).toBe(false);
182183
});
183184
});
185+
186+
describe("open in editor announcement", () => {
187+
it("speaks only after the shortcut opened the editor, from the picker or the fallback", async () => {
188+
await using fixture = await setup();
189+
const { screen, renderPicker, pressOpenFavorite, FavoriteEditorFallback } = fixture;
190+
state.allowed.add(selected);
191+
await renderPicker();
192+
using _timers = fakeTimers();
193+
const regions = () => [...document.querySelectorAll('body > [aria-live="polite"]')];
194+
const spoken = async () => {
195+
await act(async () => vi.runAllTimers());
196+
return regions()
197+
.map((region) => region.textContent)
198+
.join("");
199+
};
200+
const refuse = () =>
201+
state.run.mockResolvedValueOnce(AsyncResult.failure(Cause.fail(new Error("No editor"))));
202+
203+
refuse();
204+
await pressOpenFavorite();
205+
expect(await spoken()).toBe("");
206+
await pressOpenFavorite();
207+
expect(await spoken()).toBe("Opened in VS Code");
208+
209+
for (const region of regions()) region.textContent = "";
210+
await act(async () => screen.rerender(<FavoriteEditorFallback />));
211+
refuse();
212+
await pressOpenFavorite();
213+
expect(await spoken()).toBe("");
214+
await pressOpenFavorite();
215+
expect(await spoken()).toBe("Opened in VS Code");
216+
});
217+
});

0 commit comments

Comments
 (0)