Skip to content

Commit

Permalink
(editor): 🩹 Slow down graph panning on Chromium
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Feb 15, 2022
1 parent e6f6e25 commit 130f85e
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions apps/builder/components/shared/Graph/Graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { generate } from 'short-uuid'
import { AnswersCount } from 'services/analytics'
import { useDebounce } from 'use-debounce'

declare const window: { chrome: unknown | undefined }

export const Graph = ({
typebot,
answersCounts,
Expand Down Expand Up @@ -60,19 +62,12 @@ export const Graph = ({
const handleMouseWheel = (e: WheelEvent) => {
e.preventDefault()
const isPinchingTrackpad = e.ctrlKey
if (isPinchingTrackpad) {
const scale = graphPosition.scale - e.deltaY * 0.01
if (scale <= 0.2 || scale >= 1) return
setGraphPosition({
...graphPosition,
scale,
})
} else
setGraphPosition({
...graphPosition,
x: graphPosition.x - e.deltaX,
y: graphPosition.y - e.deltaY,
})
if (isPinchingTrackpad) return
setGraphPosition({
...graphPosition,
x: graphPosition.x - e.deltaX / (window.chrome ? 2 : 1),
y: graphPosition.y - e.deltaY / (window.chrome ? 2 : 1),
})
}

const handleGlobalMouseUp = () => setIsMouseDown(false)
Expand Down Expand Up @@ -107,8 +102,8 @@ export const Graph = ({
if (!isMouseDown) return
const { movementX, movementY } = event
setGraphPosition({
x: graphPosition.x + movementX,
y: graphPosition.y + movementY,
x: graphPosition.x + movementX / (window.chrome ? 2 : 1),
y: graphPosition.y + movementY / (window.chrome ? 2 : 1),
scale: 1,
})
}
Expand Down

3 comments on commit 130f85e

@vercel
Copy link

@vercel vercel bot commented on 130f85e Feb 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-typebot-io.vercel.app
builder-v2-git-main-typebot-io.vercel.app
next.typebot.io

@vercel
Copy link

@vercel vercel bot commented on 130f85e Feb 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

viewer-v2 – ./apps/viewer

viewer-v2-typebot-io.vercel.app
typebot-viewer.vercel.app
viewer-v2-git-main-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 130f85e Feb 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

landing-page-v2 – ./apps/landing-page

landing-page-v2-typebot-io.vercel.app
landing-page-v2-jade.vercel.app
landing-page-v2-git-main-typebot-io.vercel.app

Please sign in to comment.