import { useEffect, useState } from 'react'; import { AnimatePresence, motion } from 'framer-motion'; import { PING_EMOJIS, type Role, type RoomState } from '@two-keys/shared'; import { socket } from '../lib/socket'; import { ROLE_TEXT } from '../lib/theme'; /** Partner's online dot, what they're looking at, and the ping buttons. */ export function PartnerStatus({ state }: { state: RoomState }) { const [open, setOpen] = useState(false); const partner = state.partner; const name = partner?.seat ? state.game.roles[partner.seat].name : 'Partner'; return (
{open && ( // Anchored to the header bar (not the button) so it always fits a narrow screen.

{partner?.online ? 'Online' : 'Offline. They can rejoin with the same link.'} {partner?.online && partner.viewing ? ` ยท looking at ${partner.viewing}` : ''}

{PING_EMOJIS.map((emoji) => ( ))}
)}
); } interface Ping { id: number; emoji: string; from: Role; x: number; } /** Reactions from the partner float up the screen. */ export function PingOverlay({ roles }: { roles: RoomState['game']['roles'] }) { const [pings, setPings] = useState([]); useEffect(() => { let nextId = 1; const onPing = ({ from, emoji }: { from: Role; emoji: string }) => { const id = nextId++; setPings((p) => [...p, { id, emoji, from, x: 15 + Math.random() * 70 }]); setTimeout(() => setPings((p) => p.filter((x) => x.id !== id)), 2600); }; socket.on('ping', onPing); return () => { socket.off('ping', onPing); }; }, []); return (
{pings.map((p) => ( {p.emoji} {roles[p.from].name} ))}
); }