Skip to content

Commit ffb368f

Browse files
committed
add confetti when guess is correct
1 parent c0ead89 commit ffb368f

File tree

5 files changed

+207
-1
lines changed

5 files changed

+207
-1
lines changed

client/src/App.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ p {
9595

9696
#definition {
9797
height: 7em;
98-
font-family:'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
9998
font-weight: 600;
10099
font-size: 1.4em;
101100
padding-left: 2em;

client/src/App.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { useState, useRef, useEffect } from "react";
2+
import { useWindowSize } from "npm:react-use";
3+
import Confetti from "npm:react-confetti";
24

35
import "./App.css";
46
import { is_valid } from "./main.ts";
@@ -7,6 +9,19 @@ import { get_random_term } from "./main.ts";
79
import "animate.css";
810

911

12+
function MyConfetti( { confetti } ) {
13+
const { width, height } = useWindowSize();
14+
if (!confetti)
15+
return <>
16+
</>
17+
18+
return <>
19+
<Confetti key={ confetti } width={ width } height={ height } gravity="0.4" numberOfPieces="100" />
20+
</>
21+
}
22+
23+
24+
1025
function Square( { letter, colors, onSquareClick } ) {
1126
let color = letter.length > 0 && colors != null ? colors[letter.charCodeAt(0) - "A".charCodeAt(0)] : "";
1227
return <button key={letter} className={`square ${color}`} onClick={onSquareClick}>{letter}</ button>;
@@ -107,6 +122,7 @@ function App() {
107122
const [keyboard_colors, setKeyboardColors] = useState(Array(26).fill("square-unattempted"));
108123
const [status, setStatus] = useState('');
109124
const [attempts, setAttempts] = useState([]);
125+
const [confetti, setConfetti] = useState(false);
110126
const letters: string[] = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split("");
111127

112128
function addLetter(letter: string) {
@@ -167,6 +183,9 @@ function App() {
167183

168184
if (attempt.toLowerCase() == term.word) {
169185
if (!success) setScore(score + 100);
186+
187+
setConfetti(true);
188+
setTimeout(() => { setConfetti(false); }, 5000);
170189
setSuccess(true);
171190
setStatusWithTimeout("correct!");
172191
}
@@ -199,6 +218,7 @@ function App() {
199218
setTerm(get_random_term(5));
200219
setAttempt("");
201220
setAttempts([]);
221+
setConfetti(false);
202222
setKeyboardColors(Array(26).fill("square-unattempted"));
203223
}
204224

@@ -229,6 +249,7 @@ function App() {
229249
return (
230250
<>
231251
<div>
252+
<MyConfetti confetti={ confetti } />
232253
<Credits />
233254
<Logo />
234255
<Definition term={ term } />

client/src/index.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
text-rendering: optimizeLegibility;
1010
-webkit-font-smoothing: antialiased;
1111
-moz-osx-font-smoothing: grayscale;
12+
1213
}
1314

1415
a {

deno.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
"@vitejs/plugin-react": "npm:@vitejs/plugin-react@^4.3.3",
1414
"animate.css": "npm:animate.css@^4.1.1",
1515
"react": "npm:react@^18.3.1",
16+
"react-confetti": "npm:react-confetti@^6.4.0",
1617
"react-dom": "npm:react-dom@^18.3.1",
1718
"react-router-dom": "npm:react-router-dom@^6.28.0",
19+
"react-use": "npm:react-use@^17.6.0",
1820
"vite": "npm:vite@^5.4.11"
1921
},
2022
"compilerOptions": {

deno.lock

Lines changed: 183 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)