mirror of
https://github.com/multica-ai/multica.git
synced 2026-08-02 18:13:27 +02:00
* refactor(ui): converge ActorAvatar size to semantic tiers (MUL-4277) Replace the free-form numeric `size` on ActorAvatar with a constrained `AvatarSize` union (xs/sm/md/lg/xl/2xl) so avatar dimensions are chosen by role instead of ad-hoc pixels. This eliminates the magic-number drift where the same role rendered at different sizes across pages. - Add `@multica/ui/lib/avatar-size` (AvatarSize union + AVATAR_SIZE_PX map + default tier). - Base `ActorAvatar` (packages/ui) and business `ActorAvatar`/`AgentStatusDot` (packages/views) now take `AvatarSize`; internal font/icon math and the presence-dot threshold read px from the map. - Migrate all web/desktop call sites (packages/ui + packages/views) from numeric sizes to tiers using the role table (12,14->xs 16,18,20->sm 22,24,28->md 30,32,34->lg 40,44->xl 56,64->2xl). - Token-ise the derived consumers `AgentAvatarStack` and `IssueAgentActivityIndicator` (px looked up internally for overlap/+N math). Out of scope (per plan): ui/avatar.tsx primitive, account-tab/AvatarPicker, mobile, and component-name disambiguation. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Co-authored-by: multica-agent <github@multica.ai> * fix(ui): unify all avatars and the upload cropper to round (MUL-4277, MUL-4184) main's avatar-shape decision rendered non-human actors (agent, squad, system) and the workspace logo as rounded squares, and the upload cropper mirrored that with a square crop window. Per the updated decision (avatars_and_cropper_round_required), every avatar and the crop UI are now circular; the square path is removed rather than left as dead config. - Base ActorAvatar: always rounded-full (drop the isHuman/rounded-md split). - avatar-crop-dialog: remove the AvatarCropShape/square path; crop window is always cropShape="round". - avatar-upload-control: drop VARIANT_SHAPE; the control is always round and no longer threads a shape to the dialog (variant still drives the fallback). - Strip rounded-md/rounded-none square overrides from agent/squad/member ActorAvatar call sites; round the read-only agent/squad static wrappers. - WorkspaceAvatar: round the org logo so it matches the (now round) workspace upload/crop and the shared avatar shape. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Co-authored-by: multica-agent <github@multica.ai> * fix(ui): make round avatar shape a hard invariant (MUL-4277) Close the two remaining square squad-avatar paths flagged in review and prevent call sites from re-squaring the avatar: - base ActorAvatar: keep `rounded-full` as the last class in cn() so a call-site `className` can no longer override the circle. - SquadHeaderAvatar: drop `className="rounded"` (was overriding the base circle into a small rounded square). - SquadsPage no-avatar fallback: route through the shared ActorAvatarBase (`isSquad size="lg"`) instead of a hand-written rounded-md tile, so the fallback matches the image path — one shape source of truth. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Co-authored-by: multica-agent <github@multica.ai> * fix(views): round the agent/squad avatar loading skeletons (MUL-4277) The avatar placeholder skeletons on the agent/squad list, detail, and profile-card loading states were still rounded squares (rounded-md/lg) from the pre-round era, so the avatar visibly popped from square to circle on load — inconsistent with the round avatars and with the member/inbox/issue skeletons that already use rounded-full. Round all five: agents-page, agent-detail-page, squads-page, squad-detail-page, squad-profile-card. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Co-authored-by: multica-agent <github@multica.ai> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com> Co-authored-by: multica-agent <github@multica.ai>
236 lines
8.6 KiB
TypeScript
236 lines
8.6 KiB
TypeScript
"use client";
|
|
|
|
import { useRef, useState, useCallback, useEffect } from "react";
|
|
import { ArrowUp, Loader2 } from "lucide-react";
|
|
import { ContentEditor, type ContentEditorRef, useFileDropZone, FileDropOverlay } from "../../editor";
|
|
import { FileUploadButton } from "@multica/ui/components/common/file-upload-button";
|
|
import { Button } from "@multica/ui/components/ui/button";
|
|
import { ActorAvatar } from "../../common/actor-avatar";
|
|
import { useFileUpload } from "@multica/core/hooks/use-file-upload";
|
|
import { api } from "@multica/core/api";
|
|
import type { Attachment } from "@multica/core/types";
|
|
import { contentReferencesAttachment } from "@multica/core/types";
|
|
import { useCommentDraftStore, type CommentDraftKey } from "@multica/core/issues/stores";
|
|
import { cn } from "@multica/ui/lib/utils";
|
|
import type { AvatarSize } from "@multica/ui/lib/avatar-size";
|
|
import { useT } from "../../i18n";
|
|
import { CommentTriggerChips } from "./comment-trigger-chips";
|
|
import { useCommentTriggerPreview } from "../hooks/use-comment-trigger-preview";
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Types
|
|
// ---------------------------------------------------------------------------
|
|
|
|
interface ReplyInputProps {
|
|
issueId: string;
|
|
parentId: string;
|
|
placeholder?: string;
|
|
avatarType: string;
|
|
avatarId: string;
|
|
/** Resolves true on success, false on failure — the reply box keeps its text
|
|
* (locked + spinning) until then, clearing only on success. */
|
|
onSubmit: (content: string, attachmentIds?: string[], suppressAgentIds?: string[]) => Promise<boolean>;
|
|
size?: "sm" | "default";
|
|
/** When set, hydrates/persists the in-progress reply via the draft store.
|
|
* Required for replies inside virtualized timeline threads, where the
|
|
* enclosing CommentCard may unmount on scroll-out. */
|
|
draftKey?: CommentDraftKey;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// ReplyInput
|
|
// ---------------------------------------------------------------------------
|
|
|
|
function ReplyInput({
|
|
issueId,
|
|
parentId,
|
|
placeholder,
|
|
avatarType,
|
|
avatarId,
|
|
onSubmit,
|
|
size = "default",
|
|
draftKey,
|
|
}: ReplyInputProps) {
|
|
const { t } = useT("issues");
|
|
const placeholderText = placeholder ?? t(($) => $.reply.placeholder);
|
|
const editorRef = useRef<ContentEditorRef>(null);
|
|
// If a draft key is provided, hydrate from store on mount (defaultValue is
|
|
// the only injection point on ContentEditorRef) and flush on every onUpdate.
|
|
const initialDraft = draftKey
|
|
? useCommentDraftStore.getState().getDraft(draftKey)
|
|
: undefined;
|
|
const [content, setContent] = useState(initialDraft ?? "");
|
|
const setDraft = useCommentDraftStore((s) => s.setDraft);
|
|
const clearDraft = useCommentDraftStore((s) => s.clearDraft);
|
|
const [isEmpty, setIsEmpty] = useState(!initialDraft?.trim());
|
|
const [submitting, setSubmitting] = useState(false);
|
|
const [suppressedAgentIds, setSuppressedAgentIds] = useState<Set<string>>(() => new Set());
|
|
const triggerPreview = useCommentTriggerPreview({ issueId, parentId, content });
|
|
// Attachments uploaded in this composer session — see CommentInput for the
|
|
// rationale (drives both submit-time attachment_ids and editor previews).
|
|
const [pendingAttachments, setPendingAttachments] = useState<Attachment[]>([]);
|
|
const { uploadWithToast } = useFileUpload(api);
|
|
const { isDragOver, dropZoneProps } = useFileDropZone({
|
|
onDrop: (files) => files.forEach((f) => editorRef.current?.uploadFile(f)),
|
|
});
|
|
|
|
// Flush on tab close / mobile background — same rationale as CommentInput.
|
|
useEffect(() => {
|
|
if (!draftKey) return;
|
|
const flush = () => {
|
|
const md = editorRef.current?.getMarkdown();
|
|
if (md && md.trim().length > 0) setDraft(draftKey, md);
|
|
};
|
|
const onVis = () => { if (document.visibilityState === "hidden") flush(); };
|
|
document.addEventListener("visibilitychange", onVis);
|
|
window.addEventListener("pagehide", flush);
|
|
return () => {
|
|
document.removeEventListener("visibilitychange", onVis);
|
|
window.removeEventListener("pagehide", flush);
|
|
};
|
|
}, [draftKey, setDraft]);
|
|
|
|
const handleUpload = useCallback(async (file: File) => {
|
|
const result = await uploadWithToast(file, { issueId });
|
|
if (result) {
|
|
setPendingAttachments((prev) => [...prev, result]);
|
|
}
|
|
return result;
|
|
}, [uploadWithToast, issueId]);
|
|
|
|
useEffect(() => {
|
|
setSuppressedAgentIds(new Set());
|
|
}, [issueId, parentId]);
|
|
|
|
useEffect(() => {
|
|
const visible = new Set(triggerPreview.agents.map((agent) => agent.id));
|
|
setSuppressedAgentIds((prev) => {
|
|
const next = new Set([...prev].filter((id) => visible.has(id)));
|
|
return next.size === prev.size ? prev : next;
|
|
});
|
|
}, [triggerPreview.agents]);
|
|
|
|
const toggleSuppressedAgent = useCallback((agentId: string) => {
|
|
setSuppressedAgentIds((prev) => {
|
|
const next = new Set(prev);
|
|
if (next.has(agentId)) next.delete(agentId);
|
|
else next.add(agentId);
|
|
return next;
|
|
});
|
|
}, []);
|
|
|
|
const handleSubmit = async () => {
|
|
const content = editorRef.current?.getMarkdown()?.replace(/(\n\s*)+$/, "").trim();
|
|
if (!content || submitting) return;
|
|
// Track every attachment whose stable download URL OR legacy
|
|
// storage URL is referenced in the markdown body. Both shapes
|
|
// can appear in the same comment during the MUL-3130 rollout.
|
|
const activeIds = pendingAttachments
|
|
.filter((a) => contentReferencesAttachment(content, a))
|
|
.map((a) => a.id);
|
|
const suppressAgentIds = triggerPreview.agents
|
|
.filter((agent) => suppressedAgentIds.has(agent.id))
|
|
.map((agent) => agent.id);
|
|
// Pessimistic submit (see CommentInput): keep the text, lock + spin, clear
|
|
// only once the server accepts it.
|
|
setSubmitting(true);
|
|
try {
|
|
const ok = await onSubmit(
|
|
content,
|
|
activeIds.length > 0 ? activeIds : undefined,
|
|
suppressAgentIds.length > 0 ? suppressAgentIds : undefined,
|
|
);
|
|
if (ok) {
|
|
editorRef.current?.clearContent();
|
|
setContent("");
|
|
setIsEmpty(true);
|
|
setSuppressedAgentIds(new Set());
|
|
setPendingAttachments([]);
|
|
if (draftKey) clearDraft(draftKey);
|
|
}
|
|
} finally {
|
|
setSubmitting(false);
|
|
}
|
|
};
|
|
|
|
const avatarSize: AvatarSize = size === "sm" ? "sm" : "md";
|
|
|
|
return (
|
|
<div className="group/editor flex items-start gap-2.5">
|
|
<ActorAvatar
|
|
actorType={avatarType}
|
|
actorId={avatarId}
|
|
size={avatarSize}
|
|
className="mt-0.5 shrink-0"
|
|
/>
|
|
<div
|
|
{...dropZoneProps}
|
|
className={cn(
|
|
"relative min-w-0 flex-1 flex flex-col",
|
|
!isEmpty && "pb-9",
|
|
)}
|
|
>
|
|
{/* Lock the editor while the reply is in flight — see CommentInput. */}
|
|
<div
|
|
className={cn(
|
|
"flex-1 min-h-0 overflow-y-auto",
|
|
submitting && "pointer-events-none opacity-60",
|
|
)}
|
|
aria-busy={submitting || undefined}
|
|
>
|
|
<ContentEditor
|
|
ref={editorRef}
|
|
defaultValue={initialDraft}
|
|
placeholder={placeholderText}
|
|
onUpdate={(md) => {
|
|
setContent(md);
|
|
setIsEmpty(!md.trim());
|
|
if (draftKey) {
|
|
if (md.trim().length > 0) setDraft(draftKey, md);
|
|
else clearDraft(draftKey);
|
|
}
|
|
}}
|
|
onSubmit={handleSubmit}
|
|
onUploadFile={handleUpload}
|
|
debounceMs={100}
|
|
currentIssueId={issueId}
|
|
attachments={pendingAttachments}
|
|
enableSlashCommands
|
|
slashCommandMode="command"
|
|
/>
|
|
</div>
|
|
<div className="absolute bottom-0 left-0 right-24 min-w-0">
|
|
<CommentTriggerChips
|
|
agents={triggerPreview.agents}
|
|
suppressedAgentIds={suppressedAgentIds}
|
|
onToggle={toggleSuppressedAgent}
|
|
/>
|
|
</div>
|
|
<div className="absolute bottom-0 right-0 flex items-center gap-1">
|
|
<FileUploadButton
|
|
size="sm"
|
|
multiple
|
|
onSelect={(file) => editorRef.current?.uploadFile(file)}
|
|
/>
|
|
<Button
|
|
type="button"
|
|
variant={isEmpty ? "ghost" : "default"}
|
|
size="icon-xs"
|
|
disabled={isEmpty || submitting}
|
|
onClick={handleSubmit}
|
|
>
|
|
{submitting ? (
|
|
<Loader2 className="h-3.5 w-3.5 animate-spin" />
|
|
) : (
|
|
<ArrowUp className="h-3.5 w-3.5" />
|
|
)}
|
|
</Button>
|
|
</div>
|
|
{isDragOver && <FileDropOverlay />}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export { ReplyInput, type ReplyInputProps };
|