2
0

fix(editor): 🐛 Edge not properly connecting to step target

This commit is contained in:
Baptiste Arnaud
2022-02-19 18:09:09 +01:00
parent 3456e5af82
commit 7a4b96ff7e
6 changed files with 122 additions and 118 deletions

View File

@ -1,5 +1,5 @@
import { Coordinates, useGraph } from 'contexts/GraphContext'
import React, { useMemo } from 'react'
import React, { useLayoutEffect, useMemo, useState } from 'react'
import {
getAnchorsPosition,
computeEdgePath,
@ -38,23 +38,22 @@ export const Edge = ({ edge }: { edge: EdgeProps }) => {
getSourceEndpointId(edge)
),
// eslint-disable-next-line react-hooks/exhaustive-deps
[
sourceBlockCoordinates?.x,
sourceBlockCoordinates?.y,
edge,
sourceEndpoints,
]
[sourceBlockCoordinates?.y, edge, sourceEndpoints]
)
const targetTop = useMemo(
() => getEndpointTopOffset(targetEndpoints, graphOffsetY, edge?.to.stepId),
// eslint-disable-next-line react-hooks/exhaustive-deps
[
targetBlockCoordinates?.x,
targetBlockCoordinates?.y,
edge?.to.stepId,
targetEndpoints,
]
const [targetTop, setTargetTop] = useState(
getEndpointTopOffset(targetEndpoints, graphOffsetY, edge?.to.stepId)
)
useLayoutEffect(() => {
setTargetTop(
getEndpointTopOffset(targetEndpoints, graphOffsetY, edge?.to.stepId)
)
}, [
targetBlockCoordinates?.y,
targetEndpoints,
graphOffsetY,
edge?.to.stepId,
])
const path = useMemo(() => {
if (!sourceBlockCoordinates || !targetBlockCoordinates || !sourceTop)