Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added delay for node hover #1997

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading