UNPKG

pyb-ts

Version:

PYB-CLI - Minimal AI Agent with multi-model support and CLI interface

32 lines (31 loc) 869 B
import { useRef } from "react"; const DOUBLE_PRESS_TIMEOUT_MS = 2e3; function useDoublePress(setPending, onDoublePress, onFirstPress) { const lastPressRef = useRef(0); const timeoutRef = useRef(); return () => { const now = Date.now(); const timeSinceLastPress = now - lastPressRef.current; if (timeSinceLastPress <= DOUBLE_PRESS_TIMEOUT_MS && timeoutRef.current) { if (timeoutRef.current) { clearTimeout(timeoutRef.current); timeoutRef.current = void 0; } onDoublePress(); setPending(false); } else { onFirstPress?.(); setPending(true); timeoutRef.current = setTimeout( () => setPending(false), DOUBLE_PRESS_TIMEOUT_MS ); } lastPressRef.current = now; }; } export { DOUBLE_PRESS_TIMEOUT_MS, useDoublePress }; //# sourceMappingURL=useDoublePress.js.map