|
1 | | -<!-- @migration-task Error while migrating Svelte code: can't migrate `let confetti = false;` to `$state` because there's a variable named state. |
2 | | - Rename the variable and try again or migrate by hand. --> |
3 | 1 | <script lang="ts"> |
4 | 2 | import { page } from "$app/state"; |
5 | 3 | import { io, type Socket } from "socket.io-client"; |
|
24 | 22 | import LoaderCircle from "@lucide/svelte/icons/loader-circle"; |
25 | 23 |
|
26 | 24 | import { Confetti } from "svelte-confetti"; |
27 | | - let confetti = false; |
| 25 | + let confetti = $state(false); |
28 | 26 |
|
29 | 27 | import DOMPurify from "dompurify"; |
30 | 28 |
|
31 | 29 | const roomId = page.params.id; |
32 | 30 |
|
33 | | - let state: State = "connecting"; |
| 31 | + let gameState: State = $state("connecting"); |
34 | 32 |
|
35 | | - let name: string = ""; |
| 33 | + let name: string = $state(""); |
36 | 34 |
|
37 | 35 | import { toast } from "svelte-sonner"; |
38 | 36 | import type { z } from "zod"; |
|
43 | 41 | toast[type](message); |
44 | 42 | }); |
45 | 43 | socket.on("connect", () => { |
46 | | - if (state === "connecting") state = "choose-name"; |
| 44 | + if (gameState === "connecting") gameState = "choose-name"; |
47 | 45 | toast.success("Connected!"); |
48 | 46 | }); |
49 | 47 | socket.on("connect_error", () => toast.error("Failed to connect! Does this room exist?")); |
50 | 48 | socket.on("disconnect", () => toast.warning("Disconnected!")); |
51 | 49 |
|
52 | | - socket.on("lobby", () => (state = "waiting_start")); |
| 50 | + socket.on("lobby", () => (gameState = "waiting_start")); |
53 | 51 |
|
54 | | - let answer: z.infer<typeof Question>["data"]["solutions"][number] | null = null; |
| 52 | + let answer: z.infer<typeof Question>["data"]["solutions"][number] | null = $state(null); |
55 | 53 |
|
56 | | - let running: number | false = false; |
57 | | - let runningVisible = 0; |
| 54 | + let running: number | false = $state(false); |
| 55 | + let runningVisible = $state(0); |
58 | 56 | let currentQuestion: { |
59 | 57 | number: number; |
60 | 58 | content: string; |
61 | 59 | type: z.infer<typeof Question>["type"]; |
62 | | - } = { |
| 60 | + } = $state({ |
63 | 61 | number: 0, |
64 | 62 | content: "<p>Loading...</p>", |
65 | 63 | type: "text" |
66 | | - }; |
| 64 | + }); |
67 | 65 | let startingTime: number | null = null; |
68 | | - let timePassed = 0; |
| 66 | + let timePassed = $state(0); |
69 | 67 | setInterval(() => { |
70 | 68 | if (!startingTime) timePassed = 0; |
71 | 69 | else timePassed = Date.now() - startingTime; |
72 | 70 | }, 100); |
73 | 71 | socket.on("gameStart", () => { |
74 | | - state = "started"; |
| 72 | + gameState = "started"; |
75 | 73 | startingTime = Date.now(); |
76 | 74 | }); |
77 | 75 | socket.on("gameFinish", () => { |
78 | | - state = "finished"; |
| 76 | + gameState = "finished"; |
79 | 77 | }); |
80 | 78 | socket.on("confetti", () => (confetti = true)); |
81 | 79 | socket.on("newQuestion", (content, type) => { |
|
95 | 93 | }); |
96 | 94 | }); |
97 | 95 | socket.on("stopRunning", () => (running = false)); |
98 | | - let questionCount = 1; |
| 96 | + let questionCount = $state(1); |
99 | 97 | socket.on("questionCount", (data) => (questionCount = data)); |
100 | 98 | </script> |
101 | 99 |
|
102 | | -{#if state === "connecting"} |
| 100 | +{#if gameState === "connecting"} |
103 | 101 | <span class="animate-pulse font-bold text-5xl flex text-center items-center w-full h-full justify-center" |
104 | 102 | >Connecting...</span |
105 | 103 | > |
106 | | -{:else if state === "choose-name"} |
| 104 | +{:else if gameState === "choose-name"} |
107 | 105 | <div class="w-full h-full flex justify-center items-center align-middle text-center"> |
108 | 106 | <div class="flex flex-col rounded bg-white text-slate-900 w-min text-center p-2"> |
109 | 107 | {#if name} |
|
117 | 115 | <Button class="mt-2" onclick={() => socket.emit("join", name)}>Join</Button> |
118 | 116 | </div> |
119 | 117 | </div> |
120 | | -{:else if state === "waiting_start"} |
| 118 | +{:else if gameState === "waiting_start"} |
121 | 119 | <span class="animate-pulse font-bold text-4xl flex text-center items-center w-full h-full justify-center" |
122 | 120 | >Waiting for game to start...</span |
123 | 121 | > |
124 | | -{:else if state === "started"} |
| 122 | +{:else if gameState === "started"} |
125 | 123 | <div class="p-3 bg-white text-slate-900 rounded mb-2 flex items-center"> |
126 | 124 | <div class="text-3xl text-center">{msToMinutesAndSeconds(timePassed)}</div> |
127 | 125 | </div> |
|
156 | 154 | > |
157 | 155 | </div> |
158 | 156 | {/if} |
159 | | -{:else if state === "finished"} |
| 157 | +{:else if gameState === "finished"} |
160 | 158 | <div class="rounded p-2 bg-white text-slate-900"> |
161 | 159 | <Header size="h1">Game finished!</Header> |
162 | 160 | <p>The host may communicate more information to you via alerts. They will appear at the bottom right.</p> |
|
0 commit comments