@@ -1,12 +1,23 @@
1-import { Component, useState, type ReactNode } from "react";
1+import { Component, createContext, useContext, useState, type ReactNode } from "react";
22 import ReactMarkdown from "react-markdown";
33 import remarkBreaks from "remark-breaks";
44 import remarkGfm from "remark-gfm";
5+import { ChevronDown, ChevronRight } from "lucide-react";
6+
7+const Collapsed = createContext(false);
58
69 // Images render inline; clicking one opens it in a full-window focus dialog.
10+// When the message's header is collapsed, images shrink to an alt-text chip.
711 function Image({ src, alt }: { src?: string; alt?: string }) {
812 const [open, setOpen] = useState(false);
13+ const collapsed = useContext(Collapsed);
914 if (!src) return alt ? <span>{alt}</span> : null;
15+ if (collapsed)
16+ return (
17+ <span className="my-1 inline-block rounded border border-sepia/15 bg-sepia/5 px-2 py-0.5 text-xs text-sepia/60">
18+ {alt || "image"}
19+ </span>
20+ );
1021 return (
1122 <>
1223 <img
@@ -54,13 +65,36 @@ class Fallback extends Component<{ text: string; children: ReactNode }, { failed
5465
5566 // Markdown renders a message body as GFM. Single newlines become hard breaks so
5667 // multiline input shows as typed. If rendering ever throws, the raw text is
57-// shown instead.
58-export default function Markdown({ text }: { text: string }) {
68+// shown instead. Messages containing images get a header to collapse them; the
69+// header lines up with the username column.
70+export default function Markdown({
71+ text,
72+ collapsed,
73+ onToggle,
74+}: {
75+ text: string;
76+ collapsed: boolean;
77+ onToggle: () => void;
78+}) {
79+ const count = (text.match(/!\[[^\]]*\]\([^)]+\)/g) ?? []).length;
5980 return (
6081 <Fallback text={text}>
61- <ReactMarkdown remarkPlugins={[remarkGfm, remarkBreaks]} components={components}>
62- {text}
63- </ReactMarkdown>
82+ {count > 0 && (
83+ <button
84+ type="button"
85+ onClick={onToggle}
86+ title={collapsed ? "show images" : "hide images"}
87+ className="flex w-full items-center gap-1 text-xs leading-6 text-sepia/50 hover:text-sepia/80"
88+ >
89+ {collapsed ? <ChevronRight className="size-3" /> : <ChevronDown className="size-3" />}
90+ {count} image{count > 1 ? "s" : ""}
91+ </button>
92+ )}
93+ <Collapsed.Provider value={collapsed}>
94+ <ReactMarkdown remarkPlugins={[remarkGfm, remarkBreaks]} components={components}>
95+ {text}
96+ </ReactMarkdown>
97+ </Collapsed.Provider>
6498 </Fallback>
6599 );
66100 }