feat(join): add leave room button when there is no opponent yet

This commit is contained in:
Yael Arturo Chavoya Andalón
2024-09-30 16:36:04 -06:00
committed by Sparsh Goenka
parent e285fa4801
commit 0b5f513520
2 changed files with 17 additions and 6 deletions

View File

@@ -7,11 +7,13 @@
class: className = '',
roomCode,
createRoom,
joinRoom
joinRoom,
leaveRoom
}: {
roomCode: string;
createRoom: () => void;
joinRoom: (code: string) => void;
leaveRoom: () => void;
class: string;
} = $props();
</script>
@@ -41,8 +43,8 @@
Create Room
</button>
{/if}
{#if !roomCode}
<div class="text-center text-lg text-primary-content">OR</div>
{#if !roomCode}
<div class="space-y-2">
<input
type="text"
@@ -58,6 +60,12 @@
Join Room
</button>
</div>
{:else}
<div class="space-x-2 flex flex-row justify-center items-center">
<button class="btn btn-error text-2xl" onclick={leaveRoom}>
Leave room
</button>
</div>
{/if}
</div>
</div>

View File

@@ -6,6 +6,11 @@
import { Users } from 'lucide-svelte';
let gameState = new State();
function leaveRoom() {
gameState.socket.emit('leave');
gameState = new State();
}
</script>
<div class="min-h-screen bg-base-300 py-8 px-4 sm:px-6 lg:px-8">
@@ -40,10 +45,7 @@
</div>
<button
class="btn btn-error text-xl"
onclick={() => {
gameState.socket.emit('leave');
gameState = new State();
}}>Leave</button
onclick={leaveRoom}>Leave</button
>
</div>
{/if}
@@ -73,6 +75,7 @@
roomCode={gameState.room}
createRoom={() => gameState.createRoom()}
joinRoom={(code) => gameState.joinRoom(code)}
leaveRoom={leaveRoom}
/>
{/if}
</div>