Kinda working lobbies WIP

This commit is contained in:
2025-09-03 21:07:13 +02:00
parent d32eee314f
commit 81ad47960a
7 changed files with 110 additions and 16 deletions

View File

@@ -0,0 +1,29 @@
import { db } from "$lib/server/db";
import { eq } from "drizzle-orm";
import type { PageServerLoad } from "./$types";
import { lobbysTable } from "$lib/server/db/schema";
import { redirect } from "@sveltejs/kit";
export const load: PageServerLoad = async ({ params, locals }) => {
const id = Number(params.id);
const lobby = await db.query.lobbysTable.findFirst({
with: {
usersInLobby: {
with: {
user: true
}
}
},
where: eq(lobbysTable.id, id)
})
if (!lobby) {
redirect(307, "/error");
}
return {
lobby: lobby,
username: locals.user.username
}
};

View File

@@ -0,0 +1,15 @@
<script lang="ts">
import type { PageProps } from './$types';
let { data }: PageProps = $props();
</script>
<h1>You are in lobby with ID: {data.lobby?.id}</h1>
<h2>Youre username is: {data.username}</h2>
<h2>Players in Lobby: </h2>
<ul>
{#each data.lobby.usersInLobby as player (player.userEmail)}
<li>{player.user.username}</li>
{/each}
</ul>

View File

@@ -0,0 +1,22 @@
import { generateRandomString } from "$lib/server/auth/spotify";
import type { states } from "$lib/server/db/schema";
import { redirect } from "@sveltejs/kit";
import type { PageServerLoad } from "./$types";
import { setContext } from "svelte";
export const load: PageServerLoad = async ({locals, fetch}) => {
const response = await fetch("/api/createLobby", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(locals.user)
});
if (!response.ok) redirect(307, "/error");
const lobby = await response.json();
redirect(307, `/lobby/${lobby.id}`);
};