From 5ee149d5279408c0a0ee3e7e91e88241b2fb17ff Mon Sep 17 00:00:00 2001
From: Mitchell Riedstra <mitch@riedstra.dev>
Date: Tue, 3 Jan 2023 19:29:58 -0500
Subject: Creating new pastes from the UI works. As does the login page.

Still need to redirect to login page automatically.
Also need to show only one of Logout or Login at a time.
---
 ui/src/routes/new/+page.svelte | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

(limited to 'ui/src/routes/new/+page.svelte')

diff --git a/ui/src/routes/new/+page.svelte b/ui/src/routes/new/+page.svelte
index 28687e4..10557af 100644
--- a/ui/src/routes/new/+page.svelte
+++ b/ui/src/routes/new/+page.svelte
@@ -1,5 +1,27 @@
+<script>
+  import { goto } from '$app/navigation';
+  let content = '';
 
+  // $: console.log("Content is: ", content)
 
+  async function save() {
+    const res = await fetch("/api/v1/new", {
+      method: 'POST',
+      body: JSON.stringify({
+        content: content,
+      })
+    })
+
+    const resp = await res.json()
+    console.log(resp)
+
+    if ('Code' in resp && resp.Code === 200) {
+		goto('view/' + resp.Data.Id)
+    }
+
+  }
+
+</script>
 
 
 <div class="content">
@@ -9,11 +31,11 @@
 <label for="content">Content:</label>
 <br />
 <br />
-<textarea name="content" id="content" cols="80" rows="20"></textarea>
+<textarea name="content" id="content" cols="80" rows="20" bind:value={content}></textarea>
 
 <br />
 <br />
-<button type="submit">Save</button>
+<button type="submit" on:click={save}>Save</button>
 
 </div>
 
@@ -41,4 +63,4 @@ textarea {
 }
 
 
-</style>
\ No newline at end of file
+</style>
-- 
cgit v1.2.3

