Skip to content

Commit

Permalink
Merge pull request #1997 from stakwork/feature/delay-for-node-hover
Browse files Browse the repository at this point in the history
feat: added delay for node hover
  • Loading branch information
Rassl authored Aug 5, 2024
2 parents 8ea983c + 2941333 commit 7448d7b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/components/Universe/Graph/Cubes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Select } from '@react-three/drei'
import { ThreeEvent } from '@react-three/fiber'
import { memo, useCallback } from 'react'
import { memo, useCallback, useRef } from 'react'
import { Object3D } from 'three'
import { useAppStore } from '~/stores/useAppStore'
import { useDataStore } from '~/stores/useDataStore'
Expand All @@ -12,6 +12,8 @@ import { RelevanceBadges } from './RelevanceBadges'
import { SelectionDataNodes } from './SelectionDataNodes'
import { TextNode } from './Text'

const POINTER_IN_DELAY = 200

export const Cubes = memo(() => {
const selectedNode = useSelectedNode()
const relativeIds = useSelectedNodeRelativeIds()
Expand Down Expand Up @@ -49,10 +51,17 @@ export const Cubes = memo(() => {
[setTranscriptOpen, ignoreNodeEvent],
)

const hoverTimeoutRef = useRef<NodeJS.Timeout | null>(null)

const onPointerOut = useCallback(
(e: ThreeEvent<PointerEvent>) => {
e.stopPropagation()

if (hoverTimeoutRef.current) {
clearTimeout(hoverTimeoutRef.current)
hoverTimeoutRef.current = null
}

setHoveredNode(null)
},
[setHoveredNode],
Expand All @@ -68,7 +77,10 @@ export const Cubes = memo(() => {

if (!ignoreNodeEvent(node)) {
e.stopPropagation()
setHoveredNode(node)

hoverTimeoutRef.current = setTimeout(() => {
setHoveredNode(node)
}, POINTER_IN_DELAY)
}
}
},
Expand Down

0 comments on commit 7448d7b

Please sign in to comment.