From f182f16fe8602ae06c00dd62eac48872e66fb5e6 Mon Sep 17 00:00:00 2001 From: Araozu Date: Thu, 16 May 2024 16:15:09 -0500 Subject: [PATCH] Create lobby & redirect --- src/pages/Index.tsx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/pages/Index.tsx b/src/pages/Index.tsx index 6360ab3..abe884b 100644 --- a/src/pages/Index.tsx +++ b/src/pages/Index.tsx @@ -1,4 +1,4 @@ -import { A } from "@solidjs/router"; +import { A, useNavigate } from "@solidjs/router"; import { createSignal, onMount, Show } from "solid-js"; import { backend, UserInfo } from "../utils"; import { Card } from "../components/Card"; @@ -163,14 +163,27 @@ function UserRegistration(props: {setUserInfo: (u: UserInfo) => void}) { function LobbyConnection() { const [loading, setLoading] = createSignal(false); + const [error, setError] = createSignal(""); + const navigate = useNavigate(); const joinLobby = (ev: Event) => { ev.preventDefault(); }; const createLobby = async() => { - // setLoading(true); + + try { + const res = await backend.post<{LobbyId: string}>("/lobby/new"); + console.log(res.data); + // Redirect to the lobby component using the received lobby id + navigate(`/lobby/${res.data.LobbyId}`); + } catch (_e) { + const e: Error = _e as Error; + setError(e.message); + } finally { + setLoading(false); + } }; return ( @@ -209,6 +222,7 @@ function LobbyConnection() { Create a new lobby +

{error()}

); }