Skip to content

Commit ed1e15b

Browse files
Mohamad44pclaude
andcommitted
feat(web): add chat grid split view
Opens multiple chat threads side-by-side in a configurable grid. - Grid is a new route at `/$environmentId/grid`, reachable via a grid icon in `ChatHeader` or `Ctrl/Cmd+Shift+G`. Dimensions are configurable from 1×1 to 6×6 via a Google-Docs-style hover picker. - Each cell hosts a full `ChatView`; empty cells offer "Pick thread" (existing threads in the env) or "New thread" (creates an isolated draft under a grid-scoped logical-project key so sibling panes don't evict each other). - Layout and chosen threads persist per environment via a zustand store (`gridLayoutStore`) backed by localStorage. A `lastView` flag is also persisted so reopening the app restores whichever view (grid or single- thread) the user was last in. - Inside a grid pane the header's grid button is swapped for a × that removes the pane (not the thread). The diff toggle stays visible but opens an in-pane diff sheet instead of navigating away — `DiffPanel` takes optional `threadRefOverride` / `diffSearchOverride` / `onSelectTurnOverride` props when rendered inside a pane, and a new `GridPaneContext` lets `ChatView` route `onToggleDiff` / `onOpenTurnDiff` through the pane's local state. - `GridToolbar` reserves the Electron title-bar-overlay inset on the desktop build so the Reset/× controls don't slide under the window buttons. Tests: 47 new unit tests covering layout reducers, store persistence, and the grid keyboard shortcut. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent 62df3cb commit ed1e15b

21 files changed

Lines changed: 1982 additions & 22 deletions

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ import { ExpandedImageDialog } from "./chat/ExpandedImageDialog";
138138
import { PullRequestThreadDialog } from "./PullRequestThreadDialog";
139139
import { MessagesTimeline } from "./chat/MessagesTimeline";
140140
import { ChatHeader } from "./chat/ChatHeader";
141+
import { useGridPaneContext } from "./grid/gridPaneContext";
141142
import { type ExpandedImagePreview } from "./chat/ExpandedImagePreview";
142143
import { NoActiveThreadState } from "./NoActiveThreadState";
143144
import { resolveEffectiveEnvMode, resolveEnvironmentOptionLabel } from "./BranchToolbar.logic";
@@ -790,7 +791,9 @@ export default function ChatView(props: ChatViewProps) {
790791
composerInteractionMode ?? activeThread?.interactionMode ?? DEFAULT_INTERACTION_MODE;
791792
const isLocalDraftThread = !isServerThread && localDraftThread !== undefined;
792793
const canCheckoutPullRequestIntoThread = isLocalDraftThread;
793-
const diffOpen = rawSearch.diff === "1";
794+
const diffOpenFromRoute = rawSearch.diff === "1";
795+
const gridPaneContext = useGridPaneContext();
796+
const diffOpen = gridPaneContext ? gridPaneContext.diffOpen : diffOpenFromRoute;
794797
const activeThreadId = activeThread?.id ?? null;
795798
const activeThreadRef = useMemo(
796799
() => (activeThread ? scopeThreadRef(activeThread.environmentId, activeThread.id) : null),
@@ -1478,6 +1481,10 @@ export default function ChatView(props: ChatViewProps) {
14781481
if (!isServerThread) {
14791482
return;
14801483
}
1484+
if (gridPaneContext) {
1485+
gridPaneContext.onRequestDiff({ open: !gridPaneContext.diffOpen });
1486+
return;
1487+
}
14811488
if (!diffOpen) {
14821489
onDiffPanelOpen?.();
14831490
}
@@ -1493,7 +1500,15 @@ export default function ChatView(props: ChatViewProps) {
14931500
return diffOpen ? { ...rest, diff: undefined } : { ...rest, diff: "1" };
14941501
},
14951502
});
1496-
}, [diffOpen, environmentId, isServerThread, navigate, onDiffPanelOpen, threadId]);
1503+
}, [
1504+
diffOpen,
1505+
environmentId,
1506+
gridPaneContext,
1507+
isServerThread,
1508+
navigate,
1509+
onDiffPanelOpen,
1510+
threadId,
1511+
]);
14971512

14981513
const envLocked = Boolean(
14991514
activeThread &&
@@ -3166,6 +3181,14 @@ export default function ChatView(props: ChatViewProps) {
31663181
if (!isServerThread) {
31673182
return;
31683183
}
3184+
if (gridPaneContext) {
3185+
gridPaneContext.onRequestDiff({
3186+
open: true,
3187+
turnId,
3188+
...(filePath ? { filePath } : {}),
3189+
});
3190+
return;
3191+
}
31693192
onDiffPanelOpen?.();
31703193
void navigate({
31713194
to: "/$environmentId/$threadId",
@@ -3181,7 +3204,7 @@ export default function ChatView(props: ChatViewProps) {
31813204
},
31823205
});
31833206
},
3184-
[environmentId, isServerThread, navigate, onDiffPanelOpen, threadId],
3207+
[environmentId, gridPaneContext, isServerThread, navigate, onDiffPanelOpen, threadId],
31853208
);
31863209
// Both the Map and the revert handler are read from refs at call-time so
31873210
// the callback reference is fully stable and never busts context identity.

