Skip to content

Commit 342bee3

Browse files
committed
Add message bubbles with configurable colors and attached media layout
Signed-off-by: Arjun Mahanti <[email protected]>
1 parent cc0c47c commit 342bee3

19 files changed

Lines changed: 906 additions & 233 deletions

‎public/appearance-init.js‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,28 @@
1313
// Storage may be denied; the system palette still opens safely.
1414
}
1515
document.documentElement.dataset.colorMode = mode;
16+
let bubbleColor = "neutral";
17+
try {
18+
const value = localStorage.getItem("buzz-bubble-color.v1");
19+
if (
20+
[
21+
"neutral",
22+
"blue",
23+
"cyan",
24+
"green",
25+
"orange",
26+
"red",
27+
"pink",
28+
"lilac",
29+
"purple",
30+
"indigo",
31+
].includes(value)
32+
)
33+
bubbleColor = value;
34+
} catch {
35+
/* Neutral remains usable without storage. */
36+
}
37+
document.documentElement.dataset.bubbleColor = bubbleColor;
1638
let scale = 1;
1739
try {
1840
const value = Number(localStorage.getItem("buzz-font-scale.v1"));

‎src/app/AppearanceSettings.test.tsx‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,31 @@ it("does not hand off Reset focus when the settings form unmounts", () => {
201201
expect(focus).not.toHaveBeenCalled();
202202
appearance.dispose();
203203
});
204+
205+
it("selects and restores a message color, including retry after a failed save", async () => {
206+
const appearance = createAppearance();
207+
render(
208+
<ToastProvider>
209+
<AppearanceSettings appearance={appearance} />
210+
</ToastProvider>,
211+
);
212+
const save = vi
213+
.spyOn(Storage.prototype, "setItem")
214+
.mockImplementationOnce(() => {
215+
throw new Error("denied");
216+
});
217+
fireEvent.click(screen.getByRole("button", { name: "Blue message color" }));
218+
expect(
219+
screen.getByRole("button", { name: "Blue message color" }),
220+
).toHaveAttribute("aria-pressed", "true");
221+
expect(document.documentElement.dataset.bubbleColor).toBe("blue");
222+
fireEvent.click(
223+
screen.getByRole("button", { name: "Retry saving message color" }),
224+
);
225+
expect(localStorage.getItem("buzz-bubble-color.v1")).toBe("blue");
226+
save.mockRestore();
227+
appearance.dispose();
228+
const restored = createAppearance();
229+
expect(restored.snapshot().bubbleColor).toBe("blue");
230+
restored.dispose();
231+
});

‎src/app/AppearanceSettings.tsx‎

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import {
2+
BUBBLE_COLORS,
3+
messageButtonStyle,
4+
} from "../shared/theme/bubble-color";
5+
import { IconButton } from "../shared/design-system/ui/IconButton";
16
import { Header } from "../shared/design-system/ui/Header";
27
import { ToastNotice } from "../shared/design-system/ui/Toast";
38
import { Field } from "../shared/design-system/ui/Field";
@@ -39,10 +44,8 @@ export function AppearanceSettings({
3944
pendingFocus.current = null;
4045
if (target?.isConnected) target.focus();
4146
});
42-
const { preference, error, fontScale, fontError } = useSyncExternalStore(
43-
appearance.subscribe,
44-
appearance.snapshot,
45-
);
47+
const { preference, error, fontScale, fontError, bubbleColor, bubbleError } =
48+
useSyncExternalStore(appearance.subscribe, appearance.snapshot);
4649
return (
4750
<section aria-labelledby="appearance-settings-title">
4851
<Header id="appearance-settings-title" title="Appearance" />
@@ -74,6 +77,51 @@ export function AppearanceSettings({
7477
))}
7578
</RadioGroup>
7679
</Field>
80+
<fieldset className="m-0 mt-6 min-w-0 border-0 p-0">
81+
<legend className="mb-2 p-0 text-label-sm">Your message color</legend>
82+
<p className="mb-3 text-body-sm text-subtle">
83+
Used for your message bubbles and the send button on this device.
84+
</p>
85+
<div className="flex flex-wrap gap-2">
86+
{BUBBLE_COLORS.map((color) => (
87+
<IconButton
88+
key={color}
89+
data-bubble-color={color}
90+
style={messageButtonStyle}
91+
variant="primary"
92+
size="large"
93+
shape="round"
94+
aria-label={`${color.charAt(0).toUpperCase()}${color.slice(1)} message color`}
95+
title={`${color.charAt(0).toUpperCase()}${color.slice(1)}`}
96+
aria-pressed={bubbleColor === color}
97+
onClick={() => appearance.setBubbleColor(color)}
98+
icon={
99+
<span
100+
className={
101+
bubbleColor === color
102+
? "size-6 rounded-full border-2 border-current"
103+
: "size-6"
104+
}
105+
aria-hidden="true"
106+
/>
107+
}
108+
/>
109+
))}
110+
</div>
111+
</fieldset>
112+
{active && bubbleError && (
113+
<ToastNotice
114+
title="Message color wasn’t saved"
115+
description={bubbleError}
116+
>
117+
<Button
118+
size="sm"
119+
onClick={() => appearance.setBubbleColor(bubbleColor)}
120+
>
121+
Retry saving message color
122+
</Button>
123+
</ToastNotice>
124+
)}
77125
<fieldset className="m-0 mt-6 min-w-0 border-0 p-0">
78126
<legend className="mb-2 p-0 text-label-sm">Interface size</legend>
79127
<div className="flex flex-wrap items-center gap-3">

‎src/features/messages/AttachmentImage.tsx‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ImageIcon } from "../../shared/design-system/icons";
12
import { prepareReviewEntrance } from "./use-review-entrance";
23
import { useMediaCorners } from "./use-media-corners";
34
import { useEffect, useRef, useState } from "react";
@@ -53,7 +54,15 @@ export function AttachmentImage({
5354
}
5455
role="status"
5556
>
56-
Image unavailable
57+
{thumbnail ? (
58+
<>
59+
<ImageIcon size={20} aria-hidden="true" />
60+
<span aria-hidden="true">Unavailable</span>
61+
<span className="sr-only">Image unavailable</span>
62+
</>
63+
) : (
64+
"Image unavailable"
65+
)}
5766
</span>
5867
);
5968
return (

‎src/features/messages/ChannelTimeline.tsx‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,7 @@ function Timeline({
744744
{...(initialCache.current ? { cache: initialCache.current } : {})}
745745
>
746746
{rows.map((row, index) => {
747+
const nextRow = rows[index + 1];
747748
const day =
748749
index === 0
749750
? true
@@ -765,11 +766,8 @@ function Timeline({
765766
/>
766767
) : (
767768
<MessageRow
768-
layout={
769-
continuesMessageGroup(rows[index - 1], row)
770-
? "continuation"
771-
: "timeline"
772-
}
769+
stackPrevious={continuesMessageGroup(rows[index - 1], row)}
770+
stackNext={!!nextRow && continuesMessageGroup(row, nextRow)}
773771
session={queries}
774772
scope={scope}
775773
key={row.id}

‎src/features/messages/MessageComposer.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { messageButtonStyle } from "../../shared/theme/bubble-color";
12
import { useEffectEvent } from "react";
23
import { useMessageEditScope } from "./MessageEditScope";
34
import { useMessageDeletion } from "./MessageManagement";
@@ -1042,6 +1043,7 @@ function Composer({
10421043
size="toolbar"
10431044
shape="round"
10441045
type="submit"
1046+
style={messageButtonStyle}
10451047
aria-label={editing.target ? "Save changes" : "Send message"}
10461048
title={editing.target ? "Save changes" : "Send message"}
10471049
disabled={

‎src/features/messages/MessageRow.test.tsx‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,3 +1322,73 @@ it("never mounts an audio player for a native lookalike", () => {
13221322
expect(html).not.toContain("<audio");
13231323
expect(html).toContain("File unavailable");
13241324
});
1325+
1326+
it("renders built-in own bubbles and keeps only the last grouped avatar", () => {
1327+
const props = {
1328+
row: { ...row, authorId: "ab".repeat(32) },
1329+
viewer: "ab".repeat(32),
1330+
profile: { name: "author" },
1331+
media: () => undefined,
1332+
onOpenLink: () => true,
1333+
canOpenLink: () => true,
1334+
day: false,
1335+
retry: undefined,
1336+
};
1337+
try {
1338+
const { container, rerender } = renderDom(
1339+
<MessageRow {...props} stackNext />,
1340+
);
1341+
expect(container.querySelector("[data-own]")).toHaveTextContent("Root");
1342+
expect(
1343+
screen.queryByRole("button", { name: "View author profile" }),
1344+
).toBeNull();
1345+
rerender(<MessageRow {...props} stackPrevious />);
1346+
expect(
1347+
screen.getByRole("button", { name: "View author profile" }),
1348+
).toBeInTheDocument();
1349+
rerender(<MessageRow {...props} viewer="someone-else" />);
1350+
expect(container.querySelector("[data-own]")).toBeNull();
1351+
} finally {
1352+
cleanup();
1353+
}
1354+
});
1355+
1356+
it.each(["image", "video", "file", "audio"] as const)(
1357+
"places %s attachments outside the text bubble and omits empty bubbles",
1358+
(kind) => {
1359+
const props = {
1360+
row: {
1361+
...row,
1362+
content: "",
1363+
attachments: [{ kind, url: "https://example.com/photo.png" }],
1364+
},
1365+
profile: undefined,
1366+
media: () => undefined,
1367+
onOpenLink: () => true,
1368+
day: false,
1369+
retry: undefined,
1370+
};
1371+
try {
1372+
const { container, rerender } = renderDom(<MessageRow {...props} />);
1373+
expect(container.querySelector("[data-own]")).toBeNull();
1374+
expect(container.querySelector("[class*=messageBubble]")).toBeNull();
1375+
rerender(
1376+
<MessageRow
1377+
{...props}
1378+
row={{ ...props.row, content: "Photo caption" }}
1379+
/>,
1380+
);
1381+
const bubble = container.querySelector("[class*=messageBubble]");
1382+
const attachments = container.querySelector(
1383+
"[class*=messageAttachments]",
1384+
);
1385+
expect(bubble).toHaveTextContent("Photo caption");
1386+
expect(attachments).not.toBeNull();
1387+
expect(bubble?.contains(attachments)).toBe(false);
1388+
expect(bubble?.nextElementSibling).toBe(attachments);
1389+
expect(screen.getByText("Photo caption")).toBeInTheDocument();
1390+
} finally {
1391+
cleanup();
1392+
}
1393+
},
1394+
);

0 commit comments

Comments
 (0)