feat: sync active room players

This commit is contained in:
metamethods 2025-01-03 01:23:11 -08:00
parent 0a947d8bdd
commit 6a49c361a0

View File

@ -12,6 +12,7 @@
let { room }: { room: Room } = $props(); let { room }: { room: Room } = $props();
let roomTimer = $state(room.secondsRemaining); let roomTimer = $state(room.secondsRemaining);
let players = $state(room.players);
onMount(() => { onMount(() => {
if (!room.finished) { if (!room.finished) {
@ -29,7 +30,9 @@
.get<Room>(`/api/room/${room.roomId}`) .get<Room>(`/api/room/${room.roomId}`)
.then((result) => result.data); .then((result) => result.data);
roomTimer = updatedRoom.secondsRemaining; roomTimer = updatedRoom.secondsRemaining;
players = updatedRoom.players;
if (updatedRoom.finished) { if (updatedRoom.finished) {
console.log('killing invervals');
clearInterval(roomTimerUpdateInterval); clearInterval(roomTimerUpdateInterval);
clearInterval(roomTimerSyncInterval); clearInterval(roomTimerSyncInterval);
} }
@ -69,7 +72,7 @@
</p> </p>
<div class="grid grid-cols-1 gap-4 sm:grid-cols-2 sm:grid-rows-2"> <div class="grid grid-cols-1 gap-4 sm:grid-cols-2 sm:grid-rows-2">
{#each room.players as player} {#each players as player}
<Player {player} /> <Player {player} />
{/each} {/each}
</div> </div>