Skip to content

Commit 55c4675

Browse files
radroidclaude
authored andcommitted
feat(web): make the thread outbox read as composer chrome, and let it be reordered (#35)
Issue #35 §1: the queued-message list was visually heavier than the messages it held. It rendered four bordered cards inside the composer's own 22px outline, so a one-line message got card-sized padding and three or four queued messages pushed the prompt well up the viewport. The `QUEUED MESSAGES · N` caption collided with the container's top border, the edit/delete icons were always visible and pinned far right away from the text they act on, nothing anywhere stated that queued messages send themselves, and there was no way to reorder them. The list already renders *inside* `chat-composer-glass-host`, so the fix is to stop drawing a second container: - One dense row per message: a single truncated line, an ordinal, no border, hover background. The block is capped at `max-h-40` and scrolls, so a long queue can no longer push the composer up. - One hairline under the block instead of a card per row, so the queue reads as the top section of the composer surface. - The caption now sits inside the padded block and carries the contract: "Sends automatically when the chat is ready" — phrased to hold for both reasons a message queues, a running turn and a dropped connection. - Row actions are revealed on hover, on keyboard focus anywhere in the row, and unconditionally on coarse pointers, which have no hover to reveal them. - Beside the Queue button, Stop drops to a quiet outline. A saturated red circle should not be the highest-contrast element in the composer while the primary action is Queue. Upstream's filled treatment is untouched and still used wherever Stop is the only action. Reordering needed a persisted key. `createdAt` could not be reused: it is sent verbatim as the turn-start command's timestamp, so it becomes the message's permanent createdAt/updatedAt in server-side thread history and feeds the client's queued-turn-start grace window. Moving a message would have rewritten its history timestamp. Instead `QueuedThreadMessage` gains an *optional* `sortKey`, which keeps the persisted schema at version 1 — the version literal is a `Schema.Literals`, and storage swallows a decode failure as "skip invalid", so a bump would have silently emptied every existing queue on upgrade. A move re-deals the queue's existing ordering slots to the permuted order rather than inventing new keys, so a reordered message can never sort past one enqueued later, and only the messages that actually moved are written. Ties now break on messageId: the order is user-editable, and `load` returns messages in localStorage key-enumeration order, which is browser-defined, so two messages queued in the same millisecond could otherwise swap places across a reload. Verified against a seeded local environment: a four-message queue renders in ~130px against ~230px before, hover reveals the actions, and moving row 3 up survives a full page reload with only the two swapped records rewritten and every createdAt intact. Confirmed in light and dark. Seam impact: the only upstream-owned file touched is `ComposerPrimaryActions.tsx`, which already has a row in the ledger; its row and the header totals are updated here (+56/-13 → +71/-13, risk 276 → 336, totals +1516 → +1531). Everything else is fork-owned. This also records the web outbox as an undeclared logic mirror of upstream's mobile one, which it was already, and which this commit deliberately diverges further. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent 3f8e11c commit 55c4675

7 files changed

Lines changed: 482 additions & 31 deletions

File tree

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,13 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
9191
environmentIdentificationMode === "artwork",
9292
);
9393

