Files
multica/packages/views/chat/components/quick-agent-bar.tsx
Naiyuan Qing f4de0948a2 refactor(ui): unify ActorAvatar size tiers + round all avatars & cropper (MUL-4277, MUL-4184) (#5133)
* 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>
2026-07-10 08:31:40 +08:00

116 lines
4.2 KiB
TypeScript

"use client";
import { useMemo } from "react";
import { useQuery } from "@tanstack/react-query";
import { Plus } from "lucide-react";
import { useWorkspaceId } from "@multica/core/hooks";
import { chatPinnedAgentsOptions } from "@multica/core/chat/queries";
import { usePinChatAgent, useUnpinChatAgent } from "@multica/core/chat/mutations";
import type { Agent } from "@multica/core/types";
import {
ContextMenu,
ContextMenuTrigger,
ContextMenuContent,
ContextMenuItem,
} from "@multica/ui/components/ui/context-menu";
import { ActorAvatar } from "../../common/actor-avatar";
import { AgentPicker } from "./new-chat-button";
import { useT } from "../../i18n";
// Consistent thin ring so photo avatars and (fainter) fallback avatars read as
// the same-size circle in the chat list.
const AVATAR_RING = "ring-1 ring-inset ring-border";
// Keep the bar compact — capped at 5, matching the server limit.
const MAX_PINNED = 5;
/**
* Quick-agent bar — a compact, avatar-only strip of the user's pinned agents at
* the top of the Chat list (per user · workspace, server-side). Tapping an
* avatar starts a new chat; hovering shows the agent info card; right-clicking
* removes it; the "+" adds one (up to 5). No title, no names — space is tight.
*/
export function QuickAgentBar({
agents,
userId,
onStartNewChat,
}: {
agents: Agent[];
userId: string | undefined;
onStartNewChat: (agent: Agent) => void;
}) {
const { t } = useT("chat");
const wsId = useWorkspaceId();
const { data: pinned = [] } = useQuery(chatPinnedAgentsOptions(wsId));
const pin = usePinChatAgent();
const unpin = useUnpinChatAgent();
const agentById = useMemo(() => new Map(agents.map((a) => [a.id, a])), [agents]);
const pinnedAgents = useMemo(
() => pinned.map((p) => agentById.get(p.agent_id)).filter((a): a is Agent => !!a),
[pinned, agentById],
);
const pinnedIds = useMemo(() => new Set(pinned.map((p) => p.agent_id)), [pinned]);
const addable = useMemo(() => agents.filter((a) => !pinnedIds.has(a.id)), [agents, pinnedIds]);
const canAdd = addable.length > 0 && pinnedAgents.length < MAX_PINNED;
// Nothing to pin and nothing pinned → hide the bar.
if (agents.length === 0) return null;
if (pinnedAgents.length === 0 && !canAdd) return null;
return (
<div className="flex items-center gap-1.5 overflow-x-auto border-b px-2 py-1.5">
{pinnedAgents.map((agent) => (
<ContextMenu key={agent.id}>
<ContextMenuTrigger
render={
<button
type="button"
aria-label={agent.name}
onClick={() => onStartNewChat(agent)}
className="flex size-[34px] shrink-0 items-center justify-center rounded-full outline-none focus-visible:ring-2 focus-visible:ring-ring"
/>
}
>
<ActorAvatar
actorType="agent"
actorId={agent.id}
size="lg"
showStatusDot
enableHoverCard
profileLink={false}
className={AVATAR_RING}
/>
</ContextMenuTrigger>
<ContextMenuContent>
<ContextMenuItem variant="destructive" onClick={() => unpin.mutate(agent.id)}>
{t(($) => $.list.unpin_agent)}
</ContextMenuItem>
</ContextMenuContent>
</ContextMenu>
))}
{canAdd && (
<AgentPicker
agents={addable}
userId={userId}
onSelect={(agent) => pin.mutate(agent.id)}
side="bottom"
align="start"
triggerRender={
<button
type="button"
aria-label={t(($) => $.list.add_agent)}
// Filled circle (not a dashed outline) so it reads as the exact
// same size as the filled agent avatars — an empty outline looks
// larger at the same pixel diameter. Same ring as the avatars.
className="flex size-[34px] shrink-0 items-center justify-center rounded-full bg-muted text-muted-foreground ring-1 ring-inset ring-border outline-none transition-colors hover:bg-accent hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring"
/>
}
trigger={<Plus className="size-4" />}
/>
)}
</div>
);
}