From 165f0d3457356d68e182783445196203f7135cad Mon Sep 17 00:00:00 2001 From: "Jill \"oatmealine\" Monoids" Date: Fri, 4 Mar 2022 18:25:42 +0300 Subject: [PATCH] submit chart metadata to backend --- src/ChartCreation.svelte | 61 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 5 deletions(-) diff --git a/src/ChartCreation.svelte b/src/ChartCreation.svelte index 5994ad5..cef8d9b 100644 --- a/src/ChartCreation.svelte +++ b/src/ChartCreation.svelte @@ -2,7 +2,9 @@ import { FormField, TextField, Button, Slider } from 'attractions'; import { onMount } from 'svelte'; import IoMdCheckmark from 'svelte-icons/io/IoMdCheckmark.svelte' + import IoMdAlert from 'svelte-icons/io/IoMdAlert.svelte' import Chart from './Chart.svelte'; + import { currentChartID } from './stores'; const examples = [ ['wouldn\'t make a pipebomb', 'would make a pipebomb', @@ -23,11 +25,35 @@ example = examples[Math.floor(Math.random() * examples.length)]; }); + let error = ''; + + let name = ''; let top = ''; let left = ''; let right = ''; let bot = ''; let fontSize = 12; + + let disableButton = false; + async function trySubmit() { + disableButton = true; + + try { + const response = await fetch('http://localhost:5252/create', { + method: 'POST', + mode: 'cors', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({name, top, left, right, bot}), + }); + + currentChartID.set(await response.text()); + } catch(err) { + disableButton = false; + error = err.toString(); + } + }
@@ -55,20 +90,26 @@

+ + + + - - + + - - + + {value}px + {#if error} +
+
+
+ {error} +
+
+ {/if} +
-