import { BoxProps, Flex } from '@chakra-ui/react' import { useGraph, useGroupsCoordinates } from 'contexts/GraphContext' import { Source } from 'models' import React, { MouseEvent, useEffect, useRef, useState } from 'react' export const SourceEndpoint = ({ source, ...props }: BoxProps & { source: Source }) => { const [ranOnce, setRanOnce] = useState(false) const { setConnectingIds, addSourceEndpoint, previewingEdge } = useGraph() const { groupsCoordinates } = useGroupsCoordinates() const ref = useRef(null) const handleMouseDown = (e: MouseEvent) => { e.stopPropagation() setConnectingIds({ source }) } useEffect(() => { if (ranOnce || !ref.current || Object.keys(groupsCoordinates).length === 0) return const id = source.itemId ?? source.blockId addSourceEndpoint({ id, ref, }) setRanOnce(true) // eslint-disable-next-line react-hooks/exhaustive-deps }, [ref.current, groupsCoordinates]) if (!groupsCoordinates) return <> return ( ) }