Felix Zieger
commited on
Commit
·
35af7d4
1
Parent(s):
aeb9637
username validation fix
Browse files
src/components/GameContainer.tsx
CHANGED
@@ -16,6 +16,13 @@ import { supabase } from "@/integrations/supabase/client";
|
|
16 |
|
17 |
type GameState = "welcome" | "theme-selection" | "building-sentence" | "showing-guess";
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
export const GameContainer = () => {
|
20 |
const [gameState, setGameState] = useState<GameState>("welcome");
|
21 |
const [currentWord, setCurrentWord] = useState<string>("");
|
@@ -240,7 +247,7 @@ export const GameContainer = () => {
|
|
240 |
};
|
241 |
|
242 |
const isGuessCorrect = () => {
|
243 |
-
return aiGuess
|
244 |
};
|
245 |
|
246 |
const handleGuessComplete = () => {
|
|
|
16 |
|
17 |
type GameState = "welcome" | "theme-selection" | "building-sentence" | "showing-guess";
|
18 |
|
19 |
+
const normalizeWord = (word: string): string => {
|
20 |
+
return word.normalize('NFD')
|
21 |
+
.replace(/[\u0300-\u036f]/g, '')
|
22 |
+
.toLowerCase()
|
23 |
+
.trim();
|
24 |
+
};
|
25 |
+
|
26 |
export const GameContainer = () => {
|
27 |
const [gameState, setGameState] = useState<GameState>("welcome");
|
28 |
const [currentWord, setCurrentWord] = useState<string>("");
|
|
|
247 |
};
|
248 |
|
249 |
const isGuessCorrect = () => {
|
250 |
+
return normalizeWord(aiGuess) === normalizeWord(currentWord);
|
251 |
};
|
252 |
|
253 |
const handleGuessComplete = () => {
|
src/components/HighScoreBoard.tsx
CHANGED
@@ -75,7 +75,7 @@ export const HighScoreBoard = ({
|
|
75 |
});
|
76 |
|
77 |
const handleSubmitScore = async () => {
|
78 |
-
if (!playerName.trim() || !/^[
|
79 |
toast({
|
80 |
title: t.leaderboard.error.invalidName,
|
81 |
description: t.leaderboard.error.invalidName,
|
|
|
75 |
});
|
76 |
|
77 |
const handleSubmitScore = async () => {
|
78 |
+
if (!playerName.trim() || !/^[a-zA-ZÀ-ÿ0-9-]+$/u.test(playerName.trim())) {
|
79 |
toast({
|
80 |
title: t.leaderboard.error.invalidName,
|
81 |
description: t.leaderboard.error.invalidName,
|
src/components/game/GuessDisplay.tsx
CHANGED
@@ -60,6 +60,10 @@ export const GuessDisplay = ({
|
|
60 |
setHasSubmittedScore(true);
|
61 |
};
|
62 |
|
|
|
|
|
|
|
|
|
63 |
return (
|
64 |
<motion.div
|
65 |
initial={{ opacity: 0 }}
|
@@ -88,7 +92,7 @@ export const GuessDisplay = ({
|
|
88 |
sessionId={sessionId}
|
89 |
currentTheme={currentTheme}
|
90 |
onScoreSubmitted={handleScoreSubmitted}
|
91 |
-
|
92 |
/>
|
93 |
|
94 |
<Dialog open={showHighScores} onOpenChange={setShowHighScores}>
|
|
|
60 |
setHasSubmittedScore(true);
|
61 |
};
|
62 |
|
63 |
+
const handleShowHighScores = () => {
|
64 |
+
setShowHighScores(true);
|
65 |
+
};
|
66 |
+
|
67 |
return (
|
68 |
<motion.div
|
69 |
initial={{ opacity: 0 }}
|
|
|
92 |
sessionId={sessionId}
|
93 |
currentTheme={currentTheme}
|
94 |
onScoreSubmitted={handleScoreSubmitted}
|
95 |
+
onShowHighScores={handleShowHighScores}
|
96 |
/>
|
97 |
|
98 |
<Dialog open={showHighScores} onOpenChange={setShowHighScores}>
|
src/components/game/guess-display/ActionButtons.tsx
CHANGED
@@ -1,8 +1,6 @@
|
|
1 |
import { Button } from "@/components/ui/button";
|
2 |
-
import { Dialog, DialogContent } from "@/components/ui/dialog";
|
3 |
import { useState } from "react";
|
4 |
import { useTranslation } from "@/hooks/useTranslation";
|
5 |
-
import { HighScoreBoard } from "../../HighScoreBoard";
|
6 |
|
7 |
interface ActionButtonsProps {
|
8 |
isCorrect: boolean;
|
@@ -13,64 +11,31 @@ interface ActionButtonsProps {
|
|
13 |
sessionId: string;
|
14 |
currentTheme: string;
|
15 |
onScoreSubmitted?: () => void;
|
16 |
-
|
17 |
}
|
18 |
|
19 |
export const ActionButtons = ({
|
20 |
isCorrect,
|
21 |
onNextRound,
|
22 |
onPlayAgain,
|
23 |
-
|
24 |
-
avgWordsPerRound,
|
25 |
-
sessionId,
|
26 |
-
currentTheme,
|
27 |
-
onScoreSubmitted,
|
28 |
-
onHighScoreDialogChange,
|
29 |
}: ActionButtonsProps) => {
|
30 |
-
const [showHighScores, setShowHighScores] = useState(false);
|
31 |
const t = useTranslation();
|
32 |
|
33 |
-
const handleShowHighScores = () => {
|
34 |
-
setShowHighScores(true);
|
35 |
-
onHighScoreDialogChange?.(true);
|
36 |
-
};
|
37 |
-
|
38 |
-
const handleCloseHighScores = () => {
|
39 |
-
setShowHighScores(false);
|
40 |
-
onHighScoreDialogChange?.(false);
|
41 |
-
};
|
42 |
-
|
43 |
return (
|
44 |
-
|
45 |
-
|
46 |
-
{
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
</div>
|
59 |
-
|
60 |
-
<Dialog open={showHighScores} onOpenChange={handleCloseHighScores}>
|
61 |
-
<DialogContent className="max-h-[90vh] overflow-y-auto sm:max-w-[600px]">
|
62 |
-
<HighScoreBoard
|
63 |
-
currentScore={currentScore}
|
64 |
-
avgWordsPerRound={avgWordsPerRound}
|
65 |
-
onClose={handleCloseHighScores}
|
66 |
-
onPlayAgain={onPlayAgain}
|
67 |
-
sessionId={sessionId}
|
68 |
-
showThemeFilter={false}
|
69 |
-
initialTheme={currentTheme}
|
70 |
-
onScoreSubmitted={onScoreSubmitted}
|
71 |
-
/>
|
72 |
-
</DialogContent>
|
73 |
-
</Dialog>
|
74 |
-
</>
|
75 |
);
|
76 |
};
|
|
|
1 |
import { Button } from "@/components/ui/button";
|
|
|
2 |
import { useState } from "react";
|
3 |
import { useTranslation } from "@/hooks/useTranslation";
|
|
|
4 |
|
5 |
interface ActionButtonsProps {
|
6 |
isCorrect: boolean;
|
|
|
11 |
sessionId: string;
|
12 |
currentTheme: string;
|
13 |
onScoreSubmitted?: () => void;
|
14 |
+
onShowHighScores: () => void;
|
15 |
}
|
16 |
|
17 |
export const ActionButtons = ({
|
18 |
isCorrect,
|
19 |
onNextRound,
|
20 |
onPlayAgain,
|
21 |
+
onShowHighScores,
|
|
|
|
|
|
|
|
|
|
|
22 |
}: ActionButtonsProps) => {
|
|
|
23 |
const t = useTranslation();
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
return (
|
26 |
+
<div className="flex justify-center gap-4">
|
27 |
+
{isCorrect ? (
|
28 |
+
<Button onClick={onNextRound} className="text-white">{t.game.nextRound} ⏎</Button>
|
29 |
+
) : (
|
30 |
+
<>
|
31 |
+
<Button onClick={onPlayAgain} className="text-white">
|
32 |
+
{t.game.playAgain} ⏎
|
33 |
+
</Button>
|
34 |
+
<Button onClick={onShowHighScores} variant="secondary" className="text-white">
|
35 |
+
{t.game.saveScore}
|
36 |
+
</Button>
|
37 |
+
</>
|
38 |
+
)}
|
39 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
);
|
41 |
};
|
src/components/game/leaderboard/ScoreSubmissionForm.tsx
CHANGED
@@ -27,7 +27,7 @@ export const ScoreSubmissionForm = ({
|
|
27 |
placeholder={t.leaderboard.enterName}
|
28 |
value={playerName}
|
29 |
onChange={(e) => {
|
30 |
-
const value = e.target.value.replace(/[^a-zA-ZÀ-ÿ0-9]/g, "");
|
31 |
setPlayerName(value);
|
32 |
}}
|
33 |
onKeyDown={onKeyDown}
|
|
|
27 |
placeholder={t.leaderboard.enterName}
|
28 |
value={playerName}
|
29 |
onChange={(e) => {
|
30 |
+
const value = e.target.value.replace(/[^a-zA-ZÀ-ÿ0-9-]/g, "");
|
31 |
setPlayerName(value);
|
32 |
}}
|
33 |
onKeyDown={onKeyDown}
|