2
0

feat(editor): Add auto save

This commit is contained in:
Baptiste Arnaud
2022-01-23 08:23:05 +01:00
parent a58600a38a
commit 079cf5ec57
20 changed files with 145 additions and 198 deletions

View File

@ -30,6 +30,9 @@ import { choiceItemsAction, ChoiceItemsActions } from './actions/choiceItems'
import { variablesAction, VariablesActions } from './actions/variables'
import { edgesAction, EdgesActions } from './actions/edges'
import { webhooksAction, WebhooksAction } from './actions/webhooks'
import { useDebounce } from 'use-debounce'
const autoSaveTimeout = 10000
type UpdateTypebotPayload = Partial<{
theme: Theme
@ -85,6 +88,12 @@ export const TypebotContext = ({
undefined
)
const [debouncedLocalTypebot] = useDebounce(localTypebot, autoSaveTimeout)
useEffect(() => {
if (hasUnsavedChanges) saveTypebot()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [debouncedLocalTypebot])
const [localPublishedTypebot, setLocalPublishedTypebot] =
useState<PublicTypebot>()
const [isSavingLoading, setIsSavingLoading] = useState(false)