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-28 12:30:19 +01:00
|
|
|
<form class="form" on:submit={()=>{
|
|
|
|
|
2023-02-28 10:21:08 +01:00
|
|
|
|
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
|
2023-02-28 10:21:08 +01:00
|
|
|
|
2023-02-26 17:12:10 +01:00
|
|
|
});
|
2023-02-28 12:30:19 +01:00
|
|
|
|
|
|
|
}}>
|
|
|
|
<h1>Créer une salle</h1>
|
2023-02-28 12:35:25 +01:00
|
|
|
<InputWithLabel label="Nom de la salle" bind:value={name} minlength="3" maxlength="20" required/>
|
2023-02-28 12:30:19 +01:00
|
|
|
{#if !$isAuth}
|
2023-02-28 12:35:25 +01:00
|
|
|
<InputWithLabel label="Votre pseudo" bind:value={pseudo} minlength="4" maxlength="15" required/>
|
2023-02-28 12:30:19 +01:00
|
|
|
{/if}
|
|
|
|
<button
|
|
|
|
class="primary-btn"
|
|
|
|
|
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>
|
2023-02-28 12:30:19 +01:00
|
|
|
</form>
|
2023-02-22 12:43:39 +01:00
|
|
|
</div>
|
2023-02-28 20:08:40 +01:00
|
|
|
<svelte:head>
|
|
|
|
<title>Créer une salle</title>
|
|
|
|
</svelte:head>
|
2023-02-22 12:43:39 +01:00
|
|
|
<style lang="scss">
|
|
|
|
h1 {
|
|
|
|
font-size: 3em;
|
|
|
|
margin-top: 20px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.form {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
align-items: center;
|
|
|
|
gap: 20px;
|
2023-02-28 14:00:42 +01:00
|
|
|
width: min(100%, 666px);
|
|
|
|
padding: 7px 20px;
|
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>
|