diff --git a/app/src/components/channels/composer/composer.tsx b/app/src/components/channels/composer/composer.tsx index d3f2d57315..dfcaaf6abb 100644 --- a/app/src/components/channels/composer/composer.tsx +++ b/app/src/components/channels/composer/composer.tsx @@ -160,14 +160,9 @@ function stagedMimeType(attachment: Attachment): string { const MAX_HEIGHT_PX = 220; /** - * Two lines: the compact composer's message box opens two lines tall and grows from there. 22.5px - * lines at 15px; 24px lines at the 16px a touch screen gets (see `inputClassName`). - */ -const COMPACT_MIN_HEIGHT_PX = 45; -const COMPACT_TOUCH_MIN_HEIGHT_PX = 48; -/** - * One 24px line: a one-line box opens at this height. Given to PromptArea itself, whose own - * minimum (80px) is an inline style no class can beat. + * One 24px line: a one-line box opens at this height, the compact composer's included, and grows + * as the words wrap. Given to PromptArea itself, whose own minimum (80px) is an inline style no + * class can beat. */ const ONE_LINE_HEIGHT_PX = 24; const COMPACT_MAX_HEIGHT_PX = 160; @@ -350,7 +345,7 @@ export type ComposerProps = { spinsWhileSending?: boolean; /** * True draws the words and the controls in one row, so the empty box is one line tall and grows - * as the words wrap (Routines). Only the full-size box has it; a compact box keeps its two rows. + * as the words wrap (Routines). A compact box is always one row. */ oneLine?: boolean; }; @@ -2032,10 +2027,10 @@ export function Composer({ * internally at COMPACT_MAX_HEIGHT_PX: padding inside that box would scroll away with * the text, so the first visible line would touch the top edge on a long message. * - * A column: the attachment strip across the top, the message box under it, and the - * controls row at the bottom. + * A column: the attachment strip across the top, then one row of the controls and the + * words between them. */ - "flex flex-col px-3 py-3", + "flex flex-col p-2", MESSAGE_BOX_FRAME, className, )} @@ -2049,54 +2044,55 @@ export function Composer({ onRemove={discardAttachment} /> {/* - * TWO ROWS: the message box across the full width, then the controls under it. Attach - * and the model on the left, the microphone and send on the right, so the controls - * keep their place however long the message grows. + * ONE ROW: Attach on the left, the words in the middle, the model, the microphone and + * Send on the right. Empty, the box is one line tall, as tall as its buttons. The words + * grow upward as they wrap, and the controls stay on the bottom line, where they were. */} -
- -
-
-
- {attachmentsEnabled ? ( - - ) : null} - {/* No attachments and nothing else behind a plus, so no plus: a disabled one that - explained nothing read as broken. */} - {modelPicker} +
+ {attachmentsEnabled ? ( + + ) : null} + {/* No attachments and nothing else behind a plus, so no plus: a disabled one that + explained nothing read as broken. */} + {/* The 4px above and below a 24px line make it as tall as the 32px buttons beside it. */} +
+
+ {modelPicker} {dictates ? ( - ) : ( + ) : showValue ? ( - )} - {showValue ? ( - - {shown} - ) : null} + {/* In the message box, the model by its name, cut short when long: a chip icon + alone didn't say which model the next message goes to. The thinking setting is + in the name a screen reader hears and in the tooltip. */} + + {showValue ? shown : (selected?.label ?? "Model")} + } diff --git a/app/src/lib/auth/greeting.ts b/app/src/lib/auth/greeting.ts index e0ae2d2e52..58976555b1 100644 --- a/app/src/lib/auth/greeting.ts +++ b/app/src/lib/auth/greeting.ts @@ -1,12 +1,32 @@ import type { AuthenticatedUser } from "./queries"; -/** Keep the welcome out of message history, and never guess a first name. */ +/** + * The first word of the name the person saved: "Sam Julien" is greeted as Sam. Undefined when there + * is no name to go by (none saved, one still to be asked for, or the email standing in for it): + * a first name is never guessed from an email. + */ +export function firstName( + user: AuthenticatedUser | null | undefined, +): string | undefined { + const name = user?.name?.trim(); + if (!name || user?.needsName || name === user?.email) return undefined; + return name.split(/\s+/)[0]; +} + +/** What Home says when nobody's name is known. */ +const NO_NAME = "What would you like to work on?"; + +/** + * Home's heading: the person by their first name, asked what to work on the first time, welcomed + * back after that. Kept out of message history. + */ export function firstConversationGreeting( user: AuthenticatedUser | null | undefined, noConversations: boolean, ): string { - const name = user?.name?.trim(); - if (!noConversations || !name || user?.needsName || name === user?.email) - return "Start a conversation"; - return `Hi ${name}, what would you like to work on?`; + const name = firstName(user); + if (!name) return NO_NAME; + return noConversations + ? `Hi ${name}, what would you like to work on?` + : `Welcome back, ${name}`; } diff --git a/app/src/routes/_authed/_app/index.tsx b/app/src/routes/_authed/_app/index.tsx index b436993609..3612dd72e6 100644 --- a/app/src/routes/_authed/_app/index.tsx +++ b/app/src/routes/_authed/_app/index.tsx @@ -101,7 +101,8 @@ function Greeting() { // not yet shown. if (greeting === undefined && (!channels.isPending || waited)) setGreeting(choose()); - const heading = "text-2xl font-semibold tracking-tight text-center"; + // The title step, at a lighter weight than a page title: a greeting, not a heading to scan. + const heading = "text-2xl font-medium tracking-tight text-center"; if (!waits) return

{greeting}

; const could = [ ...new Set([ diff --git a/app/tests/composer-one-row.test.tsx b/app/tests/composer-one-row.test.tsx new file mode 100644 index 0000000000..983596f570 --- /dev/null +++ b/app/tests/composer-one-row.test.tsx @@ -0,0 +1,62 @@ +import { afterAll, afterEach, beforeAll, expect, test } from "bun:test"; +import { GlobalRegistrator } from "@happy-dom/global-registrator"; +import { cleanup, render } from "@testing-library/react"; +import { Composer } from "@/components/channels/composer/composer"; +import { settleReactWork } from "./settle-react-work"; + +/** + * The message box in a conversation (the compact composer) is one row: Attach, the words, then the + * model, the microphone and Send. Empty, it is one line tall. It was two rows, the words over the + * controls, about 114px tall before anything was typed. + * + * The harness is this repository's: see composer-attachments-ui.test.tsx. + */ +const originalFetch = global.fetch; +beforeAll(() => { + GlobalRegistrator.register({ url: "http://localhost/" }); + // Nothing here reads the server: whatever the box asks for is not found. + global.fetch = (async () => + new Response("{}", { status: 404 })) as unknown as typeof fetch; +}); +afterEach(cleanup); +afterAll(async () => { + await settleReactWork(); + global.fetch = originalFetch; + GlobalRegistrator.unregister(); +}); + +test("a conversation's box is one row: Attach, the words and Send side by side", () => { + const view = render( + Model} + onSubmit={() => {}} + />, + ); + const input = view.container.querySelector("[data-slot=composer-input]"); + const row = input?.parentElement; + expect(row?.className).toContain("flex"); + // Every control keeps its name, in the same row as the words. + const attach = view.getByRole("button", { name: "Attach a file" }); + const send = view.getByRole("button", { name: "Send message" }); + const model = view.getByRole("button", { name: "Model" }); + for (const control of [attach, send, model]) + expect(row?.contains(control)).toBe(true); + expect(view.getByRole("textbox", { name: "Message" })).toBeTruthy(); + // Attach first, the words, then the model before Send. + const order = [attach, input, model, send].map((element) => + [...(row?.querySelectorAll("*") ?? [])].indexOf(element as Element), + ); + expect(order).toEqual([...order].sort((a, b) => a - b)); +}); + +test("empty, the words take one 24px line, not two", () => { + const view = render( + {}} />, + ); + const editor = view.container.querySelector( + "[data-slot=composer-input] [style*=min-height]", + ) as HTMLElement | null; + expect(editor?.style.minHeight).toBe("24px"); +}); diff --git a/app/tests/first-conversation-greeting.test.ts b/app/tests/first-conversation-greeting.test.ts index 0c5247deaf..ae6d75df79 100644 --- a/app/tests/first-conversation-greeting.test.ts +++ b/app/tests/first-conversation-greeting.test.ts @@ -1,5 +1,5 @@ import { expect, test } from "bun:test"; -import { firstConversationGreeting } from "../src/lib/auth/greeting"; +import { firstConversationGreeting, firstName } from "../src/lib/auth/greeting"; import type { AuthenticatedUser } from "../src/lib/auth/queries"; const user: AuthenticatedUser = { @@ -10,20 +10,29 @@ const user: AuthenticatedUser = { onboarding: null, needsName: false, }; -test("greets by the saved name only with a confirmed empty conversation list", () => { +test("greets by first name: asked what to work on the first time, welcomed back after", () => { expect(firstConversationGreeting(user, true)).toBe( - "Hi Sam Julien, what would you like to work on?", + "Hi Sam, what would you like to work on?", ); - expect(firstConversationGreeting(user, false)).toBe("Start a conversation"); + expect(firstConversationGreeting(user, false)).toBe("Welcome back, Sam"); }); -test("does not greet with a missing or placeholder name", () => { +test("a first name is the first word of the saved name", () => { + expect(firstName({ ...user, name: " Ana MarĂ­a Ruiz " })).toBe("Ana"); + expect(firstName({ ...user, name: "Cher" })).toBe("Cher"); +}); +test("with a missing or placeholder name, a neutral line", () => { for (const value of [ undefined, null, { ...user, name: "" }, + { ...user, name: " " }, { ...user, needsName: true }, { ...user, name: user.email }, ]) { - expect(firstConversationGreeting(value, true)).toBe("Start a conversation"); + for (const first of [true, false]) + expect(firstConversationGreeting(value, first)).toBe( + "What would you like to work on?", + ); + expect(firstName(value)).toBeUndefined(); } }); diff --git a/app/tests/home-holds-still.test.tsx b/app/tests/home-holds-still.test.tsx index ef278bc020..b5a83093ce 100644 --- a/app/tests/home-holds-still.test.tsx +++ b/app/tests/home-holds-still.test.tsx @@ -47,8 +47,7 @@ const ANSWER_AFTER_MS = 400; /** How long a test waits for the page to ask for both lists and have them answered. */ const ANSWERED_WITHIN_MS = 10_000; /** The person the fixture signs in, and what Home says to them before their first conversation. */ -const FIRST_CONVERSATION_GREETING = - "Hi Sam Rivera, what would you like to work on?"; +const FIRST_CONVERSATION_GREETING = "Hi Sam, what would you like to work on?"; const APP = join(import.meta.dir, ".."); const ORIGIN = "http://openbot.test"; @@ -542,7 +541,7 @@ describe.skipIf(!asked)("Home while it loads", () => { } for (const engine of engines) { - test(`a conversation list that fails leaves the plain greeting, drawn once, in ${engine}`, async () => { + test(`a conversation list that fails leaves the returning greeting, drawn once, in ${engine}`, async () => { const { page, frames } = await loaded( engine, "light", @@ -551,7 +550,7 @@ describe.skipIf(!asked)("Home while it loads", () => { { bots: false, conversations: false, conversationsFail: true }, ); try { - expect(greetingsOf(frames)).toEqual(["Start a conversation"]); + expect(greetingsOf(frames)).toEqual(["Welcome back, Sam"]); } finally { await page.close(); } diff --git a/app/tests/model-picker.test.tsx b/app/tests/model-picker.test.tsx index c746d525b4..3eb81ac778 100644 --- a/app/tests/model-picker.test.tsx +++ b/app/tests/model-picker.test.tsx @@ -192,7 +192,7 @@ function thinking(popup: HTMLElement) { return within(popup).queryByRole("group", { name: "Thinking" }); } -test("the trigger is a CPU icon, and names a model that takes no effort on its own", () => { +test("the trigger says the model by its name, and names a model that takes no effort on its own", () => { const { getByRole } = render( , ); const trigger = getByRole("combobox", { name: "Model: GPT-4o" }); - // No name and no maker's mark in the row: the CPU icon and a chevron, named for screen readers. - expect(trigger.textContent).toBe(""); + // The model's name and a chevron, cut short when long. No maker's mark and no chip icon. + expect(trigger.textContent).toBe("GPT-4o"); expect(trigger.querySelector("img")).toBeNull(); - expect(trigger.firstElementChild?.classList.contains("icon-cpu")).toBe(true); + expect(trigger.querySelector(".icon-cpu")).toBeNull(); + expect(trigger.querySelector("span")?.classList.contains("truncate")).toBe( + true, + ); }); /** The open popup of a picker drawn on its own. */