Skip to content

Commit 12bbc07

Browse files
t3dotggclaude
andcommitted
fix(web): workspace card docks beside chat when the window is narrow
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 43bd667 commit 12bbc07

7 files changed

Lines changed: 94 additions & 23 deletions

File tree

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import { ChatCanvasContext } from "./ChatCanvasContext";
1111
import { resolveChatCanvasLayout, type ChatCanvasPreview } from "./chatCanvasLayout";
1212
import type { PreviewMiniPlayerObstacles } from "../preview/previewMiniPlayerLayout";
1313

14-
/** Owns the available conversation space. Floating cards never reserve it themselves. */
14+
/**
15+
* Owns the available conversation space. Cards only report where they sit; the
16+
* canvas decides when chat moves over to make room for them.
17+
*/
1518
export function ChatCanvas({
1619
composerOverlayElement,
1720
children,
@@ -96,6 +99,7 @@ export function ChatCanvas({
9699
const container = { width: measurements.width, height: measurements.height };
97100
return {
98101
container,
102+
lane: { padding: measurements.padding, minChatWidth: measurements.minChatWidth },
99103
layout: resolveChatCanvasLayout({ ...measurements, container, preview, detailsCard }),
100104
previewKey: preview?.key ?? null,
101105
reportPreview,

‎apps/web/src/components/chat/ChatCanvasContext.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { PreviewMiniPlayerObstacles } from "../preview/previewMiniPlayerLay
44

55
export const ChatCanvasContext = createContext<{
66
container: { width: number; height: number };
7+
lane: { padding: number; minChatWidth: number };
78
layout: ReturnType<typeof resolveChatCanvasLayout>;
89
previewKey: string | null;
910
reportPreview: (preview: ChatCanvasPreview) => void;

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,17 @@ export function ThreadDetailsCard({
2929
const preferredPlacement = canvas
3030
? resolveThreadDetailsCardLayout({
3131
container: canvas.container,
32-
chat: canvas.layout.chat,
32+
lane: canvas.lane,
3333
frame: null,
3434
})
3535
: null;
3636
const placement = canvas
37-
? resolveThreadDetailsCardLayout({ container: canvas.container, ...canvas.layout })
37+
? resolveThreadDetailsCardLayout({
38+
container: canvas.container,
39+
lane: canvas.lane,
40+
frame: canvas.layout.frame,
41+
overlapsDetailsCard: canvas.layout.overlapsDetailsCard,
42+
})
3843
: null;
3944
const mode = placement ? "inline" : "popover";
4045
const inlineOpen = useRightPanelStore((state) =>

‎apps/web/src/components/chat/chatCanvasLayout.test.ts‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,12 @@ describe("chat canvas layout", () => {
212212
});
213213
};
214214
const density = (result: ReturnType<typeof layout>) => {
215-
const card = resolveThreadDetailsCardLayout({ container, ...result });
215+
const card = resolveThreadDetailsCardLayout({
216+
container,
217+
lane: { padding: 20, minChatWidth: 640 },
218+
frame: result.frame,
219+
overlapsDetailsCard: result.overlapsDetailsCard,
220+
});
216221
return card
217222
? resolveThreadDetailsCardDensity(card.height, { full: 327, compact: 182 })
218223
: "hidden";
@@ -251,3 +256,38 @@ describe("chat canvas layout", () => {
251256
expect(result.frame).toEqual({ x: 272, y: 396, width: 1300, height: 400 });
252257
});
253258
});
259+
260+
describe("workspace card docking", () => {
261+
const withCard = (width: number, player: ChatCanvasPreview | null = null) =>
262+
resolveChatCanvasLayout({
263+
container: { width, height: 900 },
264+
maxChatWidth: 736,
265+
composerHeight: 180,
266+
detailsCard: { left: width - 324, right: width - 12, bottom: 400 },
267+
preview: player,
268+
});
269+
it("floats the card while the centered chat stays clear of it", () => {
270+
expect(withCard(1576).chat).toEqual({ left: 420, width: 736, insetStart: 0, insetEnd: 0 });
271+
});
272+
it("docks the card and centers chat beside it once the margin is tight", () => {
273+
expect(withCard(1575).chat).toEqual({
274+
left: 251.5,
275+
width: 736,
276+
insetStart: 0,
277+
insetEnd: 336,
278+
});
279+
expect(withCard(1411).chat).toMatchObject({ left: 169.5, width: 736 });
280+
});
281+
it("shrinks docked chat down to its readable width", () => {
282+
expect(withCard(1100).chat).toEqual({ left: 20, width: 724, insetStart: 0, insetEnd: 336 });
283+
expect(withCard(1016).chat).toMatchObject({ left: 20, width: 640 });
284+
});
285+
it("keeps docked chat in place when a new preview opens below the card", () => {
286+
expect(withCard(1411, preview)).toEqual({
287+
chat: { left: 169.5, width: 736, insetStart: 0, insetEnd: 336 },
288+
frame: { x: 1079, y: 688, width: 320, height: 200 },
289+
overlapsChat: false,
290+
overlapsDetailsCard: false,
291+
});
292+
});
293+
});

‎apps/web/src/components/chat/chatCanvasLayout.ts‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ export interface ChatCanvasPreview {
1919
}
2020

2121
const GAP = 12;
22+
// The workspace card floats in the right margin only while the centered chat
23+
// stays this far from it. Closer than this, the card looks stuck to the chat.
24+
const DETAILS_CARD_FLOAT_CLEARANCE = 96;
2225

23-
/** Pure geometry shared by the conversation, composer, and floating preview. */
26+
/** Pure geometry shared by the conversation, composer, workspace card, and floating preview. */
2427
export function resolveChatCanvasLayout({
2528
container,
2629
preview,
@@ -38,9 +41,22 @@ export function resolveChatCanvasLayout({
3841
composerHeight?: number;
3942
detailsCard?: PreviewMiniPlayerObstacles["detailsCard"];
4043
}) {
41-
const normalWidth = Math.max(0, Math.min(maxChatWidth, container.width - padding * 2));
42-
const normalLeft = (container.width - normalWidth) / 2;
43-
let chat = { left: normalLeft, width: normalWidth, insetStart: 0, insetEnd: 0 };
44+
const centeredWidth = Math.max(0, Math.min(maxChatWidth, container.width - padding * 2));
45+
// Without that clearance the card docks like a sidebar, and chat centers in
46+
// the space to its left.
47+
const laneRight =
48+
detailsCard &&
49+
(container.width + centeredWidth) / 2 + DETAILS_CARD_FLOAT_CLEARANCE > detailsCard.left
50+
? detailsCard.left - GAP
51+
: container.width;
52+
const normalWidth = Math.max(0, Math.min(maxChatWidth, laneRight - padding * 2));
53+
const normalLeft = (laneRight - normalWidth) / 2;
54+
let chat = {
55+
left: normalLeft,
56+
width: normalWidth,
57+
insetStart: 0,
58+
insetEnd: container.width - laneRight,
59+
};
4460
let frame: PreviewMiniPlayerFrame | null = null;
4561
let overlapsChat = false;
4662
if (preview && container.width > 0 && container.height > 0) {

‎apps/web/src/components/chat/threadDetailsCardLayout.test.ts‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,39 @@ import {
44
resolveThreadDetailsCardLayout,
55
} from "./threadDetailsCardLayout";
66

7+
const lane = { padding: 20, minChatWidth: 640 };
78
const resolve = (width: number, height: number, previewY: number | null = null) =>
89
resolveThreadDetailsCardLayout({
910
container: { width, height },
10-
chat: { left: (width - 736) / 2, width: 736 },
11+
lane,
1112
frame: previewY === null ? null : { x: width - 332, y: previewY, width: 320, height: 240 },
1213
});
1314

14-
describe("floating details card", () => {
15-
it("uses the right margin without reserving chat space", () => {
15+
describe("workspace card", () => {
16+
it("pins to the top right at a fixed width", () => {
1617
expect(resolve(1600, 900)).toEqual({
1718
x: 1276,
1819
y: 12,
1920
width: 312,
2021
height: 876,
2122
});
22-
expect(resolve(1344, 900)?.width).toBe(280);
23+
expect(resolve(1344, 900)).toMatchObject({ x: 1020, width: 312 });
2324
});
24-
it("hides when the margin cannot hold readable controls", () => {
25-
expect(resolve(1200, 900)).toBeNull();
25+
it("hides when a readable chat lane cannot fit beside it", () => {
26+
expect(resolve(1016, 900)).toMatchObject({ x: 692 });
27+
expect(resolve(1015, 900)).toBeNull();
2628
});
2729
it("keeps the card at the top right while the preview is freely dragged vertically", () => {
2830
for (const y of [12, 170, 250, 400, 648]) {
2931
expect(resolve(1600, 900, y)).toEqual({ x: 1276, y: 12, width: 312, height: 876 });
3032
}
3133
});
32-
it("keeps width and height independent", () => {
33-
expect(resolve(1344, 900, 600)).toMatchObject({ width: 280, height: 876 });
34+
it("keeps full height while a preview stays clear of the card", () => {
35+
expect(resolve(1344, 900, 600)).toMatchObject({ width: 312, height: 876 });
3436
expect(
3537
resolveThreadDetailsCardLayout({
3638
container: { width: 1600, height: 900 },
37-
chat: { left: 432, width: 736 },
39+
lane,
3840
frame: { x: 12, y: 100, width: 320, height: 240 },
3941
})?.height,
4042
).toBe(876);
@@ -45,7 +47,7 @@ describe("card content fitting", () => {
4547
const place = (previewY: number, previewHeight = 365, overlapsDetailsCard = false) =>
4648
resolveThreadDetailsCardLayout({
4749
container: { width: 1584, height: 988 },
48-
chat: { left: 424, width: 736 },
50+
lane,
4951
frame: { x: 1260, y: previewY, width: 240, height: previewHeight },
5052
overlapsDetailsCard,
5153
});

‎apps/web/src/components/chat/threadDetailsCardLayout.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,25 @@ export function resolveThreadDetailsCardDensity(
99
return "essential";
1010
}
1111

12-
/** The card uses leftover space. It never changes the conversation's width. */
12+
/**
13+
* The card pins to the top right while a readable chat lane fits beside it.
14+
* The chat canvas decides whether chat moves over to make room.
15+
*/
1316
export function resolveThreadDetailsCardLayout({
1417
container,
15-
chat,
18+
lane,
1619
frame,
1720
overlapsDetailsCard = false,
1821
}: {
1922
container: { width: number; height: number };
20-
chat: { left: number; width: number };
23+
lane: { padding: number; minChatWidth: number };
2124
frame: PreviewMiniPlayerFrame | null;
2225
overlapsDetailsCard?: boolean;
2326
}) {
2427
const gap = 12;
25-
const width = Math.min(312, container.width - chat.left - chat.width - gap * 2);
26-
if (width < 240) return null;
28+
const width = 312;
2729
const x = container.width - width - gap;
30+
if (x - gap - lane.padding * 2 < lane.minChatWidth) return null;
2831
// Resizing consumes the height above the player. Dragging first tries to
2932
// clear the full card and folds it only when there is no readable placement.
3033
const height =

0 commit comments

Comments
 (0)