|
|
@@ -1,9 +1,34 @@
|
|
|
<script>
|
|
|
+ import {PUBLIC_API_URL} from "$env/static/public";
|
|
|
+ import {toast} from "$lib/toast.svelte.js";
|
|
|
+ import {goto} from "$app/navigation";
|
|
|
+
|
|
|
let title = $state("");
|
|
|
let gameContext = $state("");
|
|
|
|
|
|
const submit = async ()=>{
|
|
|
- console.log("submit");
|
|
|
+ const body = {
|
|
|
+ title: title,
|
|
|
+ game_context: gameContext
|
|
|
+ };
|
|
|
+
|
|
|
+ const response = await fetch(`${PUBLIC_API_URL}/game`, {
|
|
|
+ method: "POST",
|
|
|
+ headers: {"Content-Type": "application/json"},
|
|
|
+ credentials: "include",
|
|
|
+ body: JSON.stringify(body)
|
|
|
+ });
|
|
|
+
|
|
|
+ const data = await response.json();
|
|
|
+ if(!response.ok){
|
|
|
+ toast(data.error.message, "error");
|
|
|
+ if(response.status === 401){
|
|
|
+ goto("/");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ toast("Game created");
|
|
|
+ goto("/game");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
const autofocus = (node)=>{
|
|
|
@@ -24,7 +49,7 @@
|
|
|
<main>
|
|
|
<div class="heading">
|
|
|
<h1>New Adventure</h1>
|
|
|
- <p>Set the stage for your story. You can always change these later.</p>
|
|
|
+ <p>Set the stage for your story</p>
|
|
|
</div>
|
|
|
|
|
|
<form class="standardForm" onsubmit={submit}>
|