2
0

🐛 (editor) Fix undo / redo not working properly on button nodes

This commit is contained in:
Baptiste Arnaud
2022-11-17 17:46:24 +01:00
parent feaf49f137
commit c4a4aa3e83
2 changed files with 3 additions and 9 deletions

View File

@ -9,7 +9,7 @@ import {
import { PlusIcon } from '@/components/icons'
import { useTypebot } from '@/features/editor'
import { ButtonItem, ItemIndices, ItemType } from 'models'
import React, { useEffect, useRef, useState } from 'react'
import React, { useRef, useState } from 'react'
import { isNotDefined } from 'utils'
type Props = {
@ -20,16 +20,9 @@ type Props = {
export const ButtonsItemNode = ({ item, indices, isMouseOver }: Props) => {
const { deleteItem, updateItem, createItem } = useTypebot()
const [initialContent] = useState(item.content ?? '')
const [itemValue, setItemValue] = useState(item.content ?? 'Click to edit')
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 = () => {
if (itemValue === '') deleteItem(indices)
else
@ -38,7 +31,7 @@ export const ButtonsItemNode = ({ item, indices, isMouseOver }: Props) => {
const handleKeyPress = (e: React.KeyboardEvent<HTMLDivElement>) => {
if (e.key === 'Escape' && itemValue === 'Click to edit') deleteItem(indices)
if (e.key === 'Enter' && itemValue !== '' && initialContent === '')
if (e.key === 'Enter' && itemValue !== '' && itemValue !== 'Click to edit')
handlePlusClick()
}

View File

@ -14,6 +14,7 @@ export const ItemNodeContent = ({ item, indices, isMouseOver }: Props) => {
case ItemType.BUTTON:
return (
<ButtonsItemNode
key={item.content}
item={item}
isMouseOver={isMouseOver}
indices={indices}