import { useState } from "react"; import { Plus, X } from "lucide-react"; import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"; import { REACTION_EMOJIS, type Reactions } from "@/api/types"; import { cn } from "@/lib/utils"; import type { Human } from "@/api/types"; interface ReactionBarProps { reactions: Reactions; currentHumanId: string; humans?: Human[]; onToggle: (emoji: string) => void; } function getReactorNames( humanIds: string[], humans?: Human[], ): string { return humanIds .map((id) => { const human = humans?.find((h) => h.id === id); return human?.email_prefix ?? id; }) .join(", "); } export function ReactionBar({ reactions, currentHumanId, humans, onToggle }: ReactionBarProps) { const [expanded, setExpanded] = useState(false); const activeEmojis = REACTION_EMOJIS.filter( (emoji) => reactions?.[emoji] && reactions[emoji].length > 0, ); const handleToggle = (emoji: string) => { onToggle(emoji); setExpanded(false); }; return (
{/* Existing reaction pills */} {activeEmojis.map((emoji) => { const reactors = reactions![emoji]; const isMine = reactors.includes(currentHumanId); return ( {getReactorNames(reactors, humans)} ); })} {/* Expand / picker toggle */} {expanded ? (
{REACTION_EMOJIS.map((emoji) => { // Skip emojis that already have pills if (activeEmojis.includes(emoji)) return null; return ( ); })}
) : ( )}
); }