throttle scroll zoom (#1287)

This commit is contained in:
Kurt Hutten
2024-01-12 09:14:37 +11:00
committed by GitHub
parent 15d96a072d
commit db98bcf2a0

View File

@ -7,7 +7,7 @@ import {
} from 'react' } from 'react'
import { v4 as uuidv4 } from 'uuid' import { v4 as uuidv4 } from 'uuid'
import { useStore } from '../useStore' import { useStore } from '../useStore'
import { getNormalisedCoordinates } from '../lib/utils' import { getNormalisedCoordinates, throttle } from '../lib/utils'
import Loading from './Loading' import Loading from './Loading'
import { cameraMouseDragGuards } from 'lib/cameraControls' import { cameraMouseDragGuards } from 'lib/cameraControls'
import { useGlobalStateContext } from 'hooks/useGlobalStateContext' import { useGlobalStateContext } from 'hooks/useGlobalStateContext'
@ -115,9 +115,9 @@ export const Stream = ({ className = '' }) => {
setClickCoords({ x, y }) setClickCoords({ x, y })
} }
const handleScroll: WheelEventHandler<HTMLVideoElement> = (e) => { const fps = 60
const handleScroll: WheelEventHandler<HTMLVideoElement> = throttle((e) => {
if (!cameraMouseDragGuards[cameraControls].zoom.scrollCallback(e)) return if (!cameraMouseDragGuards[cameraControls].zoom.scrollCallback(e)) return
engineCommandManager.sendSceneCommand({ engineCommandManager.sendSceneCommand({
type: 'modeling_cmd_req', type: 'modeling_cmd_req',
cmd: { cmd: {
@ -126,7 +126,7 @@ export const Stream = ({ className = '' }) => {
}, },
cmd_id: uuidv4(), cmd_id: uuidv4(),
}) })
} }, Math.round(1000 / fps))
const handleMouseUp: MouseEventHandler<HTMLVideoElement> = ({ const handleMouseUp: MouseEventHandler<HTMLVideoElement> = ({
clientX, clientX,