Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

feat(community): share dialog renders multiple messages (render half)

Shelly56fae46b8e39
diff --git a/src/web/src/components/community/message-share-dialog.tsx b/src/web/src/components/community/message-share-dialog.tsx
index 27b801f04..9ab07342c 100644
--- a/src/web/src/components/community/message-share-dialog.tsx
+++ b/src/web/src/components/community/message-share-dialog.tsx
@@ -1,6 +1,6 @@
"use client"
-import { useCallback, useRef, useState } from "react"
+import { useCallback, useMemo, useRef, useState } from "react"
import Image from "next/image"
import { toBlob } from "html-to-image"
import { toast } from "sonner"
@@ -13,49 +13,60 @@ import { tid } from "@/lib/community/testids"
import { applyHighlightToRange, clearHighlights, hasHighlights } from "@/lib/community/highlight-range"
import type { RenderMsg } from "./_types"
-// Share a single message as an image. Renders a self-contained "share card"
-// that mirrors the in-app message blob (avatar / name / content — NO timestamp,
-// per spec) plus an Alook brand footer, then rasterises THAT SAME node to PNG
-// (WYSIWYG) via html-to-image — fully client-side, no backend. The captured
-// node has a fixed width and its own solid background so the export is stable
-// regardless of the surrounding theme surface.
+// Share one OR several messages as an image. Renders a self-contained "share
+// card" that mirrors the in-app message blob(s) (avatar / name / content — NO
+// timestamp, per spec) plus an Alook brand footer, then rasterises THAT SAME
+// node to PNG (WYSIWYG) via html-to-image — fully client-side, no backend. The
+// captured node has a fixed width and its own solid background so the export is
+// stable regardless of the surrounding theme surface.
+//
+// Multi-message (Gus uiux #128, Alli #133): pass an array of the selected
+// messages (in order). Consecutive same-author messages collapse the avatar/
+// name (each carries `grouped`, computed by the message list — reused verbatim),
+// exactly like the chat stream. Everything else — toBlob capture, Download/Copy,
+// drag-highlight — is shared; highlight is per-message (each body its own ref).
export function MessageShareDialog({ m, open, onClose }: {
- m: RenderMsg
+ m: RenderMsg | RenderMsg[]
open: boolean
onClose: () => void
}) {
+ const messages = useMemo(() => (Array.isArray(m) ? m : [m]), [m])
const cardRef = useRef<HTMLDivElement>(null)
- // The message-body wrapper — highlight operations are scoped to it so a drag
- // can never wrap the avatar/name/footer, only the message text.
- const bodyRef = useRef<HTMLDivElement>(null)
+ // One body wrapper per message — highlight operations are scoped to the body
+ // the drag happened in, so a drag never wraps the avatar/name/footer OR bleeds
+ // across messages (Alli #133: highlight is per-message). Keyed by message id.
+ const bodyRefs = useRef(new Map<string, HTMLDivElement | null>())
const [busy, setBusy] = useState<"copy" | "download" | null>(null)
const [copied, setCopied] = useState(false)
// Drives the Reset button's presence. Gus (uiux #95): the button is HIDDEN
// (not disabled) when there's nothing to reset — "less is more". Mirrors the
- // DOM (`mark[data-hl]` count) after each apply/reset.
+ // DOM (any `mark[data-hl]` across the bodies) after each apply/reset.
const [highlighted, setHighlighted] = useState(false)
- // On mouseup inside the body, wrap the current selection in a highlight.
+ const anyHighlight = useCallback(
+ () => [...bodyRefs.current.values()].some((b) => b && hasHighlights(b)),
+ [],
+ )
+
+ // On mouseup inside a message body, wrap the current selection in a highlight.
// Text-node-level wrapping (see highlight-range.ts) — never surroundContents,
- // so it survives spanning multiple markdown elements. Drags stack; the
- // browser selection is collapsed afterward so it doesn't also land in the PNG.
- const onBodyMouseUp = useCallback(() => {
- const body = bodyRef.current
+ // so it survives spanning multiple markdown elements. Drags stack; the browser
+ // selection is collapsed afterward so it doesn't also land in the PNG. Scoped
+ // to the one body the drag is in — a selection straying outside it is ignored.
+ const onBodyMouseUp = useCallback((id: string) => {
+ const body = bodyRefs.current.get(id)
if (!body) return
const sel = window.getSelection?.()
if (!sel || sel.isCollapsed || sel.rangeCount === 0) return
const range = sel.getRangeAt(0)
- // Ignore selections that stray outside the message body.
if (!body.contains(range.commonAncestorContainer)) return
const added = applyHighlightToRange(body, range)
sel.removeAllRanges()
- if (added > 0) setHighlighted(hasHighlights(body))
- }, [])
+ if (added > 0) setHighlighted(anyHighlight())
+ }, [anyHighlight])
const resetHighlights = useCallback(() => {
- const body = bodyRef.current
- if (!body) return
- clearHighlights(body)
+ for (const body of bodyRefs.current.values()) if (body) clearHighlights(body)
setHighlighted(false)
}, [])
@@ -115,7 +126,7 @@ export function MessageShareDialog({ m, open, onClose }: {
const url = URL.createObjectURL(blob)
const a = document.createElement("a")
a.href = url
- a.download = `alook-message-${m.authorName ?? "share"}.png`
+ a.download = `alook-message-${messages[0]?.authorName ?? "share"}.png`
a.click()
URL.revokeObjectURL(url)
} catch {
@@ -134,59 +145,68 @@ export function MessageShareDialog({ m, open, onClose }: {
max-width so the width below can actually apply. */}
<DialogContent className="w-180 max-w-[calc(100vw-2rem)] sm:max-w-[calc(100vw-2rem)] gap-0 p-0">
<DialogHeader className="px-5 pt-5 pb-3">
- <DialogTitle>Share message</DialogTitle>
+ <DialogTitle>{messages.length > 1 ? `Share ${messages.length} messages` : "Share message"}</DialogTitle>
</DialogHeader>
{/* Preview area — the padding frames the card; the card itself is what
- gets captured. */}
- <div className="bg-muted/40 px-6 py-6">
+ gets captured. Scrolls when the card is tall (many messages, Alli
+ #137): only the PREVIEW is height-bounded + scrollable — `toBlob`
+ captures `cardRef` (the full card), so the export is never cut by
+ this scroll bound. */}
+ <div className="max-h-[60vh] overflow-y-auto bg-muted/40 px-6 py-6">
{/* The card takes the full preview width — a generous, poster-like
default so the share image reads as a proper card at any content
- length (a short message just has more breathing room, rather than
- collapsing to a narrow chip). */}
+ length. The CARD itself is NOT height-capped: the exported PNG is
+ the full card (Alli #137). Runaway height is bounded PER MESSAGE
+ (each body clamps at 32 lines, below), and the PREVIEW container
+ (the wrapper above) scrolls — so a many-message selection is fully
+ exported but doesn't blow the popup out. */}
<div
ref={cardRef}
- className="overflow-hidden rounded-xl bg-card p-5 shadow-(--e1)"
+ className="rounded-xl bg-card p-5 shadow-(--e1)"
>
- <div className="flex gap-3">
- <Avatar label={m.authorAvatar ?? "?"} seed={m.authorId} size={40} />
- <div className="min-w-0 flex-1">
- <div
- className="mb-0.5 text-[15px] font-semibold"
- style={{ color: m.color ?? "var(--foreground)" }}
- >
- {m.authorName}
+ {messages.map((msg) => (
+ // A grouped message (consecutive same author) collapses the avatar
+ // column into a spacer + drops the name, matching the chat stream.
+ <div key={msg.id} className={`flex gap-3 ${msg.grouped ? "mt-0.5" : "mt-3 first:mt-0"}`}>
+ {msg.grouped
+ ? <div className="w-10 shrink-0" aria-hidden />
+ : <Avatar label={msg.authorAvatar ?? "?"} seed={msg.authorId} size={40} />}
+ <div className="min-w-0 flex-1">
+ {!msg.grouped && (
+ <div
+ className="mb-0.5 text-[15px] font-semibold"
+ style={{ color: msg.color ?? "var(--foreground)" }}
+ >
+ {msg.authorName}
+ </div>
+ )}
+ {/* Each body: clamp at 32 lines (Alli #137 — one number for
+ single & multi share). Two layers, same as the original
+ single-message card: `max-h` hard-bounds any structure
+ (multi-paragraph markdown escapes line-clamp alone), and
+ `line-clamp-[32]` gives a single-block message a tidy
+ ellipsis. Each body also drives its own drag-highlight
+ (per-message scope, Alli #133) via its ref in `bodyRefs`;
+ the `mark[data-hl]` styles are the soft-yellow marker
+ (rasterises cleanly under html-to-image — plain bg +
+ box-decoration-break, no mask). max-h ≈ 32 lines at the
+ body's 15px/leading-snug. */}
+ {msg.content && (
+ <div
+ ref={(el) => { bodyRefs.current.set(msg.id, el) }}
+ onMouseUp={() => onBodyMouseUp(msg.id)}
+ className="max-h-[41rem] overflow-hidden line-clamp-[32] [&_mark[data-hl]]:bg-[rgba(255,208,92,0.5)] [&_mark[data-hl]]:[border-radius:2px] [&_mark[data-hl]]:[padding:0_1px] [&_mark[data-hl]]:[box-decoration-break:clone] [&_mark[data-hl]]:[-webkit-box-decoration-break:clone] [&_mark[data-hl]]:text-inherit"
+ >
+ <MessageBody text={msg.content} />
+ </div>
+ )}
</div>
- {/* Cap the message body so a very long message can't blow the
- card (and the popup) out vertically (Alli's spec, uiux #38;
- 24 lines per Gus #37). Two layers:
- • Primary bound = `max-h` + `overflow-hidden`. line-clamp
- alone only clamps WITHIN one block, so multi-paragraph
- markdown (the actual bug case) would escape it — the
- max-height hard-bounds any structure (paragraphs, code,
- lists) and rasterises cleanly through html-to-image.
- • `line-clamp-[24]` is the enhancement: a single-paragraph
- message gets a tidy trailing ellipsis; multi-block content
- is still caught by max-h (clean cut, no ellipsis — bounded
- is the bar). No gradient fade — masks rasterise
- unreliably in html-to-image.
- Clamped inside cardRef so the PNG matches the preview; the
- avatar/name/footer sit outside this box and stay complete.
- max-h ≈ 24 lines at the body's 15px/leading-snug. */}
- {m.content && (
- <div
- ref={bodyRef}
- onMouseUp={onBodyMouseUp}
- className="max-h-[31rem] overflow-hidden line-clamp-[24] [&_mark[data-hl]]:bg-[rgba(255,208,92,0.5)] [&_mark[data-hl]]:[border-radius:2px] [&_mark[data-hl]]:[padding:0_1px] [&_mark[data-hl]]:[box-decoration-break:clone] [&_mark[data-hl]]:[-webkit-box-decoration-break:clone] [&_mark[data-hl]]:text-inherit"
- >
- <MessageBody text={m.content} />
- </div>
- )}
</div>
- </div>
+ ))}
{/* Brand footer — Alook logo + brand font, mirrors the marketing
- footer treatment. */}
+ footer treatment. One footer for the whole card, single or multi. */}
<div className="mt-4 flex items-center gap-1.5 border-t border-border/50 pt-3">
<Image src="/alook.svg" alt="" width={16} height={16} />
<span