From db98bcf2a0edd421025398e55a7dd9d74a86a7b2 Mon Sep 17 00:00:00 2001 From: Kurt Hutten Date: Fri, 12 Jan 2024 09:14:37 +1100 Subject: [PATCH] throttle scroll zoom (#1287) --- src/components/Stream.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/Stream.tsx b/src/components/Stream.tsx index 7464529f8..2b201d955 100644 --- a/src/components/Stream.tsx +++ b/src/components/Stream.tsx @@ -7,7 +7,7 @@ import { } from 'react' import { v4 as uuidv4 } from 'uuid' import { useStore } from '../useStore' -import { getNormalisedCoordinates } from '../lib/utils' +import { getNormalisedCoordinates, throttle } from '../lib/utils' import Loading from './Loading' import { cameraMouseDragGuards } from 'lib/cameraControls' import { useGlobalStateContext } from 'hooks/useGlobalStateContext' @@ -115,9 +115,9 @@ export const Stream = ({ className = '' }) => { setClickCoords({ x, y }) } - const handleScroll: WheelEventHandler = (e) => { + const fps = 60 + const handleScroll: WheelEventHandler = throttle((e) => { if (!cameraMouseDragGuards[cameraControls].zoom.scrollCallback(e)) return - engineCommandManager.sendSceneCommand({ type: 'modeling_cmd_req', cmd: { @@ -126,7 +126,7 @@ export const Stream = ({ className = '' }) => { }, cmd_id: uuidv4(), }) - } + }, Math.round(1000 / fps)) const handleMouseUp: MouseEventHandler = ({ clientX,