Files
chatkit/dist/react/ChatHistory.js
T
CatoandClaude Opus 5.5 652e04a149 feat(app): ChatApp — the whole chat app every product shares (#43)
* docs: the fleet's chats side by side

Every product renders chatkit's Composer, most render ChatScreen and
ChatThread, but the app around them — chat list, New chat, Temporary chat,
titles, rename/delete, restore on reload, the queue, attachment defaults —
is written again in each product. One table, read from each repo's main
on 2026-10-27, with the file each cell comes from.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018WZnBnaLP6RhwFkLxRTKgE

* feat(app): ChatApp, the whole chat app every product shares

The pieces were shared; the app was not. ChatApp composes ChatScreen,
Composer and ChatThread and owns what each product re-implemented:

- the header (Chats · title · New chat · More with Temporary chat, Share,
  Rename, Delete) as frosted pills, with headerStart/headerEnd slots;
- the chat list: a <dialog> drawer on a phone (Escape, focus trap and
  restore from the browser; opens on its close button, not the search
  box), a rail when wide; search, Today/Yesterday/Earlier, one row
  anatomy (title, date, one "…" → Rename · Delete as equal cells);
- New chat; Temporary chat that writes nothing and ends on leaving;
- titles from the first message (Heidi's rule) or makeTitle();
- the open chat restored on reload (or driven by conversationId);
- turns per conversation that keep running in the background, Stop that
  keeps what arrived, Retry on a failure, a queue behind a running answer;
- attachments on by default, staged above the text, shown in the turn.

Storage is an adapter: ConversationStore (list/get/create/append/rename/
remove) with localConversationStore (versioned, never throws, quota drops
the oldest) and httpConversationStore (Heidi's REST shape,
serverWritesTurns for routes that store turns themselves). The product
supplies the transport and its words.

Additive: ChatScreen, Composer and ChatThread behave as before;
ChatMessageData gains optional attachments and Composer an optional
stagedPosition. Unit tests cover grouping, titles, search, dates, restore
and both stores (with storage that throws and a quota); test/browser-app.mjs
drives demo/app.html at 390px and 1440px.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018WZnBnaLP6RhwFkLxRTKgE

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-27 10:16:21 +01:00

58 lines
6.6 KiB
JavaScript

"use client";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useState } from "react";
import { filterConversations, formatConversationDate, groupConversations, } from "../conversations.js";
import { IconMore, IconNewChat, IconSearch, IconX } from "./icons.js";
/**
* The chat list — the same in every product: New chat, a search box, the
* chats under Today / Yesterday / Earlier. Every row has ONE anatomy: the
* title, the date (or "Answering…"), and one "…" that opens the row's two
* actions, Rename and Delete, as two equal cells under it. A delete asks
* once, in the row.
*/
export function ChatHistory({ conversations, state, activeId, busyIds, onOpen, onNew, onRename, onRemove, onRetry, onClose, search = filterConversations, locale, labels, }) {
const [query, setQuery] = useState("");
const [armed, setArmed] = useState(null);
const [confirming, setConfirming] = useState(null);
const [editing, setEditing] = useState(null);
const now = Date.now();
const shown = search(conversations, query);
const groups = groupConversations(shown, now);
const close = () => {
setArmed(null);
setConfirming(null);
setEditing(null);
};
const submitRename = (e, id) => {
e.preventDefault();
const value = String(new FormData(e.currentTarget).get("title") ?? "").trim();
if (value)
onRename(id, value);
close();
};
return (_jsxs("nav", { className: "ck-history", "aria-label": labels.chats, children: [_jsxs("div", { className: "ck-history-head", children: [_jsx("span", { className: "ck-history-title", children: labels.chats }), onClose && (_jsx("button", { type: "button", className: "ck-icon-btn ck-history-close", onClick: onClose, "aria-label": labels.closeChats, title: labels.closeChats, "data-ck-initial-focus": "", children: _jsx(IconX, {}) }))] }), _jsxs("button", { type: "button", className: "ck-history-new", onClick: onNew, children: [_jsx(IconNewChat, {}), _jsx("span", { children: labels.newChat })] }), _jsxs("label", { className: "ck-history-search", children: [_jsx(IconSearch, {}), _jsx("input", { type: "search", value: query, onChange: (e) => setQuery(e.target.value), placeholder: labels.search, "aria-label": labels.search, enterKeyHint: "search" })] }), _jsx("div", { className: "ck-history-list", children: state === "loading" && conversations.length === 0 ? (_jsx("p", { className: "ck-history-empty", role: "status", children: labels.loadingChats })) : state === "error" ? (_jsxs("div", { className: "ck-history-empty", role: "status", children: [_jsx("p", { children: labels.listFailed }), _jsx("button", { type: "button", className: "ck-history-retry", onClick: onRetry, children: labels.tryAgain })] })) : conversations.length === 0 ? (_jsx("p", { className: "ck-history-empty", children: labels.noChats })) : groups.length === 0 ? (_jsx("p", { className: "ck-history-empty", children: labels.noMatch(query.trim()) })) : (groups.map((group) => (_jsxs("section", { className: "ck-history-group", "aria-label": labels[group.key], children: [_jsx("h3", { className: "ck-history-group-title", children: labels[group.key] }), _jsx("ul", { children: group.items.map((c) => {
const title = c.title.trim() || labels.untitled;
const busy = busyIds.has(c.id);
const active = c.id === activeId;
const isArmed = armed === c.id;
return (_jsxs("li", { className: active ? "ck-history-row ck-history-row-active" : "ck-history-row", children: [editing === c.id ? (_jsxs("form", { className: "ck-history-rename", onSubmit: (e) => submitRename(e, c.id), children: [_jsx("input", { name: "title", defaultValue: c.title, "aria-label": labels.renameField, autoFocus: true, onKeyDown: (e) => {
if (e.key === "Escape") {
e.preventDefault();
e.stopPropagation();
close();
}
} }), _jsxs("div", { className: "ck-history-pair", children: [_jsx("button", { type: "submit", children: labels.save }), _jsx("button", { type: "button", onClick: close, children: labels.cancel })] })] })) : (_jsxs("div", { className: "ck-history-line", children: [_jsxs("button", { type: "button", className: "ck-history-open", "aria-current": active ? "page" : undefined, onClick: () => {
close();
onOpen(c.id);
}, children: [_jsx("span", { className: "ck-history-name", children: title }), _jsx("span", { className: "ck-history-date", children: busy
? labels.answering
: formatConversationDate(c.updatedAt, now, locale) })] }), _jsx("button", { type: "button", className: "ck-history-more", "aria-expanded": isArmed, "aria-label": labels.chatActions(title), title: labels.chatActions(title), onClick: () => {
setConfirming(null);
setArmed(isArmed ? null : c.id);
}, children: _jsx(IconMore, {}) })] })), isArmed && editing !== c.id && confirming !== c.id && (_jsxs("div", { className: "ck-history-pair", children: [_jsx("button", { type: "button", onClick: () => setEditing(c.id), children: labels.rename }), _jsx("button", { type: "button", onClick: () => setConfirming(c.id), children: labels.delete })] })), confirming === c.id && (_jsxs("div", { className: "ck-history-confirm", role: "group", "aria-label": labels.deleteAsk(title), children: [_jsx("p", { children: labels.deleteAsk(title) }), _jsxs("div", { className: "ck-history-pair", children: [_jsx("button", { type: "button", className: "ck-history-danger", onClick: () => {
close();
onRemove(c.id);
}, children: labels.delete }), _jsx("button", { type: "button", onClick: close, children: labels.cancel })] })] }))] }, c.id));
}) })] }, group.key)))) })] }));
}
//# sourceMappingURL=ChatHistory.js.map