Skip to content
62 changes: 46 additions & 16 deletions app/src/components/app-sidebar/channel-item-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import type { MessageListEmphasis } from "@/lib/settings/message-list";
* the row ends in the unread dot instead. The dot has a place of its own at the row's end, kept
* empty on such a row with nothing unread, so every row's dot is in one column, and the pin and the
* age line up before it. The pin used to come after the dot, and on a pinned row pushed it out of
* the column. A row whose orb says it keeps no place for a dot.
* the column. A row whose orb says it keeps no place for a dot. A row under its Bot in the Bots
* panel, which has no orb, says it with the same arcs in the dot's color instead, coming out of the
* end of its title at the last letter's upper-right corner (`.waiting-arcs-right` in styles.css),
* and keeps no place for a dot either.
*
* A conversation a routine spoke in last, with nothing written since (`routine`), has a small clock
* drawn inside its Bot's orb (`BotOrb`'s `startedBy`), so a routine's conversations read apart from
Expand Down Expand Up @@ -68,14 +71,17 @@ export function ChannelItemContent({
// Whether the row's orb says it is unread: one Bot's orb, drawn (a compact row under its Bot has none).
const oneOrb = useOneOrb(participantIds);
const onOrb = oneOrb && (view !== "compact" || avatar);
const unreadDot = onOrb ? null : unread ? (
<span
className="size-2 shrink-0 rounded-full bg-primary"
data-slot="unread-dot"
/>
) : (
<span aria-hidden="true" className="size-2 shrink-0" />
);
// Under its Bot (a compact row with no avatar), the arcs at the title's end say it.
const underItsBot = view === "compact" && !avatar;
const unreadDot =
onOrb || underItsBot ? null : unread ? (
<span
className="size-2 shrink-0 rounded-full bg-primary"
data-slot="unread-dot"
/>
) : (
<span aria-hidden="true" className="size-2 shrink-0" />
);
const pin = pinned ? (
<IconPinFilled
className="size-3 shrink-0 text-muted-foreground"
Expand Down Expand Up @@ -139,13 +145,37 @@ export function ChannelItemContent({
{avatar ? (
<span className="sr-only" data-slot="bot-name">{`${name}, `}</span>
) : null}
<span
className={`min-w-0 flex-1 truncate text-sm leading-5 tracking-[-1%] ${unread ? "font-semibold" : "font-normal"}`}
title={title}
>
{displayedTitle}
{caret}
</span>
{/*
* Under its Bot, something new: the waiting arcs at the end of the title. The title is only
* as wide as its text there, so they hang right where it ends, or after its ellipsis when it
* is cut short, from a place 6px wide that keeps them clear of what comes after.
*/}
{underItsBot && unread ? (
<span className="flex min-w-0 flex-1 items-center">
<span
className="min-w-0 truncate font-semibold text-sm leading-5 tracking-[-1%]"
title={title}
>
{displayedTitle}
{caret}
</span>
<span
aria-hidden="true"
className="relative w-1.5 shrink-0 self-stretch"
data-slot="unread-arcs"
>
<span className="waiting-arcs-right" />
</span>
</span>
) : (
<span
className={`min-w-0 flex-1 truncate text-sm leading-5 tracking-[-1%] ${unread ? "font-semibold" : "font-normal"}`}
title={title}
>
{displayedTitle}
{caret}
</span>
)}
{time}
{pin}
{unreadDot}
Expand Down
58 changes: 53 additions & 5 deletions app/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -748,9 +748,11 @@
* (`--bot-orb-color`, set on the orb), drawn a little toward the text color so they hold against
* the surface: deeper in light, brighter in dark. The near arc sits 2px clear of the orb's edge and
* the far one 3px past it, reaching 6px out; the far one is a shade fainter, as a sound dies away.
* Each sweeps 60°, centred at half past one, and fades out at both ends, so neither ends in a hard
* stop. Between them, and between arc and orb, is whatever is behind, a row's hover included. They
* scale with the orb; these sizes are at the sidebar's 24px.
* Each sweeps 60°, centred at about twenty to two, and fades out at both ends, so neither ends in a
* hard stop. They face the way the arcs coming out of an unread conversation's title do
* (`.waiting-arcs-right` below), so the two read as one sign. Between them, and between arc and
* orb, is whatever is behind, a row's hover included. They scale with the
* orb; these sizes are at the sidebar's 24px.
*
* They come in once, as the state comes: they fade in and settle out from the orb, over the app's
* entrance (200ms, lib/motion.ts), and go the same way back. Nothing pulses. Under reduced motion
Expand Down Expand Up @@ -788,13 +790,13 @@
transparent calc(var(--bot-orb-unit) * 18.25)
);
-webkit-mask-image: conic-gradient(
from 15deg,
from 20deg,
transparent 0deg,
#000 9deg 51deg,
transparent 60deg
);
mask-image: conic-gradient(
from 15deg,
from 20deg,
transparent 0deg,
#000 9deg 51deg,
transparent 60deg
Expand Down Expand Up @@ -825,6 +827,52 @@
}
}

/*
* A conversation under its Bot in the Bots panel with something new in it (`ChannelItemContent`, a
* row with no orb of its own): the waiting arcs a Bot's orb wears, facing the same way, coming out
* of the end of the title as the orb's come out of the orb. They are drawn round a point in the
* title's last letter (2.5px in from where the text ends, at the line's middle) and sit at that
* letter's upper-right corner, as the orb's sit at the orb's: the same 60° about twenty to two.
* Their shape is the orb's, scaled to a letter, the near arc about 3.5px clear of the letter's
* corner, a little more than the orb's 2.25px, as letters have corners and an orb has none; the
* far one 3px past it, so the pair reads as short as it does round an orb. In the dot's color (`--primary`: near black in light, near white
* in dark), the far arc a shade fainter and half the weight, both fading out at their ends as the
* orb's do. They reach 1-2px above the line, into the row's own padding, and about 10px past the
* text, where the row keeps them 6px of their own before its gap (`ChannelItemContent`), so they
* stay clear of the age, the pin or the row's edge after them. When the title is cut short, they
* come out of its ellipsis.
*/
.waiting-arcs-right {
/* How far the far arc reaches from the centre, which is the box's left foot. */
--arcs-reach: 12.85px;
position: absolute;
left: -2.5px;
top: calc(50% - var(--arcs-reach));
width: var(--arcs-reach);
height: var(--arcs-reach);
pointer-events: none;
background: radial-gradient(
circle at 0 var(--arcs-reach),
transparent 8.35px,
var(--primary) 8.85px 9.85px,
transparent 10.35px 11.35px,
color-mix(in oklab, var(--primary) 75%, transparent) 11.85px 12.35px,
transparent var(--arcs-reach)
);
-webkit-mask-image: conic-gradient(
from 20deg at 0 var(--arcs-reach),
transparent 0deg,
#000 9deg 51deg,
transparent 60deg
);
mask-image: conic-gradient(
from 20deg at 0 var(--arcs-reach),
transparent 0deg,
#000 9deg 51deg,
transparent 60deg
);
}

/*
* A Bot whose routine spoke last (`BotOrb`'s `startedBy` "routine"): a small clock inside its orb,
* so a routine's conversation reads apart from the person's own. A pale, soft-edged dial breathed
Expand Down
151 changes: 137 additions & 14 deletions app/tests/bots-panel-waiting-arcs.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -353,13 +353,15 @@ const MARGIN = 7;
/**
* Where on a 24px orb to look, as an angle clockwise from twelve o'clock and a distance from the
* orb's middle, in CSS pixels. The orb's edge is 12 out; the near arc's line runs from 14.25 to
* 15.25 and the far one's from 17.25 to 17.75, each over a sweep centred at half past one (45°).
* 15.25 and the far one's from 17.25 to 17.75, each over a sweep centred at about twenty to two
* (50°). The orb's upper left and other sides are bare.
*/
const POINTS = {
near: [45, 14.75],
far: [45, 17.5],
gap: [45, 13.1],
between: [45, 16.25],
near: [50, 14.75],
far: [50, 17.5],
gap: [50, 13.1],
between: [50, 16.25],
upperLeft: [315, 14.75],
left: [270, 14.75],
below: [180, 14.75],
lowerLeft: [225, 14.75],
Expand Down Expand Up @@ -478,6 +480,7 @@ async function calling(
contrast(seen.far, seen.surface) < contrast(seen.near, seen.surface),
clear: bareAt(seen.gap, seen.surface) && bareAt(seen.between, seen.surface),
upperRight:
bareAt(seen.upperLeft, seen.surface) &&
bareAt(seen.left, seen.surface) &&
bareAt(seen.below, seen.surface) &&
bareAt(seen.lowerLeft, seen.surface),
Expand Down Expand Up @@ -573,9 +576,12 @@ describe.skipIf(!asked)(

/*
* Opening a Bot answers nothing that waits on the person, so its arcs stay while it is open. Its
* conversations under it have no orb of their own, so the unread one keeps its dot.
* conversations under it have no orb of their own, so the unread one says it with the same arcs,
* coming out of the end of its title at the last letter's upper-right corner, in the dot's
* color: at the end of the text, clear of its letters, inside the row and clear of the row above,
* and standing out from the surface.
*/
test("the arcs stay while the Bot is open and after it closes; its unread conversation under it keeps its dot", async () => {
test("the arcs stay while the Bot is open and after it closes; its unread conversation under it has the arcs at its title's end", async () => {
for (const [engine, browser] of engines) {
for (const theme of THEMES) {
const page = await open(browser, { theme });
Expand Down Expand Up @@ -604,15 +610,132 @@ describe.skipIf(!asked)(
upperRight: true,
standsOut: true,
});
const unreadDots = await panel(page)
.locator(
'[data-slot="bot-conversation-row"] [data-slot="unread-dot"]',
)
.count();
expect({ engine, theme, unreadDots }).toEqual({
const rows = panel(page).locator(
'[data-slot="bot-conversation-row"]',
);
const row = rows.filter({ hasText: "Which vendors to shortlist" });
// From a little before the end of the title's text to the row's end, and from a little
// above the row to the title's foot, in CSS pixels. The title is only as wide as its text.
const where = await row.evaluate((row) => {
const title = row.querySelector(
"[data-slot=unread-arcs]",
)?.previousElementSibling;
if (!title) return null;
const t = title.getBoundingClientRect();
const r = row.getBoundingClientRect();
return {
textEnd: t.right,
rowRight: r.right,
rowTop: r.top,
bottom: t.bottom,
};
});
if (!where) throw new Error("no row");
const ABOVE = 4;
const BEFORE = 16;
const clip = {
x: where.textEnd - BEFORE,
y: where.rowTop - ABOVE,
width: where.rowRight - (where.textEnd - BEFORE),
height: where.bottom - (where.rowTop - ABOVE),
};
// The arcs' ink is what changes when they are hidden; the title's is what is left.
const arcs = row.locator(".waiting-arcs-right");
const drawn = await page.screenshot({ clip });
await arcs.evaluate((each) => {
(each as HTMLElement).style.visibility = "hidden";
});
const bare = await page.screenshot({ clip });
await arcs.evaluate((each) => {
(each as HTMLElement).style.visibility = "";
});
const ink = await page.evaluate(
async ({ shots, theme, width }) => {
const pixels = async (base64: string) => {
const image = new Image();
image.src = `data:image/png;base64,${base64}`;
await image.decode();
const canvas = document.createElement("canvas");
canvas.width = image.naturalWidth;
canvas.height = image.naturalHeight;
const context = canvas.getContext("2d");
if (!context) throw new Error("no 2d context");
context.drawImage(image, 0, 0);
return context.getImageData(
0,
0,
canvas.width,
canvas.height,
);
};
const [drawn, bare] = await Promise.all(shots.map(pixels));
if (!drawn || !bare) throw new Error("no shots");
const scale = drawn.width / width;
const level = (data: Uint8ClampedArray, at: number) =>
((data[at] ?? 0) +
(data[at + 1] ?? 0) +
(data[at + 2] ?? 0)) /
3;
const surface = level(bare.data, 0);
const arcs: [number, number][] = [];
const text: [number, number][] = [];
let best = surface;
for (let y = 0; y < drawn.height; y++)
for (let x = 0; x < drawn.width; x++) {
const at = (y * drawn.width + x) * 4;
const with_ = level(drawn.data, at);
const without = level(bare.data, at);
if (Math.abs(with_ - without) >= 40) {
arcs.push([x, y]);
best =
theme === "light"
? Math.min(best, with_)
: Math.max(best, with_);
}
if (Math.abs(without - surface) >= 40) text.push([x, y]);
}
let first = Infinity;
let last = -Infinity;
let top = Infinity;
let nearest = Infinity;
for (const [x, y] of arcs) {
first = Math.min(first, x / scale);
last = Math.max(last, (x + 1) / scale);
top = Math.min(top, y / scale);
for (const [u, v] of text)
nearest = Math.min(
nearest,
Math.hypot(x - u, y - v) / scale,
);
}
return { count: arcs.length, first, last, top, nearest, best };
},
{
shots: [drawn, bare].map((shot) => shot.toString("base64")),
theme,
width: clip.width,
},
);
expect({
engine,
theme,
dots: await rows.locator('[data-slot="unread-dot"]').count(),
arcs: await rows.locator('[data-slot="unread-arcs"]').count(),
drawn: ink.count > 0,
atTheEnd: ink.first >= BEFORE - 4,
inItsRow: ink.top >= ABOVE && ink.last <= clip.width - 1,
clearOfTitle: ink.nearest >= 1,
inked: theme === "light" ? ink.best < 90 : ink.best > 165,
}).toEqual({
engine,
theme,
unreadDots: 1,
dots: 0,
arcs: 1,
drawn: true,
atTheEnd: true,
inItsRow: true,
clearOfTitle: true,
inked: true,
});

await research.getByRole("button", { name: /^Research/ }).click();
Expand Down
24 changes: 22 additions & 2 deletions app/tests/compact-conversations.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ test("where Bots are orbs, an unread conversation's orb wears the arcs and its r
}
});

test("where there is no lone orb to wear the arcs, an unread row keeps its dot", () => {
test("where there is no lone orb to wear the arcs, an unread row keeps its dot, but under its Bot the arcs are at its title's end", () => {
const group = compactRow(
{ unread: true, participantIds: ["bot-1", "bot-2"] },
"orb",
Expand All @@ -210,11 +210,31 @@ test("where there is no lone orb to wear the arcs, an unread row keeps its dot",
expect((each as HTMLElement).dataset.state).toBe("idle");
group.unmount();

// Under its Bot: no dot, nor a place kept for one; the arcs hang from just after the title, which is
// only as wide as its text, at its last letter's upper-right corner, unseen by a screen reader as
// the dot was.
const underItsBot = compactRow({ unread: true, avatar: false }, "orb");
expect(
underItsBot.container.querySelector("[data-slot=unread-dot]"),
).not.toBeNull();
).toBeNull();
const arcs = underItsBot.container.querySelector(
"[data-slot=unread-arcs]",
) as HTMLElement;
expect(arcs.getAttribute("aria-hidden")).toBe("true");
expect(arcs.previousElementSibling?.textContent).toBe(
"Trip budget for Lisbon",
);
expect(arcs.previousElementSibling?.classList.contains("flex-1")).toBe(false);
expect(arcs.querySelector(".waiting-arcs-right")).not.toBeNull();
expect(
underItsBot.container.querySelector("[aria-hidden=true].size-2"),
).toBeNull();
underItsBot.unmount();
const readUnderItsBot = compactRow({ unread: false, avatar: false }, "orb");
expect(
readUnderItsBot.container.querySelector("[data-slot=unread-arcs]"),
).toBeNull();
readUnderItsBot.unmount();

const face = compactRow({ unread: true }, "face");
expect(face.container.querySelector("[data-slot=unread-dot]")).not.toBeNull();
Expand Down
Loading