2
0

♻️ Normalize data

This commit is contained in:
Baptiste Arnaud
2022-01-06 09:40:56 +01:00
parent 6c1e0fd345
commit 9fa4c7dffa
114 changed files with 1545 additions and 1632 deletions

View File

@ -1,4 +1,4 @@
import { Block, PublicTypebot } from 'bot-engine'
import { PublicTypebot } from 'models'
import {
createContext,
Dispatch,
@ -8,6 +8,7 @@ import {
useState,
} from 'react'
import { Coordinates } from './GraphContext'
import produce from 'immer'
type Position = Coordinates & { scale: number }
@ -35,31 +36,13 @@ export const AnalyticsGraphProvider = ({
const [graphPosition, setGraphPosition] = useState(graphPositionDefaultValue)
const updateBlocks = (blocks: Block[]) => {
if (!typebot) return
setTypebot({
...typebot,
blocks: [...blocks],
})
}
const updateBlockPosition = (blockId: string, newPosition: Coordinates) => {
if (!typebot) return
blockId === 'start-block'
? setTypebot({
...typebot,
startBlock: {
...typebot.startBlock,
graphCoordinates: newPosition,
},
})
: updateBlocks(
typebot.blocks.map((block) =>
block.id === blockId
? { ...block, graphCoordinates: newPosition }
: block
)
)
setTypebot(
produce(typebot, (nextTypebot) => {
nextTypebot.blocks.byId[blockId].graphCoordinates = newPosition
})
)
}
return (