From 64cc2a9f2b6b86f0c292c1fef4b0ded7151e9a20 Mon Sep 17 00:00:00 2001 From: Anthony LC Date: Thu, 18 Apr 2024 09:48:53 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B(app-impress)=20fix=20bug=20rerende?= =?UTF-8?q?ring=20when=20empty=20data?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the data is empty, the editor kept the previous data and didn't rerender correctly the current editor. This commit fixes this issue. --- .../template/components/TemplateEditor.tsx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/frontend/apps/impress/src/features/templates/template/components/TemplateEditor.tsx b/src/frontend/apps/impress/src/features/templates/template/components/TemplateEditor.tsx index 13fe9f6d..f62502c2 100644 --- a/src/frontend/apps/impress/src/features/templates/template/components/TemplateEditor.tsx +++ b/src/frontend/apps/impress/src/features/templates/template/components/TemplateEditor.tsx @@ -44,17 +44,19 @@ export const TemplateEditor = ({ template }: TemplateEditorProps) => { }, [html, showWarning]); useEffect(() => { - if (!editor?.loadProjectData) { + if (!editor?.loadProjectData || !editor?.Storage) { return; } - editor.loadProjectData(template.code_editor); - }, [template.code_editor, editor]); + const projectData = Object.keys(template.code_editor).length + ? template.code_editor + : editor.getProjectData(); - useEffect(() => { - editor?.Storage.add('remote', { + editor.loadProjectData(projectData); + + editor.Storage.add('remote', { load() { - return Promise.resolve(template.code_editor); + return Promise.resolve(projectData); }, store(data: ProjectData) { updateCodeEditor({ @@ -71,7 +73,7 @@ export const TemplateEditor = ({ template }: TemplateEditorProps) => { editor?.Storage.add('remote', { load() { - return Promise.resolve(template.code_editor); + return Promise.resolve(editor.getProjectData()); }, store() { return Promise.resolve();