// "+1" on a sent line at the counter (plan 6F.5; the waiter app has the same): the first tap arms // it, more taps count up, "Send +N" sends one more of the same line (printed as new); 4 s without // a tap puts it back. Nothing is sent by one stray tap. import { useEffect, useRef, useState } from 'react' import { useTranslation } from '@xenia/i18n' import { Button } from '@xenia/ui' const WAIT_MS = 4000 export default function OneMore({ onSend }) { const { t } = useTranslation('terminal') const [count, setCount] = useState(0) const [busy, setBusy] = useState(false) const timer = useRef(null) useEffect(() => () => clearTimeout(timer.current), []) const tap = () => { if (busy) return setCount(c => Math.min(c + 1, 20)) clearTimeout(timer.current) timer.current = setTimeout(() => setCount(0), WAIT_MS) } const send = async () => { if (busy || !count) return clearTimeout(timer.current) setBusy(true) try { await onSend(count) } finally { setBusy(false); setCount(0) } } return ( {count > 0 && } ) }