2
0

🚸 (editor) Automatically move graph on first group on mount

This commit is contained in:
Baptiste Arnaud
2022-12-16 08:47:02 +01:00
parent 68de7b720f
commit 6c55510d80
2 changed files with 14 additions and 4 deletions

View File

@@ -53,7 +53,9 @@ export const Graph = ({
connectingIds, connectingIds,
} = useGraph() } = useGraph()
const { updateGroupCoordinates } = useGroupsCoordinates() const { updateGroupCoordinates } = useGroupsCoordinates()
const [graphPosition, setGraphPosition] = useState(graphPositionDefaultValue) const [graphPosition, setGraphPosition] = useState(
graphPositionDefaultValue(typebot.groups[0].graphCoordinates)
)
const [debouncedGraphPosition] = useDebounce(graphPosition, 200) const [debouncedGraphPosition] = useDebounce(graphPosition, 200)
const transform = useMemo( const transform = useMemo(
() => () =>

View File

@@ -40,7 +40,13 @@ export type Node = Omit<Group, 'blocks'> & {
})[] })[]
} }
export const graphPositionDefaultValue = { x: 400, y: 100, scale: 1 } export const graphPositionDefaultValue = (
firstGroupCoordinates: Coordinates
) => ({
x: 400 - firstGroupCoordinates.x,
y: 100 - firstGroupCoordinates.y,
scale: 1,
})
export type ConnectingIds = { export type ConnectingIds = {
source: Source source: Source
@@ -76,7 +82,7 @@ const graphContext = createContext<{
setFocusedGroupId: Dispatch<SetStateAction<string | undefined>> setFocusedGroupId: Dispatch<SetStateAction<string | undefined>>
//@ts-ignore //@ts-ignore
}>({ }>({
graphPosition: graphPositionDefaultValue, graphPosition: graphPositionDefaultValue({ x: 0, y: 0 }),
connectingIds: null, connectingIds: null,
}) })
@@ -87,7 +93,9 @@ export const GraphProvider = ({
children: ReactNode children: ReactNode
isReadOnly?: boolean isReadOnly?: boolean
}) => { }) => {
const [graphPosition, setGraphPosition] = useState(graphPositionDefaultValue) const [graphPosition, setGraphPosition] = useState(
graphPositionDefaultValue({ x: 0, y: 0 })
)
const [connectingIds, setConnectingIds] = useState<ConnectingIds | null>(null) const [connectingIds, setConnectingIds] = useState<ConnectingIds | null>(null)
const [previewingEdge, setPreviewingEdge] = useState<Edge>() const [previewingEdge, setPreviewingEdge] = useState<Edge>()
const [sourceEndpoints, setSourceEndpoints] = useState<IdMap<Endpoint>>({}) const [sourceEndpoints, setSourceEndpoints] = useState<IdMap<Endpoint>>({})