This is an automated email from the ASF dual-hosted git repository. marat pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-karavan.git
commit ac14c13b1a135f9b0cea89e60b1fe4361eeb1554 Author: Marat Gubaidullin <ma...@talismancloud.io> AuthorDate: Thu Mar 14 18:46:24 2024 -0400 Fix #1170 --- karavan-app/src/main/webui/src/editor/CodeEditor.tsx | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/karavan-app/src/main/webui/src/editor/CodeEditor.tsx b/karavan-app/src/main/webui/src/editor/CodeEditor.tsx index 3658889b..3ff9d5ba 100644 --- a/karavan-app/src/main/webui/src/editor/CodeEditor.tsx +++ b/karavan-app/src/main/webui/src/editor/CodeEditor.tsx @@ -36,12 +36,21 @@ export function CodeEditor(props: Props) { const [file, designerTab, setFile] = useFileStore((s) => [s.file, s.designerTab, s.setFile], shallow) const [code, setCode] = useState<string>(); + useEffect(() => setCode(file?.code), []); + useEffect(() => { - setCode(file?.code); - }, []); + const interval = setInterval(() => { + saveCode(); + }, 3000); + return () => { + clearInterval(interval); + saveCode(); + } + }, [code]); + - function save(name: string, code: string) { - if (file) { + function saveCode() { + if (file && code && file.code !== code) { file.code = code; ProjectService.updateFile(file, true); } @@ -59,7 +68,7 @@ export function CodeEditor(props: Props) { className={'code-editor'} onChange={(value, ev) => { if (value) { - save(file?.name, value) + setCode(value) } }} />