From 3f973d1170a136457cd188624079a5860aff070d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 14 Nov 2023 11:05:56 +0100 Subject: [PATCH] Implement form handler --- .../realtime-compiler/resources/live-edit.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/realtime-compiler/resources/live-edit.js b/packages/realtime-compiler/resources/live-edit.js index ca7714ea47b..cbe9b5816de 100644 --- a/packages/realtime-compiler/resources/live-edit.js +++ b/packages/realtime-compiler/resources/live-edit.js @@ -61,7 +61,21 @@ function initLiveEdit() { } function handleFormSubmit(event, editor) { - // + event.preventDefault(); + + fetch('/_hyde/live-edit', { + method: "POST", + body: new FormData(event.target), + headers: new Headers({ + "Accept": "application/json", + }), + }).then(async response => { + if (response.ok) { + window.location.reload(); + } else { + alert(`Error saving content: ${response.status} ${response.statusText}\n${JSON.parse(await response.text()).error ?? 'Unknown error'}`); + } + }); } const article = getArticle();