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 = '', class: className = '',
roomCode, roomCode,
createRoom, createRoom,
joinRoom joinRoom,
leaveRoom
}: { }: {
roomCode: string; roomCode: string;
createRoom: () => void; createRoom: () => void;
joinRoom: (code: string) => void; joinRoom: (code: string) => void;
leaveRoom: () => void;
class: string; class: string;
} = $props(); } = $props();
</script> </script>
@@ -41,8 +43,8 @@
Create Room Create Room
</button> </button>
{/if} {/if}
<div class="text-center text-lg text-primary-content">OR</div>
{#if !roomCode} {#if !roomCode}
<div class="text-center text-lg text-primary-content">OR</div>
<div class="space-y-2"> <div class="space-y-2">
<input <input
type="text" type="text"
@@ -58,6 +60,12 @@
Join Room Join Room
</button> </button>
</div> </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} {/if}
</div> </div>
</div> </div>

View File

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