Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix(community): decouple share affordance from select-mode plumbing

Shelly3dc516ec43da
diff --git a/src/web/src/components/community/message-context-sheet.tsx b/src/web/src/components/community/message-context-sheet.tsx
index 14990042f..fc8970fce 100644
--- a/src/web/src/components/community/message-context-sheet.tsx
+++ b/src/web/src/components/community/message-context-sheet.tsx
@@ -1,6 +1,6 @@
"use client"
-import { useCallback, useEffect, useMemo, useRef } from "react"
+import { useCallback, useEffect, useMemo, useRef, useState } from "react"
import { useRouter, useParams } from "next/navigation"
import { toast } from "sonner"
import { useQuery, useQueryClient } from "@tanstack/react-query"
@@ -8,6 +8,7 @@ import { deriveThreadName } from "@alook/shared"
import { Sheet, SheetContent, SheetHeader, SheetTitle } from "@/components/ui/sheet"
import { useSheetResize, SheetResizeHandle } from "@/components/ui/sheet-resize-handle"
import { MessageRow } from "./message-row"
+import { MessageShareDialog } from "./message-share-dialog"
import { ChannelIcon } from "./channel-icon"
import { Skeleton } from "@/components/ui/skeleton"
import { apiFetch, toastApiError } from "@/lib/api/client"
@@ -464,8 +465,20 @@ function ContextRows({
onDownloadFile: (url: string) => void
onOpenContextSheet?: (seq: number) => void
}) {
+ // Single-message share from the peek sheet. The sheet has no select-mode
+ // context (it's a read-only preview), so Share opens the dialog directly on
+ // the clicked row — via `onShareSingle`, independent of the list's select-mode
+ // plumbing (Cecilia #511: share capability must not depend on it).
+ const [shareTarget, setShareTarget] = useState<RenderMsg | null>(null)
+ const onShareSingleId = useCallback(
+ (id: string) => setShareTarget(rows.find((r) => r.id === id) ?? null),
+ [rows],
+ )
return (
<div className="flex flex-col">
+ {shareTarget && (
+ <MessageShareDialog m={shareTarget} open onClose={() => setShareTarget(null)} />
+ )}
{rows.map((m, i) => {
const isTarget = m.id === anchorId
const prev = i > 0 ? rows[i - 1] : null
@@ -493,6 +506,7 @@ function ContextRows({
onPreviewImage={onPreviewImage}
onDownloadFile={onDownloadFile}
resolveUserName={resolveUserName}
+ onShareSingleId={onShareSingleId}
/>
</div>
</div>
diff --git a/src/web/src/components/community/message-row.tsx b/src/web/src/components/community/message-row.tsx
index 5e7807b1f..53cc879e3 100644
--- a/src/web/src/components/community/message-row.tsx
+++ b/src/web/src/components/community/message-row.tsx
@@ -39,6 +39,10 @@ export interface MessageRowProps {
selected?: boolean
onToggleSelectId?: (id: string) => void
onEnterSelectId?: (id: string) => void
+ // Direct single-message share (surfaces with no select-mode, e.g. the context
+ // sheet). Independent of `onEnterSelectId` so share never depends on select
+ // plumbing (Cecilia #511).
+ onShareSingleId?: (id: string) => void
}
function MessageRowImpl(props: MessageRowProps) {
@@ -47,7 +51,7 @@ function MessageRowImpl(props: MessageRowProps) {
onToggleReactionId, onReactId, onReplyId, onPinId, onCreateThreadId,
onCopyId, onRetryId, onJumpToId, onPreviewImage, onDownloadFile,
resolveUserName, onImageLoad,
- selectMode, selected, onToggleSelectId, onEnterSelectId,
+ selectMode, selected, onToggleSelectId, onEnterSelectId, onShareSingleId,
} = props
const id = m.id
const replyToId = m.replyTo?.id
@@ -68,6 +72,7 @@ function MessageRowImpl(props: MessageRowProps) {
const onJumpReply = useCallback(() => { if (replyToId) onJumpToId?.(replyToId) }, [onJumpToId, replyToId])
const onToggleSelect = useCallback(() => onToggleSelectId?.(id), [onToggleSelectId, id])
const onEnterSelect = useCallback(() => onEnterSelectId?.(id), [onEnterSelectId, id])
+ const onShareSingle = useCallback(() => onShareSingleId?.(id), [onShareSingleId, id])
// Map an absent id-based source to `undefined` so `Message` sees the same
// "feature off" signal it used to (its interactive/menu logic keys off which
@@ -97,6 +102,7 @@ function MessageRowImpl(props: MessageRowProps) {
selected={selected}
onToggleSelect={onToggleSelectId ? onToggleSelect : undefined}
onEnterSelect={onEnterSelectId ? onEnterSelect : undefined}
+ onShareSingle={onShareSingleId ? onShareSingle : undefined}
/>
)
}
diff --git a/src/web/src/components/community/message.tsx b/src/web/src/components/community/message.tsx
index e31e6bce3..a200ea759 100644
--- a/src/web/src/components/community/message.tsx
+++ b/src/web/src/components/community/message.tsx
@@ -49,7 +49,7 @@ function MessageImpl({
m, compact, pinned, onOpenThread, onOpenProfile, onJumpReply,
onToggleReaction, onReact, onReply, onPin, onCreateThread, onCopy, onRetry,
onPreviewImage, onDownloadFile, highlighted, resolveUserName, onImageLoad,
- selectMode, selected, onToggleSelect, onEnterSelect,
+ selectMode, selected, onToggleSelect, onEnterSelect, onShareSingle,
}: {
m: RenderMsg
compact?: boolean
@@ -69,16 +69,20 @@ function MessageImpl({
highlighted?: boolean
resolveUserName?: (userId: string) => string
onImageLoad?: () => void
- // Multi-select for "share as image" (Gus uiux #128/#142). `selectMode` is on
- // for the whole list while selecting; `selected` is this row's state;
- // `onToggleSelect` toggles it. `onEnterSelect` is called by the Share button —
- // clicking Share enters select mode with this row pre-selected (unified entry:
- // single-share is just select-mode with one message). All undefined when the
- // surface doesn't support multi-share (keeps the affordance off).
+ // "Share as image" (Gus uiux #128/#142). Two independent ways the Share
+ // affordance can act — a surface wires whichever it supports:
+ // · `onEnterSelect` — the main list: clicking Share enters multi-select mode
+ // with this row pre-selected (unified entry; single-share = one pick).
+ // · `onShareSingle` — a surface with no select-mode context (the message
+ // context-sheet peek): clicking Share opens the dialog on just this row.
+ // Share shows if EITHER is present — share capability must NOT depend on the
+ // select-mode plumbing (Cecilia #511: coupling them silently dropped share
+ // from every caller that didn't wire select-mode).
selectMode?: boolean
selected?: boolean
onToggleSelect?: () => void
onEnterSelect?: () => void
+ onShareSingle?: () => void
}) {
// keep the hover toolbar pinned open while its ⋯ dropdown is open
const [toolbarOpen, setToolbarOpen] = useState(false)
@@ -110,10 +114,9 @@ function MessageImpl({
onReply, onPin, pinned,
onCreateThread: m.thread ? undefined : onCreateThread,
onCopy,
- // Share enters multi-select mode with this row pre-selected (Gus #142) —
- // the actual share dialog opens from the select bar. Single-message share
- // is just this with no further picks.
- onShare: canShare ? onEnterSelect : undefined,
+ // Share: enter multi-select (main list) if wired, else direct single-share
+ // (context-sheet). Undefined only when the surface wired NEITHER.
+ onShare: canShare ? (onEnterSelect ?? onShareSingle) : undefined,
}
const showMenu = hasMessageMenu(menuHandlers)
const interactive = !compact && showMenu
@@ -172,8 +175,8 @@ function MessageImpl({
<Reply className="size-4" />
</button>
)}
- {canShare && onEnterSelect && (
- <button data-testid={tid.messageShare(m.id)} onClick={onEnterSelect} className="grid size-7 place-items-center rounded text-muted-foreground hover:bg-accent hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none" aria-label="Share as image">
+ {canShare && (onEnterSelect || onShareSingle) && (
+ <button data-testid={tid.messageShare(m.id)} onClick={onEnterSelect ?? onShareSingle} className="grid size-7 place-items-center rounded text-muted-foreground hover:bg-accent hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none" aria-label="Share as image">
<Share className="size-4" />
</button>
)}
@@ -482,7 +485,8 @@ function messagePropsEqual(prev: MessageProps, next: MessageProps): boolean {
prev.selectMode === next.selectMode &&
prev.selected === next.selected &&
prev.onToggleSelect === next.onToggleSelect &&
- prev.onEnterSelect === next.onEnterSelect
+ prev.onEnterSelect === next.onEnterSelect &&
+ prev.onShareSingle === next.onShareSingle
)
}