WIP: remove drizzle completly, add env variable for api URL
This commit is contained in:
@@ -2,38 +2,42 @@ import { redirect } from '@sveltejs/kit';
|
||||
import type { PageServerLoad } from './$types';
|
||||
import type { User } from '../../../app';
|
||||
import type { Settings } from '$lib/types';
|
||||
import { env } from '$env/dynamic/public';
|
||||
|
||||
export const load: PageServerLoad = async ({ params, fetch, locals: { user } }) => {
|
||||
if (!user) {
|
||||
redirect(307, '/');
|
||||
}
|
||||
if (!user) {
|
||||
redirect(307, '/');
|
||||
}
|
||||
|
||||
const response = await fetch(`http://hitstar.xyz/api/lobby/${params.id}`, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
if (!env.PUBLIC_API_BASE) redirect(307, '/error');
|
||||
|
||||
if (response.status != 200) {
|
||||
redirect(307, '/');
|
||||
}
|
||||
const u = new URL(`lobby/${params.id}`, env.PUBLIC_API_BASE);
|
||||
const response = await fetch(u, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
const {
|
||||
id,
|
||||
host,
|
||||
players,
|
||||
gameSettings
|
||||
}: { id: string; host: User; players: User[]; gameSettings: Settings } = await response.json();
|
||||
console.log('Successful request for lobby');
|
||||
console.log(id);
|
||||
if (response.status != 200) {
|
||||
redirect(307, '/');
|
||||
}
|
||||
|
||||
return {
|
||||
user: user,
|
||||
lobby: {
|
||||
id,
|
||||
host,
|
||||
players,
|
||||
gameSettings
|
||||
}
|
||||
};
|
||||
const {
|
||||
id,
|
||||
host,
|
||||
players,
|
||||
gameSettings
|
||||
}: { id: string; host: User; players: User[]; gameSettings: Settings } = await response.json();
|
||||
console.log('Successful request for lobby');
|
||||
console.log(id);
|
||||
|
||||
return {
|
||||
user: user,
|
||||
lobby: {
|
||||
id,
|
||||
host,
|
||||
players,
|
||||
gameSettings
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
import PlayerList from '$lib/components/PlayerList.svelte';
|
||||
import GameSettings from '$lib/components/GameSettings.svelte';
|
||||
import type { PageProps } from './$types';
|
||||
import { env } from '$env/dynamic/public';
|
||||
import { goto } from '$app/navigation';
|
||||
|
||||
// Create WebSocket client
|
||||
|
||||
@@ -12,7 +14,7 @@
|
||||
|
||||
let { data }: PageProps = $props();
|
||||
|
||||
let lobbyCode = $state(data.lobby.id);
|
||||
let lobbyCode = $state(data.lobby.id);
|
||||
let isHost = $state(data.user.email === data.lobby.host.email); // Assume current user is host for this example
|
||||
|
||||
// Available options for settings
|
||||
@@ -84,8 +86,14 @@
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
wsClient.connect(`ws://hitstar.xyz/api/lobby?id=${lobbyCode}`);
|
||||
wsClient.gameSettings = data.lobby.gameSettings
|
||||
if (!env.PUBLIC_API_WS_BASE) {
|
||||
goto('/error');
|
||||
return;
|
||||
}
|
||||
|
||||
const u = new URL(`lobby?id=${lobbyCode}`, env.PUBLIC_API_WS_BASE);
|
||||
wsClient.connect(u.href);
|
||||
wsClient.gameSettings = data.lobby.gameSettings;
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
@@ -130,7 +138,11 @@
|
||||
<!-- Left column: Player list -->
|
||||
<div class="md:col-span-1">
|
||||
{#if wsClient.connected}
|
||||
<PlayerList players={wsClient.players} maxPlayers={wsClient.gameSettings.maxPlayers} host={data.lobby.host} />
|
||||
<PlayerList
|
||||
players={wsClient.players}
|
||||
maxPlayers={wsClient.gameSettings.maxPlayers}
|
||||
host={data.lobby.host}
|
||||
/>
|
||||
{:else}
|
||||
<div class="bg-white rounded-lg shadow-sm p-5 flex items-center justify-center">
|
||||
<div class="flex items-center text-amber-600">
|
||||
|
||||
Reference in New Issue
Block a user