‎apps/web/src/components/DiffPanel.tsx‎

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { FileDiff, type FileDiffMetadata, Virtualizer } from "@pierre/diffs/reac
33
import { useQuery } from "@tanstack/react-query";
44
import { useNavigate, useParams, useSearch } from "@tanstack/react-router";
55
import { scopeThreadRef } from "@t3tools/client-runtime";
6-
import type { TurnId } from "@t3tools/contracts";
6+
import type { ScopedThreadRef, TurnId } from "@t3tools/contracts";
7+
8+
import type { DiffRouteSearch } from "../diffRouteSearch";
79
import {
810
ChevronLeftIcon,
911
ChevronRightIcon,
@@ -162,11 +164,26 @@ function buildFileDiffRenderKey(fileDiff: FileDiffMetadata): string {
162164

163165
interface DiffPanelProps {
164166
mode?: DiffPanelMode;
167+
/**
168+
* Optional thread-ref override. When provided, DiffPanel uses this instead
169+
* of reading the thread from the current route params. Used by grid panes
170+
* where the route doesn't contain the thread.
171+
*/
172+
threadRefOverride?: ScopedThreadRef | null;
173+
/** Optional override for diff search state (diff open, turn id, file path). */
174+
diffSearchOverride?: DiffRouteSearch;
175+
/** Called when the user picks a turn in the strip — overrides route navigate. */
176+
onSelectTurnOverride?: (turnId: TurnId | null) => void;
165177
}
166178

167179
export { DiffWorkerPoolProvider } from "./DiffWorkerPoolProvider";
168180

169-
export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
181+
export default function DiffPanel({
182+
mode = "inline",
183+
threadRefOverride,
184+
diffSearchOverride,
185+
onSelectTurnOverride,
186+
}: DiffPanelProps) {
170187
const navigate = useNavigate();
171188
const { resolvedTheme } = useTheme();
172189
const settings = useSettings();
@@ -177,11 +194,17 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
177194
const previousDiffOpenRef = useRef(false);
178195
const [canScrollTurnStripLeft, setCanScrollTurnStripLeft] = useState(false);
179196
const [canScrollTurnStripRight, setCanScrollTurnStripRight] = useState(false);
180-
const routeThreadRef = useParams({
197+
const routeThreadRefFromParams = useParams({
181198
strict: false,
182199
select: (params) => resolveThreadRouteRef(params),
183200
});
184-
const diffSearch = useSearch({ strict: false, select: (search) => parseDiffRouteSearch(search) });
201+
const routeThreadRef =
202+
threadRefOverride !== undefined ? threadRefOverride : routeThreadRefFromParams;
203+
const routeDiffSearch = useSearch({
204+
strict: false,
205+
select: (search) => parseDiffRouteSearch(search),
206+
});
207+
const diffSearch = diffSearchOverride ?? routeDiffSearch;
185208
const diffOpen = diffSearch.diff === "1";
186209
const activeThreadId = routeThreadRef?.threadId ?? null;
187210
const activeThread = useStore(
@@ -345,6 +368,10 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
345368

346369
const selectTurn = (turnId: TurnId) => {
347370
if (!activeThread) return;
371+
if (onSelectTurnOverride) {
372+
onSelectTurnOverride(turnId);
373+
return;
374+
}
348375
void navigate({
349376
to: "/$environmentId/$threadId",
350377
params: buildThreadRouteParams(scopeThreadRef(activeThread.environmentId, activeThread.id)),
@@ -356,6 +383,10 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
356383
};
357384
const selectWholeConversation = () => {
358385
if (!activeThread) return;
386+
if (onSelectTurnOverride) {
387+
onSelectTurnOverride(null);
388+
return;
389+
}
359390
void navigate({
360391
to: "/$environmentId/$threadId",
361392
params: buildThreadRouteParams(scopeThreadRef(activeThread.environmentId, activeThread.id)),

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

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@ import {
66
type ThreadId,
77
} from "@t3tools/contracts";
88
import { scopeThreadRef } from "@t3tools/client-runtime";
9-
import { memo } from "react";
9+
import { memo, useCallback } from "react";
10+
import { useNavigate } from "@tanstack/react-router";
1011
import GitActionsControl from "../GitActionsControl";
1112
import { type DraftId } from "~/composerDraftStore";
12-
import { DiffIcon, TerminalSquareIcon } from "lucide-react";
13+
import { DiffIcon, Grid2X2Icon, TerminalSquareIcon, XIcon } from "lucide-react";
1314
import { Badge } from "../ui/badge";
1415
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
1516
import ProjectScriptsControl, { type NewProjectScriptInput } from "../ProjectScriptsControl";
1617
import { Toggle } from "../ui/toggle";
18+
import { Button } from "../ui/button";
1719
import { SidebarTrigger } from "../ui/sidebar";
20+
import { useGridPaneContext } from "../grid/gridPaneContext";
1821
import { OpenInPicker } from "./OpenInPicker";
1922

2023
interface ChatHeaderProps {
@@ -68,10 +71,18 @@ export const ChatHeader = memo(function ChatHeader({
6871
onToggleTerminal,
6972
onToggleDiff,
7073
}: ChatHeaderProps) {
74+
const navigate = useNavigate();
75+
const gridPane = useGridPaneContext();
76+
const openGridView = useCallback(() => {
77+
void navigate({
78+
to: "/$environmentId/grid",
79+
params: { environmentId: activeThreadEnvironmentId },
80+
});
81+
}, [activeThreadEnvironmentId, navigate]);
7182
return (
7283
<div className="@container/header-actions flex min-w-0 flex-1 items-center gap-2">
7384
<div className="flex min-w-0 flex-1 items-center gap-2 overflow-hidden sm:gap-3">
74-
<SidebarTrigger className="size-7 shrink-0 md:hidden" />
85+
{gridPane ? null : <SidebarTrigger className="size-7 shrink-0 md:hidden" />}
7586
<h2
7687
className="min-w-0 shrink truncate text-sm font-medium text-foreground"
7788
title={activeThreadTitle}
@@ -158,11 +169,51 @@ export const ChatHeader = memo(function ChatHeader({
158169
<TooltipPopup side="bottom">
159170
{!isGitRepo
160171
? "Diff panel is unavailable because this project is not a git repository."
161-
: diffToggleShortcutLabel
162-
? `Toggle diff panel (${diffToggleShortcutLabel})`
163-
: "Toggle diff panel"}
172+
: gridPane
173+
? "Open diff (switches this pane to full-thread view)"
174+
: diffToggleShortcutLabel
175+
? `Toggle diff panel (${diffToggleShortcutLabel})`
176+
: "Toggle diff panel"}
164177
</TooltipPopup>
165178
</Tooltip>
179+
{gridPane ? (
180+
<Tooltip>
181+
<TooltipTrigger
182+
render={
183+
<Button
184+
className="shrink-0"
185+
variant="outline"
186+
size="icon-xs"
187+
aria-label="Remove this pane from the grid"
188+
onClick={(event) => {
189+
event.stopPropagation();
190+
gridPane.onClosePane();
191+
}}
192+
>
193+
<XIcon className="size-3" />
194+
</Button>
195+
}
196+
/>
197+
<TooltipPopup side="bottom">Remove pane from grid</TooltipPopup>
198+
</Tooltip>
199+
) : (
200+
<Tooltip>
201+
<TooltipTrigger
202+
render={
203+
<Button
204+
className="shrink-0"
205+
variant="outline"
206+
size="icon-xs"
207+
aria-label="Open grid split view"
208+
onClick={openGridView}
209+
>
210+
<Grid2X2Icon className="size-3" />
211+
</Button>
212+
}
213+
/>
214+
<TooltipPopup side="bottom">Open grid split view</TooltipPopup>
215+
</Tooltip>
216+
)}
166217
</div>
167218
</div>
168219
);
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { type EnvironmentId } from "@t3tools/contracts";
2+
import { SquarePenIcon } from "lucide-react";
3+
4+
import { Button } from "../ui/button";
5+
6+
import { GridThreadPicker } from "./GridThreadPicker";
7+
8+
interface GridEmptyPaneProps {
9+
environmentId: EnvironmentId;
10+
excludedThreadKeys: ReadonlySet<string>;
11+
onSelectThread: (threadKey: string) => void;
12+
onRequestNewThread: () => void;
13+
densityClass: string;
14+
}
15+
16+
export function GridEmptyPane({
17+
environmentId,
18+
excludedThreadKeys,
19+
onSelectThread,
20+
onRequestNewThread,
21+
densityClass,
22+
}: GridEmptyPaneProps) {
23+
return (
24+
<div className="flex h-full min-h-0 flex-col items-center justify-center gap-3 bg-background p-3 text-center">
25+
<div className="text-xs text-muted-foreground">Empty pane</div>
26+
<div className={`flex flex-col items-center gap-2 ${densityClass}`}>
27+
<GridThreadPicker
28+
environmentId={environmentId}
29+
excludedThreadKeys={excludedThreadKeys}
30+
onSelect={onSelectThread}
31+
triggerLabel="Pick thread"
32+
/>
33+
<Button
34+
variant="outline"
35+
size="xs"
36+
className="gap-1.5"
37+
onClick={onRequestNewThread}
38+
aria-label="Start a new thread in this cell"
39+
>
40+
<SquarePenIcon className="size-3" />
41+
New thread
42+
</Button>
43+
</div>
44+
<div className="text-[10px] text-muted-foreground">
45+
Click a thread from the sidebar, or use "New thread".
46+
</div>
47+
</div>
48+
);
49+
}

0 commit comments

Comments
 (0)