From c24c5ee54ef033794ae1188e083740279370e270 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Fri, 18 Aug 2023 15:41:06 -0400 Subject: [PATCH] POSTing the body to the server. --- static/index.html | 10 +++++++++- static/script.js | 35 +++++++++++++++++++++++++++++++++++ static/style.css | 0 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 static/script.js create mode 100644 static/style.css diff --git a/static/index.html b/static/index.html index 13606a2..5564d9f 100644 --- a/static/index.html +++ b/static/index.html @@ -1,5 +1,13 @@ + + + + - Test html file. + Input org-mode source:
+ +
+
+
diff --git a/static/script.js b/static/script.js new file mode 100644 index 0000000..06b8c00 --- /dev/null +++ b/static/script.js @@ -0,0 +1,35 @@ +let inFlightRequest = null; +const inputElement = document.querySelector("#org-input"); +const outputElement = document.querySelector("#parse-output"); + +function abortableFetch(request, options) { + const controller = new AbortController(); + const signal = controller.signal; + + return { + abort: () => controller.abort(), + ready: fetch(request, { ...options, signal }) + }; +} + +async function renderParseResponse(response) { + console.log(response); +} + +inputElement.addEventListener("input", async () => { + let orgSource = inputElement.value; + if (inFlightRequest != null) { + inFlightRequest.abort(); + inFlightRequest = null; + } + + let newRequest = abortableFetch("/parse", { + method: "POST", + cache: "no-cache", + body: orgSource, + }); + inFlightRequest = newRequest; + + let response = await inFlightRequest.ready; + renderParseResponse(await response.json()); +}); diff --git a/static/style.css b/static/style.css new file mode 100644 index 0000000..e69de29