generateur_v3/frontend/src/routes/room/create/+page.svelte

75 lines
1.6 KiB
Svelte
Raw Normal View History

2023-02-22 12:43:39 +01:00
<script lang="ts">
2023-02-23 17:11:57 +01:00
import { createRoom } from "../../../requests/room.request";
import { getContext } from "svelte";
import { goto } from "$app/navigation";
import InputWithLabel from "../../../components/forms/InputWithLabel.svelte";
2023-02-22 12:43:39 +01:00
2023-02-23 17:11:57 +01:00
let name = "";
let pseudo = "";
const { isAuth } = getContext("auth");
2023-02-26 17:12:10 +01:00
let loading = false;
const { error } = getContext("notif");
2023-02-22 12:43:39 +01:00
</script>
<div class="container">
2023-02-23 17:11:57 +01:00
<div class="form">
<h1>Créer une salle</h1>
<InputWithLabel label="Nom de la salle" bind:value={name} />
{#if !$isAuth}
<InputWithLabel label="Votre pseudo" bind:value={pseudo} />
{/if}
<button
class="primary-btn"
on:click={() => {
2023-02-22 12:43:39 +01:00
console.log('(NAME)', name)
2023-02-26 17:12:10 +01:00
loading = true
2023-02-22 12:43:39 +01:00
createRoom({ name }, !$isAuth ? pseudo : null).then((r) => {
2023-02-26 17:12:10 +01:00
2023-02-22 12:43:39 +01:00
if(!$isAuth){
sessionStorage.setItem('reconnect', r.member)
}
2023-02-26 16:29:05 +01:00
goto(`/room/${r.room}`);
2023-02-26 17:12:10 +01:00
loading= false
}).catch((e) => {
error("Erreur", "Une erreur est survenue lors de la création de la salle")
loading= false
console.log(e);
});
2023-02-22 12:43:39 +01:00
}}
2023-02-23 17:11:57 +01:00
>
2023-02-26 17:12:10 +01:00
{#if loading}
<span class="spinner"></span>
{:else}
Créer
{/if}
2023-02-23 17:11:57 +01:00
</button>
</div>
2023-02-22 12:43:39 +01:00
</div>
<style lang="scss">
h1 {
font-size: 3em;
margin-top: 20px;
}
.form {
display: flex;
flex-direction: column;
align-items: center;
gap: 20px;
2023-02-23 17:11:57 +01:00
width: max-content;
2023-02-22 12:43:39 +01:00
}
2023-02-23 17:11:57 +01:00
.container {
2023-02-22 12:43:39 +01:00
display: flex;
justify-content: center;
}
2023-02-26 17:12:10 +01:00
.spinner {
width: 15px;
height: 15px;
border-width: 2px !important;
}
2023-02-22 12:43:39 +01:00
</style>