94-
const stopButton = (
94+
const renderStopButton = (emphasisClassName: string) => (
9595
<button
9696
type="button"
97-
className="flex size-8 cursor-pointer items-center justify-center rounded-full bg-destructive/90 text-white shadow-xs shadow-destructive/24 inset-shadow-[0_1px_--theme(--color-white/16%)] transition-all duration-150 hover:bg-destructive hover:scale-105 active:inset-shadow-[0_1px_--theme(--color-black/8%)] active:shadow-none sm:h-8 sm:w-8"
97+
className={cn(
98+
"flex size-8 cursor-pointer items-center justify-center rounded-full transition-all duration-150 sm:h-8 sm:w-8",
99+
emphasisClassName,
100+
)}
98101
{...pointerFocusProps}
99102
onClick={onInterrupt}
100103
aria-label="Stop generation"
@@ -105,6 +108,18 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
105108
</button>
106109
);
107110

111+
// The filled treatment, used wherever Stop is the only action in the footer.
112+
const stopButton = renderStopButton(
113+
"bg-destructive/90 text-white shadow-xs shadow-destructive/24 inset-shadow-[0_1px_--theme(--color-white/16%)] hover:bg-destructive hover:scale-105 active:inset-shadow-[0_1px_--theme(--color-black/8%)] active:shadow-none",
114+
);
115+
116+
// Beside the Queue button, Stop is the secondary action, so it drops to a
117+
// quiet outline: a saturated red circle should not be the highest-contrast
118+
// element in the composer while the primary action is Queue.
119+
const secondaryStopButton = renderStopButton(
120+
"border border-border/60 bg-background/40 text-muted-foreground hover:border-destructive/40 hover:bg-destructive/10 hover:text-destructive",
121+
);
122+
108123
const queueButton = (
109124
<Button
110125
type="submit"
@@ -177,7 +192,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
177192
if (canQueue) {
178193
return (
179194
<div className={cn("flex items-center justify-end", compact ? "gap-1.5" : "gap-2")}>
180-
{stopButton}
195+
{secondaryStopButton}
181196
{queueButton}
182197
</div>
183198
);

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

Lines changed: 87 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import type { EnvironmentId, MessageId, ThreadId } from "@t3tools/contracts";
2-
import { CheckIcon, PencilIcon, Trash2Icon, XIcon } from "lucide-react";
2+
import { ArrowDownIcon, ArrowUpIcon, CheckIcon, PencilIcon, Trash2Icon, XIcon } from "lucide-react";
33
import { useCallback, useEffect, useRef, useState } from "react";
44

55
import {
66
holdEditingThreadOutboxMessage,
7+
moveThreadOutboxMessage,
78
releaseEditingThreadOutboxMessage,
89
removeThreadOutboxMessage,
910
updateThreadOutboxMessage,
@@ -15,9 +16,14 @@ import { Button } from "../ui/button";
1516
import { Textarea } from "../ui/textarea";
1617

1718
/**
18-
* The visible pending-queue for the active thread, rendered just above the
19-
* composer. Each queued message is editable in place and removable; the drain
20-
* (useThreadOutboxDrain) sends the head automatically once the thread settles.
19+
* The visible pending-queue for the active thread. It renders *inside* the
20+
* composer's glass host, so it is deliberately chrome-less: one dense row per
21+
* message, separated from the prompt by a single hairline. Boxing each row
22+
* would put a second bordered container inside the composer's own 22px outline.
23+
*
24+
* Each queued message is editable in place, removable, and can be moved within
25+
* the queue; the drain (useThreadOutboxDrain) sends the head automatically once
26+
* the thread settles.
2127
*/
2228
export function ThreadOutboxQueueList({
2329
environmentId,
@@ -33,22 +39,45 @@ export function ThreadOutboxQueueList({
3339
}
3440

3541
return (
36-
<div className="mx-auto mb-1.5 w-full max-w-3xl">
37-
<div className="flex items-center justify-between px-1 pb-1">
38-
<span className="text-[11px] font-medium uppercase tracking-wide text-muted-foreground/70">
39-
Queued {queue.length === 1 ? "message" : "messages"} · {queue.length}
42+
<div className="border-border/40 border-b px-2.5 pt-2.5 pb-1.5 sm:px-3 sm:pt-3">
43+
<div className="flex items-baseline gap-1.5 px-1 pb-1 text-[11px] text-muted-foreground/70 leading-none">
44+
<span className="font-medium">
45+
{queue.length} queued {queue.length === 1 ? "message" : "messages"}
4046
</span>
47+
<span aria-hidden="true">·</span>
48+
{/* The contract, which was previously nowhere in the UI. Phrased to hold
49+
for both reasons a message queues: a running turn, and a dropped
50+
connection. */}
51+
<span className="truncate">Sends automatically when the chat is ready</span>
4152
</div>
42-
<ul className="flex flex-col gap-1.5">
43-
{queue.map((message) => (
44-
<QueuedMessageRow key={message.messageId} message={message} />
53+
{/* Capped so a long queue scrolls instead of pushing the composer up the
54+
viewport. */}
55+
<ul className="flex max-h-40 flex-col overflow-y-auto overscroll-contain">
56+
{queue.map((message, index) => (
57+
<QueuedMessageRow
58+
key={message.messageId}
59+
canMoveDown={index < queue.length - 1}
60+
canMoveUp={index > 0}
61+
message={message}
62+
position={index + 1}
63+
/>
4564
))}
4665
</ul>
4766
</div>
4867
);
4968
}
5069

51-
function QueuedMessageRow({ message }: { message: QueuedThreadMessage }) {
70+
function QueuedMessageRow({
71+
canMoveDown,
72+
canMoveUp,
73+
message,
74+
position,
75+
}: {
76+
canMoveDown: boolean;
77+
canMoveUp: boolean;
78+
message: QueuedThreadMessage;
79+
position: number;
80+
}) {
5281
const [isEditing, setIsEditing] = useState(false);
5382
const [draft, setDraft] = useState(message.text);
5483
const [busy, setBusy] = useState(false);
@@ -106,9 +135,21 @@ function QueuedMessageRow({ message }: { message: QueuedThreadMessage }) {
106135
}
107136
}, [message]);
108137

138+
const move = useCallback(
139+
async (direction: "up" | "down") => {
140+
setBusy(true);
141+
try {
142+
await moveThreadOutboxMessage(message, direction);
143+
} finally {
144+
setBusy(false);
145+
}
146+
},
147+
[message],
148+
);
149+
109150
if (isEditing) {
110151
return (
111-
<li className="rounded-lg border border-border/60 bg-card/70 p-2">
152+
<li className="py-1">
112153
<Textarea
113154
aria-label="Edit queued message"
114155
autoFocus
@@ -146,19 +187,45 @@ function QueuedMessageRow({ message }: { message: QueuedThreadMessage }) {
146187
return (
147188
<li
148189
className={cn(
149-
"group flex items-start gap-2 rounded-lg border border-border/50 bg-card/50 px-3 py-2 text-sm",
190+
"group flex items-center gap-2 rounded-md px-1 py-1 text-sm hover:bg-accent/40",
150191
busy && "opacity-50",
151192
)}
152193
>
153-
<p className="min-w-0 flex-1 whitespace-pre-wrap break-words text-foreground/90 line-clamp-3">
154-
{message.text}
155-
</p>
156-
<div className="flex shrink-0 items-center gap-0.5 opacity-60 transition-opacity group-hover:opacity-100">
194+
<span
195+
aria-hidden="true"
196+
className="w-3 shrink-0 text-right text-[11px] text-muted-foreground/50 tabular-nums"
197+
>
198+
{position}
199+
</span>
200+
{/* One line, truncated: a queued message is a reminder of what is coming,
201+
not something to read in full. Editing shows the whole text. */}
202+
<p className="min-w-0 flex-1 truncate text-foreground/80">{message.text}</p>
203+
{/* Revealed on hover, on keyboard focus anywhere in the row, and always on
204+
touch devices, which have no hover state to reveal them. */}
205+
<div className="flex shrink-0 items-center gap-0.5 opacity-0 transition-opacity group-focus-within:opacity-100 group-hover:opacity-100 pointer-coarse:opacity-100">
206+
<Button
207+
aria-label={`Move queued message ${position} up`}
208+
disabled={busy || !canMoveUp}
209+
onClick={() => void move("up")}
210+
size="icon-xs"
211+
variant="ghost"
212+
>
213+
<ArrowUpIcon className="size-3.5" />
214+
</Button>
215+
<Button
216+
aria-label={`Move queued message ${position} down`}
217+
disabled={busy || !canMoveDown}
218+
onClick={() => void move("down")}
219+
size="icon-xs"
220+
variant="ghost"
221+
>
222+
<ArrowDownIcon className="size-3.5" />
223+
</Button>
157224
<Button
158225
aria-label="Edit queued message"
159226
disabled={busy}
160227
onClick={beginEditing}
161-
size="icon-sm"
228+
size="icon-xs"
162229
variant="ghost"
163230
>
164231
<PencilIcon className="size-3.5" />
@@ -167,7 +234,7 @@ function QueuedMessageRow({ message }: { message: QueuedThreadMessage }) {
167234
aria-label="Remove queued message"
168235
disabled={busy}
169236
onClick={() => void remove()}
170-
size="icon-sm"
237+
size="icon-xs"
171238
variant="ghost"
172239
>
173240
{busy ? <XIcon className="size-3.5" /> : <Trash2Icon className="size-3.5" />}

0 commit comments

Comments
 (0)