-
Notifications
You must be signed in to change notification settings - Fork 0
/
_Lobby.svelte
89 lines (81 loc) · 1.85 KB
/
_Lobby.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<script>
import { players, isHost, code, nickname } from './_store';
import Loading from '$lib/components/Loading.svelte';
import { send } from '$lib/utils/api.js';
</script>
<h2>Invite</h2>
<div class="code">{`${window.location.origin}/game?code=${$code.toUpperCase()}`}</div>
<button
class="bg-green"
on:click={() => {
navigator.clipboard.writeText(`${window.location.origin}/game?code=${$code.toUpperCase()}`);
}}>Copy game link</button
>
{#if navigator.share}
<button
class="bg-red"
on:click={() => {
navigator.share({
title: 'UNO Game Invite',
url: `${window.location.origin}/game?code=${$code.toUpperCase()}`
})
}}>Share link</button
>
{/if}
<h2 style="m">Players</h2>
<div class="players-list">
{#each $players as player}
<div class="player">
<span>
<b>{player.nickname}</b> {player.nickname === $nickname ? '(You)' : ''} {player.isHost ? '(Host)' : ''}
</span>
{#if $isHost && player.nickname !== $nickname}
<button on:click={() => send('kick', { target: player.nickname })}>Kick</button>
{/if}
</div>
{/each}
</div>
{#if $isHost}
<button
class="bg-yellow"
on:click={async () => {
await send('startGame');
}}>Start game</button
>
{:else}
<span class="dark-block">Wating for host<Loading /></span>
{/if}
<button
class="bg-blue"
style="margin-top: auto"
on:click={async () => {
await send('leave');
}}>Leave room</button
>
<style lang="scss">
.players-list {
display: flex;
flex-direction: column;
gap: 0.3rem;
.player {
display: flex;
justify-content: space-between;
button {
flex: 0;
}
}
}
.code {
font-family: monospace;
background-color: hsl(0, 0%, 40%);
padding: 0.2rem 0.4rem;
border-radius: 0.2rem;
border: 0.2rem solid transparent;
display: flex;
align-items: center;
justify-content: center;
}
h2:not(:first-child) {
margin-top: 1rem;
}
</style>