Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions apps/app/src/views/RootComposeView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
readInitialPromptFromLocationState,
resolveRootComposeEffectiveEnvironmentValue,
resolveRootComposePanelThreadId,
shouldStartComposingFromLocationState,
shouldNavigateAfterThreadCreate,
} from "./RootComposeView";

Expand Down Expand Up @@ -255,6 +256,22 @@ describe("hasSingleUseRootComposeTargetState", () => {
});
});

describe("shouldStartComposingFromLocationState", () => {
it("treats sidebar new-thread focus navigation as a compose request", () => {
expect(shouldStartComposingFromLocationState({ focusPrompt: true })).toBe(
true,
);
});

it("ignores non-focus navigation state", () => {
expect(shouldStartComposingFromLocationState(null)).toBe(false);
expect(shouldStartComposingFromLocationState({})).toBe(false);
expect(
shouldStartComposingFromLocationState({ focusPrompt: false }),
).toBe(false);
});
});

describe("shouldNavigateAfterThreadCreate", () => {
it("follows the preference for ordinary new threads", () => {
expect(
Expand Down
14 changes: 13 additions & 1 deletion apps/app/src/views/RootComposeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,13 @@ export function readRootComposeFolderTargetFromLocationState(
return null;
}

export function shouldStartComposingFromLocationState(state: unknown): boolean {
if (typeof state !== "object" || state === null) {
return false;
}
return "focusPrompt" in state && state.focusPrompt === true;
}

type RootComposeViewProps =
| {
surface: "page";
Expand Down Expand Up @@ -749,7 +756,9 @@ export function RootComposeView(props: RootComposeViewProps) {
);
// The no-projects welcome replaces the composer until the user opts in; once
// they pick "New thread" we reveal the composer for the rest of the session.
const [startedComposing, setStartedComposing] = useState(false);
const [startedComposing, setStartedComposing] = useState(() =>
shouldStartComposingFromLocationState(location.state),
);
const [navigateToThreadAfterCreate] =
useNavigateToThreadAfterCreatePreference();
const [forkSeed, setForkSeed] = useState<ForkThreadCreateSeed | null>(() =>
Expand Down Expand Up @@ -904,6 +913,9 @@ export function RootComposeView(props: RootComposeViewProps) {
if (!hasSingleUseRootComposeTargetState(location.state)) {
return;
}
if (shouldStartComposingFromLocationState(location.state)) {
setStartedComposing(true);
}
if (folderTarget?.kind === "set") {
setRootComposeFolderId(folderTarget.folderId);
} else if (folderTarget?.kind === "clear") {
Expand Down
Loading