Put a user message's copy button beside its timestamp

The copy button sat on its own row above the group's time, costing a
line of vertical space for nothing. It now shares that row, left of the
timestamp, the way a bot message's actions already do. A file-only
message leaves no gap: only messages with text get a button, picked by
copyableMessages.
This commit is contained in:
2026-10-22 12:33:48 +01:00
parent 08d02e6033
commit 133e6b87c9
5 changed files with 72 additions and 11 deletions
@@ -0,0 +1,27 @@
import { describe, expect, test } from "bun:test";
import type { BotMessageWithAttachments } from "@/src/types";
import copyableMessages from "./copyable-messages";
function message(text?: string): BotMessageWithAttachments {
return { id: 1, author: "user", text } as BotMessageWithAttachments;
}
describe("copyableMessages", () => {
test("keeps the messages that have text", () => {
const kept = copyableMessages({
messages: [message("hello"), message(undefined), message("hi")],
});
expect(kept.map((one) => one.text)).toEqual(["hello", "hi"]);
});
test("drops text that is only whitespace", () => {
expect(copyableMessages({ messages: [message(" ")] })).toEqual([]);
});
test("a group with no text has nothing to copy", () => {
expect(copyableMessages({ messages: [message(), message()] })).toEqual(
[],
);
});
});
@@ -0,0 +1,14 @@
import type { BotMessageWithAttachments } from "@/src/types";
/**
* The messages of a group that can be copied: a file-only message has no
* text, and its copy button renders nothing, so it would only leave a
* gap in the row.
*/
export default function copyableMessages({
messages,
}: {
messages: BotMessageWithAttachments[];
}): BotMessageWithAttachments[] {
return messages.filter((message) => Boolean(message.text?.trim()));
}