Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Anchel123 committed Jan 22, 2025
1 parent d192e0f commit ecf24d7
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions app/components/ForceGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default function ForceGraph({
const [parentHeight, setParentHeight] = useState<number>(0)
const [hoverElement, setHoverElement] = useState<Node | Link | undefined>()
const parentRef = useRef<HTMLDivElement>(null)
const lastClick = useRef<{ date: Date, name: string }>({ date: new Date(), name: "" })
const toast = useToast()

useEffect(() => {
Expand Down Expand Up @@ -119,19 +120,29 @@ export default function ForceGraph({
graph.removeLinks()
}

const handleNodeRightClick = async (node: Node) => {
const handleNodeClick = async (node: Node) => {

const now = new Date()
const { date, name } = lastClick.current

if (now.getTime() - date.getTime() < 1000 && name === (node.data.name || node.id.toString())) {
return
}

if (!node.expand) {
await onFetchNode(node)
} else {
deleteNeighbors([node])
}

lastClick.current = { date: new Date(), name: node.data.name || node.id.toString() }
}

const handleHover = (element: Node | Link | null) => {
setHoverElement(element === null ? undefined : element)
}

const handleClick = (element: Node | Link, evt: MouseEvent) => {
const handleRightClick = (element: Node | Link, evt: MouseEvent) => {
if (!("source" in element) && isAddElement) {
if (setSelectedNodes) {
setSelectedNodes(prev => {
Expand Down Expand Up @@ -263,11 +274,11 @@ export default function ForceGraph({
ctx.fillText(link.label, 0, 0);
ctx.restore()
}}
onNodeClick={handleClick}
onLinkClick={handleClick}
onNodeClick={handleNodeClick}
onNodeHover={handleHover}
onLinkHover={handleHover}
onNodeRightClick={handleNodeRightClick}
onNodeRightClick={handleRightClick}
onLinkRightClick={handleRightClick}
onBackgroundClick={handleUnselected}
onBackgroundRightClick={handleUnselected}
onEngineStop={() => {
Expand Down

0 comments on commit ecf24d7

Please sign in to comment.