diff --git a/src/components/code-editor/YAMLEditor.tsx b/src/components/code-editor/YAMLEditor.tsx index 8328e5a..4081fcf 100644 --- a/src/components/code-editor/YAMLEditor.tsx +++ b/src/components/code-editor/YAMLEditor.tsx @@ -2,6 +2,7 @@ import { Dialog } from "@headlessui/react"; import useSWR from "swr"; import axios from "axios"; import dynamic from "next/dynamic"; +import { useEffect } from "react"; const Editor = dynamic(() => import("@monaco-editor/react"), { ssr: false }); @@ -13,6 +14,15 @@ function YAMLEditor(props: { }) { const { data: editorBody, mutate } = useSWR("/api/compose", fetcher); + useEffect(() => { + async function updateBody() { + await mutate(); + } + if (props.YAMLEditorOpen) { + updateBody(); + } + }, [mutate, props.YAMLEditorOpen]); + const handleYAMLEditorClose = () => { props.handleYAMLEditorClose(); }; diff --git a/src/pages/dashboard/index.tsx b/src/pages/dashboard/index.tsx index 5cb1983..ddfd5ee 100644 --- a/src/pages/dashboard/index.tsx +++ b/src/pages/dashboard/index.tsx @@ -168,8 +168,9 @@ const Dashboard: NextPage = () => { setYAMLEditorOpen(true); }; - const handleYAMLEditorClose = () => { + const handleYAMLEditorClose = async () => { setYAMLEditorOpen(false); + await mutate(); }; return (