@devries-cameron20 / t3code Mirror · read-only / commits / 911212bf4f
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 05:45 UTC

fix(web): open project picker from boring sidebar's header (#26495)

Co-authored-by: maria-rcks <maria@kuuro.net>

Utkarsh Patil committed Nov 3, 2026 at 22:49 UTC 911212bf4f60915676ac891345fb325457db957e
5 files changed +163 -8
apps/web/src/components/Sidebar.browser.test.tsx new
+89
@@ -0,0 +1,89 @@
1 +import { DEFAULT_CLIENT_SETTINGS, EnvironmentId, ProjectId } from "@t3tools/contracts";
2 +import { describe, expect, it, vi } from "vite-plus/test";
3 +import { userEvent } from "vite-plus/test/browser";
4 +
5 +import { render } from "../../test/render";
6 +import { openCommandPalette } from "../commandPaletteBus";
7 +import { useHandleNewThread } from "../hooks/useHandleNewThread";
8 +import { __setClientSettingsForTests, getClientSettings } from "../hooks/useSettings";
9 +import { useProjects } from "../state/entities";
10 +import type { Project } from "../types";
11 +import Sidebar from "./Sidebar";
12 +import { SidebarProvider } from "./ui/sidebar";
13 +
14 +vi.mock("../state/entities", { spy: true });
15 +vi.mock("../hooks/useHandleNewThread", { spy: true });
16 +vi.mock("../commandPaletteBus", () => ({
17 + openCommandPalette: vi.fn(),
18 + isCommandPaletteOpen: () => false,
19 +}));
20 +vi.mock("./sidebar/SidebarChrome", () => ({
21 + SidebarChromeHeader: () => null,
22 + SidebarChromeFooter: () => null,
23 +}));
24 +
25 +function project(id: string): Project {
26 + return {
27 + id: ProjectId.make(id),
28 + environmentId: EnvironmentId.make("local"),
29 + title: id,
30 + workspaceRoot: `/projects/${id}`,
31 + repositoryIdentity: null,
32 + defaultModelSelection: null,
33 + createdAt: "2026-01-01T00:00:00.000Z",
34 + updatedAt: "2026-01-01T00:00:00.000Z",
35 + scripts: [],
36 + };
37 +}
38 +
39 +describe("sidebar header new thread", () => {
40 + it.each([
41 + { mode: "normal", count: 2, shift: false, picker: true },
42 + { mode: "boring", count: 2, shift: false, picker: true },
43 + { mode: "boring", count: 2, shift: true, picker: false },
44 + { mode: "boring", count: 1, shift: false, picker: false },
45 + { mode: "legacy", count: 2, shift: false, picker: false },
46 + ] as const)("$mode sidebar, $count projects, shift=$shift: picker=$picker", async (scenario) => {
47 + using stack = new DisposableStack();
48 + const previousSettings = getClientSettings();
49 + stack.defer(() => __setClientSettingsForTests(previousSettings));
50 + __setClientSettingsForTests({
51 + ...DEFAULT_CLIENT_SETTINGS,
52 + boringSidebarEnabled: scenario.mode === "boring",
53 + legacySidebarEnabled: scenario.mode === "legacy",
54 + });
55 + const projects = [project("active"), project("idle")].slice(0, scenario.count);
56 + const currentProjectRef = {
57 + environmentId: projects[0]!.environmentId,
58 + projectId: projects[0]!.id,
59 + };
60 + const startThread = vi.fn().mockResolvedValue(null);
61 + vi.mocked(useProjects).mockReturnValue(projects);
62 + vi.mocked(useHandleNewThread).mockReturnValue({
63 + activeDraftThread: null,
64 + activeThread: null,
65 + defaultProjectRef: currentProjectRef,
66 + handleNewThread: startThread,
67 + routeDraftId: null,
68 + routeThreadRef: null,
69 + });
70 + vi.mocked(openCommandPalette).mockClear();
71 + await using screen = await render(
72 + <SidebarProvider>
73 + <Sidebar routeReveal={{ observedKey: null, pendingKey: null }} />
74 + </SidebarProvider>,
75 + );
76 +
77 + await userEvent.click(screen.getByRole("button", { name: "New thread", exact: true }), {
78 + modifiers: scenario.shift ? ["Shift"] : [],
79 + });
80 +
81 + if (scenario.picker) {
82 + expect(openCommandPalette).toHaveBeenCalledExactlyOnceWith({ open: "new-thread-in" });
83 + expect(startThread).not.toHaveBeenCalled();
84 + } else {
85 + expect(openCommandPalette).not.toHaveBeenCalled();
86 + expect(startThread).toHaveBeenCalledExactlyOnceWith(currentProjectRef);
87 + }
88 + });
89 +});
apps/web/src/components/Sidebar.tsx
+3 -2
@@ -1006,6 +1006,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
1006 },
1007 });
1008 const boringSidebarEnabled = useBoringSidebarEnabled();
1009 + const legacySidebarEnabled = useClientSettings((settings) => settings.legacySidebarEnabled);
1010 const folderRowsMultiline = useClientSettings((settings) => settings.boringSidebarMultilineRows);
1011 const newThreadContext = useHandleNewThread();
1012 // Row callbacks capture only the handler; the rest of the context changes with the route.
@@ -2950,7 +2951,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
2951
2952 const handleNewThreadClick = (event?: ReactMouseEvent) => {
2953 if (
2953 - boringSidebarEnabled ||
2954 + legacySidebarEnabled ||
2955 shouldCreateNewThreadInCurrentProject(
2956 event?.shiftKey ?? false,
2957 scopeGroups.length,
@@ -3182,7 +3183,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
3183 newThreadShortcutLabel={newThreadShortcutLabel}
3184 newThreadInProjectShortcutLabel={newThreadInProjectShortcutLabel}
3185 showNewThreadInProjectHint={
3185 - !boringSidebarEnabled &&
3186 + !legacySidebarEnabled &&
3187 !shouldCreateNewThreadInCurrentProject(
3188 false,
3189 scopeGroups.length,
apps/web/src/shortcuts/chatRouteCommands.test.ts new
+65
@@ -0,0 +1,65 @@
1 +import { DEFAULT_CLIENT_SETTINGS, EnvironmentId, ProjectId } from "@t3tools/contracts";
2 +import type { AnyRouter } from "@tanstack/react-router";
3 +import { describe, expect, it, vi } from "vite-plus/test";
4 +
5 +import * as commandPalette from "../commandPaletteBus";
6 +import * as settings from "../hooks/useSettings";
7 +import * as threadActions from "../lib/chatThreadActions";
8 +import * as entities from "../state/entities";
9 +import type { Project } from "../types";
10 +import { installChatRouteCommands } from "./chatRouteCommands";
11 +import * as dispatcher from "./dispatcher";
12 +
13 +function project(id: string): Project {
14 + return {
15 + id: ProjectId.make(id),
16 + environmentId: EnvironmentId.make("local"),
17 + title: id,
18 + workspaceRoot: `/projects/${id}`,
19 + repositoryIdentity: null,
20 + defaultModelSelection: null,
21 + createdAt: "2026-01-01T00:00:00.000Z",
22 + updatedAt: "2026-01-01T00:00:00.000Z",
23 + scripts: [],
24 + };
25 +}
26 +
27 +describe("new thread commands", () => {
28 + it.each([
29 + { mode: "normal", count: 2, command: "chat.new", picker: true },
30 + { mode: "boring", count: 2, command: "chat.new", picker: true },
31 + { mode: "boring", count: 1, command: "chat.new", picker: false },
32 + { mode: "legacy", count: 2, command: "chat.new", picker: false },
33 + { mode: "boring", count: 2, command: "chat.newLocal", picker: false },
34 + ] as const)("$mode sidebar, $count projects, $command: picker=$picker", (scenario) => {
35 + using _settings = vi.spyOn(settings, "getClientSettings").mockReturnValue({
36 + ...DEFAULT_CLIENT_SETTINGS,
37 + boringSidebarEnabled: scenario.mode === "boring",
38 + legacySidebarEnabled: scenario.mode === "legacy",
39 + });
40 + using _projects = vi
41 + .spyOn(entities, "readProjects")
42 + .mockReturnValue([project("active"), project("idle")].slice(0, scenario.count));
43 + using openPicker = vi.spyOn(commandPalette, "openCommandPalette").mockImplementation(() => {});
44 + using startLocal = vi.spyOn(threadActions, "startNewThreadFromContext").mockResolvedValue(true);
45 + using register = vi.spyOn(dispatcher, "registerCommands").mockReturnValue(() => {});
46 + const router = { state: { matches: [] } } as unknown as AnyRouter;
47 + using stack = new DisposableStack();
48 + stack.defer(installChatRouteCommands(router));
49 + const commands = register.mock.calls[0]![0];
50 + const event = {
51 + preventDefault: vi.fn(),
52 + stopPropagation: vi.fn(),
53 + } as unknown as KeyboardEvent;
54 +
55 + commands[scenario.command]!(event);
56 +
57 + if (scenario.picker) {
58 + expect(openPicker).toHaveBeenCalledWith({ open: "new-thread-in" });
59 + expect(startLocal).not.toHaveBeenCalled();
60 + } else {
61 + expect(openPicker).not.toHaveBeenCalled();
62 + expect(startLocal).toHaveBeenCalledOnce();
63 + }
64 + });
65 +});
apps/web/src/shortcuts/chatRouteCommands.ts
+1 -4
@@ -123,12 +123,9 @@ export function installChatRouteCommands(router: AnyRouter): () => void {
123 void scratch.startScratchThread(environmentId);
124 },
125 "chat.new": (event) => {
126 - // The boring sidebar's folders already show the context, so it starts in
127 - // the current project like the legacy sidebar did.
128 - const { boringSidebarEnabled, legacySidebarEnabled } = getClientSettings();
126 + const { legacySidebarEnabled } = getClientSettings();
127 const groups = readProjectGroups();
128 if (
131 - !boringSidebarEnabled &&
129 !legacySidebarEnabled &&
130 !shouldCreateNewThreadInCurrentProject(
131 false,
docs/user/thread-sidebar.md
+5 -2
@@ -5,8 +5,11 @@ need a separate branch and working directory.
5
6 ## Start a thread
7
8 -On web and desktop, a new thread keeps the current project and carries your model
9 -and mode selections, unless the destination project has its own model default.
8 +On web and desktop, **New thread** opens the project picker when you have multiple
9 +projects in the default or project-grouped sidebar. The legacy sidebar always
10 +starts in the current project. **Shift-click** to start in
11 +the current project, or use a project's own new-thread action. A new thread carries
12 +your model and mode selections, unless the destination project has its own model default.
13 Its branch and workspace mode come from your configured defaults. To continue in
14 an existing worktree, use **New thread in this worktree** from the branch toolbar.
15