2
0

fix(editor): 🐛 Undo with item change

This commit is contained in:
Baptiste Arnaud
2022-03-28 15:18:02 +02:00
parent f869ca377a
commit cd6c5c04c5

View File

@ -9,7 +9,7 @@ import {
import { PlusIcon } from 'assets/icons' import { PlusIcon } from 'assets/icons'
import { useTypebot } from 'contexts/TypebotContext' import { useTypebot } from 'contexts/TypebotContext'
import { ButtonItem, ItemIndices, ItemType } from 'models' import { ButtonItem, ItemIndices, ItemType } from 'models'
import React, { useRef, useState } from 'react' import React, { useEffect, useRef, useState } from 'react'
import { isNotDefined } from 'utils' import { isNotDefined } from 'utils'
type Props = { type Props = {
@ -30,6 +30,12 @@ export const ButtonNodeContent = ({
const [itemValue, setItemValue] = useState(item.content ?? 'Click to edit') const [itemValue, setItemValue] = useState(item.content ?? 'Click to edit')
const editableRef = useRef<HTMLDivElement | null>(null) const editableRef = useRef<HTMLDivElement | null>(null)
useEffect(() => {
if (itemValue !== item.content)
setItemValue(item.content ?? 'Click to edit')
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [item])
const handleInputSubmit = () => { const handleInputSubmit = () => {
if (itemValue === '') deleteItem(indices) if (itemValue === '') deleteItem(indices)
else else