2
0

fix(editor): 🐛 Throttle incoming typebot to avoid overwrite bug

This commit is contained in:
Baptiste Arnaud
2022-05-12 10:04:19 -07:00
parent 22e4873c11
commit 6af47f0277
2 changed files with 2 additions and 12 deletions

View File

@ -161,13 +161,6 @@ export const TypebotContext = ({
useEffect(() => { useEffect(() => {
if (!typebot || !currentTypebotRef.current) return if (!typebot || !currentTypebotRef.current) return
if (
dequal(
omit(typebot, 'updatedAt'),
omit(currentTypebotRef.current, 'updatedAt')
)
)
return
if (typebotId !== currentTypebotRef.current.id) { if (typebotId !== currentTypebotRef.current.id) {
setLocalTypebot({ ...typebot }) setLocalTypebot({ ...typebot })
flush() flush()
@ -189,10 +182,7 @@ export const TypebotContext = ({
const saveTypebot = async (options?: { disableMutation: boolean }) => { const saveTypebot = async (options?: { disableMutation: boolean }) => {
if (!currentTypebotRef.current || !typebot) return if (!currentTypebotRef.current || !typebot) return
const typebotToSave = { const typebotToSave = { ...currentTypebotRef.current }
...currentTypebotRef.current,
updatedAt: new Date().toISOString(),
}
if (dequal(omit(typebot, 'updatedAt'), omit(typebotToSave, 'updatedAt'))) if (dequal(omit(typebot, 'updatedAt'), omit(typebotToSave, 'updatedAt')))
return return
setIsSavingLoading(true) setIsSavingLoading(true)

View File

@ -92,7 +92,7 @@ const reducer = <T>(state: State<T>, action: Action<T>) => {
// ) // )
return { return {
past: [...past, present].filter(isDefined), past: [...past, present].filter(isDefined),
present: newPresent, present: { ...newPresent, updatedAt: new Date() },
future: [], future: [],
} }
} }