Create lobby & redirect
This commit is contained in:
parent
b0b14bc559
commit
f182f16fe8
@ -1,4 +1,4 @@
|
|||||||
import { A } from "@solidjs/router";
|
import { A, useNavigate } from "@solidjs/router";
|
||||||
import { createSignal, onMount, Show } from "solid-js";
|
import { createSignal, onMount, Show } from "solid-js";
|
||||||
import { backend, UserInfo } from "../utils";
|
import { backend, UserInfo } from "../utils";
|
||||||
import { Card } from "../components/Card";
|
import { Card } from "../components/Card";
|
||||||
@ -163,14 +163,27 @@ function UserRegistration(props: {setUserInfo: (u: UserInfo) => void}) {
|
|||||||
|
|
||||||
function LobbyConnection() {
|
function LobbyConnection() {
|
||||||
const [loading, setLoading] = createSignal(false);
|
const [loading, setLoading] = createSignal(false);
|
||||||
|
const [error, setError] = createSignal("");
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const joinLobby = (ev: Event) => {
|
const joinLobby = (ev: Event) => {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
};
|
};
|
||||||
|
|
||||||
const createLobby = async() => {
|
const createLobby = async() => {
|
||||||
//
|
|
||||||
setLoading(true);
|
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 (
|
return (
|
||||||
@ -209,6 +222,7 @@ function LobbyConnection() {
|
|||||||
Create a new lobby
|
Create a new lobby
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
<p>{error()}</p>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user