Merge pull request #458 from vector-im/dbkr/fix_network_waiting_after_timeout

Fix 'waiting for network' after reaching time limit
This commit is contained in:
David Baker 2022-07-08 19:03:55 +01:00 committed by GitHub
commit aeec2c076e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -57,13 +57,17 @@ export const PTTButton: React.FC<Props> = ({
const buttonRef = useRef<HTMLButtonElement>(); const buttonRef = useRef<HTMLButtonElement>();
const [activeTouchId, setActiveTouchId] = useState<number | null>(null); const [activeTouchId, setActiveTouchId] = useState<number | null>(null);
const [buttonHeld, setButtonHeld] = useState(false);
const hold = useCallback(() => { const hold = useCallback(() => {
// This update is delayed so the user only sees it if latency is significant // This update is delayed so the user only sees it if latency is significant
if (buttonHeld) return;
setButtonHeld(true);
enqueueNetworkWaiting(true, 100); enqueueNetworkWaiting(true, 100);
startTalking(); startTalking();
}, [enqueueNetworkWaiting, startTalking]); }, [enqueueNetworkWaiting, startTalking, buttonHeld]);
const unhold = useCallback(() => { const unhold = useCallback(() => {
setButtonHeld(false);
setNetworkWaiting(false); setNetworkWaiting(false);
stopTalking(); stopTalking();
}, [setNetworkWaiting, stopTalking]); }, [setNetworkWaiting, stopTalking]);