Commit cd0c47aa authored by Michael Vrána's avatar Michael Vrána

Edge replacing

parent d231ac00
Pipeline #80168 passed with stages
in 4 minutes and 19 seconds
......@@ -5,7 +5,7 @@ import ParamNode from './ParamNode'
import { AlibType } from '../../../interfaces/Algorithms'
import { Actions, ReduxState } from '../../../reducers'
const { updateGhostEdge, setBuildEdge, addEdge } = Actions
const { updateGhostEdge, setBuildEdge, addEdge, deleteEdge } = Actions
export interface ParamNodeContainerProps {
nodeId: string
......@@ -23,61 +23,66 @@ const ParamNodeContainer = (props: ParamNodeContainerProps) => {
const dispatch = useDispatch()
const { edges, ghostEdge, buildEdge, hasError, cursorMode } = useSelector(
(state: ReduxState) => ({
edges: state.algorithmData.present.edges,
ghostEdge: state.algorithmUI.ghostEdge,
buildEdge: state.algorithmCanvas.buildEdge,
hasError: state.algorithmData.present.incompatibleEdges.some(
(state: ReduxState) => {
const edges = state.algorithmData.present.edges.filter(
(edge) =>
(edge.startNodeId === nodeId && paramIndex === undefined) ||
edge.startNodeId === nodeId ||
(edge.endNodeId === nodeId &&
edge.endParamIndex === paramIndex)
),
cursorMode: state.algorithmCanvas.cursorMode
})
)
return {
edges,
ghostEdge: state.algorithmUI.ghostEdge,
buildEdge: state.algorithmCanvas.buildEdge,
hasError: edges.some((edge) =>
state.algorithmData.present.incompatibleEdges.has(edge)
),
cursorMode: state.algorithmCanvas.cursorMode
}
}
)
const handleMouseDown = useCallback(
() => {
if (buildEdge || cursorMode === 'move') return
const handleMouseDown = useCallback(() => {
if (buildEdge || cursorMode === 'move') return
batch(() => {
dispatch(setBuildEdge(true))
dispatch(
updateGhostEdge(
isOutput
? {
startNodeId: nodeId,
endNodeId: ''
}
: {
endNodeId: nodeId,
endParamIndex: paramIndex,
startNodeId: ''
}
)
console.log(edges)
batch(() => {
dispatch(setBuildEdge(true))
if (isOutput)
return dispatch(
updateGhostEdge({ startNodeId: nodeId, endNodeId: '' })
)
})
},
[dispatch, nodeId, paramIndex, isOutput, buildEdge, cursorMode]
)
edges.forEach((edge) => dispatch(deleteEdge(edge.id)))
dispatch(
updateGhostEdge({
endNodeId: nodeId,
endParamIndex: paramIndex,
startNodeId: ''
})
)
})
}, [dispatch, nodeId, paramIndex, isOutput, buildEdge, cursorMode, edges])
const handleInputMouseUp = useCallback(
(e: React.MouseEvent) => {
e.stopPropagation()
if (
// is the same node
ghostEdge.startNodeId === nodeId ||
// already has an end
ghostEdge.endNodeId ||
edges.some(
(edge) =>
edge.endNodeId === nodeId &&
edge.endParamIndex === paramIndex
)
edges.some((edge) => ghostEdge.startNodeId === edge.startNodeId)
)
return
batch(() => {
edges.forEach((edge) => dispatch(deleteEdge(edge.id)))
dispatch(setBuildEdge(false))
dispatch(
addEdge({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment