2
0

perf(editor): 🚸 More predictable edge management

This commit is contained in:
Baptiste Arnaud
2022-03-25 13:31:14 +01:00
parent f3c5f6bea2
commit c507ef55ae
7 changed files with 76 additions and 24 deletions

View File

@ -27,8 +27,14 @@ export const Graph = ({
answersCounts?: AnswersCount[]
onUnlockProPlanClick?: () => void
} & FlexProps) => {
const { draggedStepType, setDraggedStepType, draggedStep, setDraggedStep } =
useStepDnd()
const {
draggedStepType,
setDraggedStepType,
draggedStep,
setDraggedStep,
draggedItem,
setDraggedItem,
} = useStepDnd()
const graphContainerRef = useRef<HTMLDivElement | null>(null)
const editorContainerRef = useRef<HTMLDivElement | null>(null)
const { createBlock } = useTypebot()
@ -77,6 +83,7 @@ export const Graph = ({
const handleMouseUp = (e: MouseEvent) => {
if (!typebot) return
if (draggedItem) setDraggedItem(undefined)
if (!draggedStep && !draggedStepType) return
const coordinates = {
x: e.clientX - graphPosition.x - blockWidth / 3,

View File

@ -22,7 +22,7 @@ export const ItemNodesList = ({
indices: { blockIndex, stepIndex },
isReadOnly = false,
}: Props) => {
const { typebot, createItem, deleteItem } = useTypebot()
const { typebot, createItem, detachItemFromStep } = useTypebot()
const { draggedItem, setDraggedItem, mouseOverBlock } = useStepDnd()
const placeholderRefs = useRef<HTMLDivElement[]>([])
const blockId = typebot?.blocks[blockIndex].id
@ -96,7 +96,7 @@ export const ItemNodesList = ({
) => {
if (!typebot || isReadOnly) return
placeholderRefs.current.splice(itemIndex + 1, 1)
deleteItem({ blockIndex, stepIndex, itemIndex })
detachItemFromStep({ blockIndex, stepIndex, itemIndex })
setPosition(absolute)
setRelativeCoordinates(relative)
setDraggedItem(item)