import { useState } from 'react'; import { Plus, Type, X } from 'lucide-react'; import { Tooltip, TooltipContent, TooltipTrigger, } from '@/components/ui/tooltip'; import { HumanAvatar } from '@/components/human-avatar'; import { REACTION_EMOJIS, type Reactions, type Human } from '@/api/types'; import { cn } from '@/lib/utils'; import { resolveHumanDisplay } from '@/lib/humans'; interface ReactionBarProps { reactions: Reactions; currentHumanId: string; humans?: Human[]; onToggle: (key: string) => void; onOpenTextReaction: () => void; } const EMOJI_SET = new Set(REACTION_EMOJIS); function getReactorNames(humanIds: string[], humans?: Human[]): string { return humanIds .map((id) => resolveHumanDisplay(id, humans).displayName) .join(', '); } function getReactorList( humanIds: string[], humans: Human[] | undefined, currentHumanId: string, ): { id: string; label: string; isMine: boolean }[] { return humanIds.map((id) => ({ id, label: resolveHumanDisplay(id, humans).displayName, isMine: id === currentHumanId, })); } export function ReactionBar({ reactions, currentHumanId, humans, onToggle, onOpenTextReaction, }: ReactionBarProps) { const [expanded, setExpanded] = useState(false); const activeEmojis = REACTION_EMOJIS.filter( (emoji) => reactions?.[emoji] && reactions[emoji].length > 0, ); const activeTextReactions = Object.keys(reactions ?? {}).filter( (key) => !EMOJI_SET.has(key) && (reactions?.[key]?.length ?? 0) > 0, ); const handleToggle = (key: string) => { onToggle(key); setExpanded(false); }; return (
{/* Emoji reaction pills */} {activeEmojis.map((emoji) => { const reactors = reactions?.[emoji] ?? []; const isMine = reactors.includes(currentHumanId); return ( {getReactorNames(reactors, humans)} ); })} {/* Text reaction pills */} {activeTextReactions.map((text) => { const reactors = reactions?.[text] ?? []; const isMine = reactors.includes(currentHumanId); const firstReactor = resolveHumanDisplay(reactors[0], humans); const reactorList = getReactorList(reactors, humans, currentHumanId); return (
“{text}”
    {reactorList.map((r) => (
  • {r.label} {r.isMine && (you)}
  • ))}
{isMine ? 'Click to remove' : 'Click to add yours'}
); })} {/* Picker / actions */} {expanded ? (
{REACTION_EMOJIS.map((emoji) => { if (activeEmojis.includes(emoji)) return null; return ( ); })}
) : (
Quick reply{' '} R
)}
); }