Felix Zieger commited on
Commit
5cd06ed
·
1 Parent(s): 6864389

navigation

Browse files
src/components/GameContainer.tsx CHANGED
@@ -235,6 +235,7 @@ export const GameContainer = () => {
235
  currentScore={successfulRounds}
236
  avgWordsPerRound={getAverageWordsPerRound()}
237
  sessionId={sessionId}
 
238
  />
239
  )}
240
  </motion.div>
 
235
  currentScore={successfulRounds}
236
  avgWordsPerRound={getAverageWordsPerRound()}
237
  sessionId={sessionId}
238
+ onBack={handleBack}
239
  />
240
  )}
241
  </motion.div>
src/components/game/GuessDisplay.tsx CHANGED
@@ -1,5 +1,5 @@
1
  import { motion } from "framer-motion";
2
- import { useState } from "react";
3
  import { useTranslation } from "@/hooks/useTranslation";
4
  import { Button } from "@/components/ui/button";
5
  import {
@@ -40,6 +40,18 @@ export const GuessDisplay = ({
40
  const [showConfirmDialog, setShowConfirmDialog] = useState(false);
41
  const [hasSubmittedScore, setHasSubmittedScore] = useState(false);
42
  const t = useTranslation();
 
 
 
 
 
 
 
 
 
 
 
 
43
  const isGuessCorrect = () => aiGuess.toLowerCase() === currentWord.toLowerCase();
44
 
45
  const handleScoreSubmitted = () => {
@@ -55,9 +67,9 @@ export const GuessDisplay = ({
55
  >
56
  <RoundHeader
57
  successfulRounds={currentScore}
58
- goToWelcomeScreen={onBack}
59
  showConfirmDialog={showConfirmDialog}
60
- setShowConfirmDialog={setShowConfirmDialog}
61
  />
62
 
63
  <WordDisplay currentWord={currentWord} />
 
1
  import { motion } from "framer-motion";
2
+ import { useState, useEffect } from "react";
3
  import { useTranslation } from "@/hooks/useTranslation";
4
  import { Button } from "@/components/ui/button";
5
  import {
 
40
  const [showConfirmDialog, setShowConfirmDialog] = useState(false);
41
  const [hasSubmittedScore, setHasSubmittedScore] = useState(false);
42
  const t = useTranslation();
43
+
44
+ console.log("GuessDisplay - Rendering with showConfirmDialog:", showConfirmDialog);
45
+
46
+ const handleSetShowConfirmDialog = (show: boolean) => {
47
+ console.log("GuessDisplay - Setting showConfirmDialog to:", show);
48
+ setShowConfirmDialog(show);
49
+ };
50
+
51
+ useEffect(() => {
52
+ console.log("GuessDisplay - showConfirmDialog changed to:", showConfirmDialog);
53
+ }, [showConfirmDialog]);
54
+
55
  const isGuessCorrect = () => aiGuess.toLowerCase() === currentWord.toLowerCase();
56
 
57
  const handleScoreSubmitted = () => {
 
67
  >
68
  <RoundHeader
69
  successfulRounds={currentScore}
70
+ onBack={onBack}
71
  showConfirmDialog={showConfirmDialog}
72
+ setShowConfirmDialog={handleSetShowConfirmDialog}
73
  />
74
 
75
  <WordDisplay currentWord={currentWord} />
src/components/game/SentenceBuilder.tsx CHANGED
@@ -44,7 +44,8 @@ export const SentenceBuilder = ({
44
  const [containsTargetWord, setContainsTargetWord] = useState(false);
45
  const t = useTranslation();
46
 
47
- // Input validation
 
48
  const validateInput = (input: string) => {
49
  setHasMultipleWords(input.trim().split(/\s+/).length > 1);
50
  setContainsTargetWord(
@@ -57,6 +58,11 @@ export const SentenceBuilder = ({
57
  onInputChange(value);
58
  };
59
 
 
 
 
 
 
60
  const isValidInput = !playerInput || /^[\p{L} ]+$/u.test(playerInput);
61
 
62
  return (
@@ -67,9 +73,9 @@ export const SentenceBuilder = ({
67
  >
68
  <RoundHeader
69
  successfulRounds={successfulRounds}
70
- goToWelcomeScreen={onBack}
71
  showConfirmDialog={showConfirmDialog}
72
- setShowConfirmDialog={setShowConfirmDialog}
73
  />
74
 
75
  <WordDisplay currentWord={currentWord} />
@@ -88,7 +94,7 @@ export const SentenceBuilder = ({
88
  sentence={sentence}
89
  />
90
 
91
- <AlertDialog open={showConfirmDialog} onOpenChange={setShowConfirmDialog}>
92
  <AlertDialogContent>
93
  <AlertDialogHeader>
94
  <AlertDialogTitle>{t.game.leaveGameTitle}</AlertDialogTitle>
 
44
  const [containsTargetWord, setContainsTargetWord] = useState(false);
45
  const t = useTranslation();
46
 
47
+ console.log("SentenceBuilder - Rendering with showConfirmDialog:", showConfirmDialog);
48
+
49
  const validateInput = (input: string) => {
50
  setHasMultipleWords(input.trim().split(/\s+/).length > 1);
51
  setContainsTargetWord(
 
58
  onInputChange(value);
59
  };
60
 
61
+ const handleSetShowConfirmDialog = (show: boolean) => {
62
+ console.log("SentenceBuilder - Setting showConfirmDialog to:", show);
63
+ setShowConfirmDialog(show);
64
+ };
65
+
66
  const isValidInput = !playerInput || /^[\p{L} ]+$/u.test(playerInput);
67
 
68
  return (
 
73
  >
74
  <RoundHeader
75
  successfulRounds={successfulRounds}
76
+ onBack={onBack}
77
  showConfirmDialog={showConfirmDialog}
78
+ setShowConfirmDialog={handleSetShowConfirmDialog}
79
  />
80
 
81
  <WordDisplay currentWord={currentWord} />
 
94
  sentence={sentence}
95
  />
96
 
97
+ <AlertDialog open={showConfirmDialog} onOpenChange={handleSetShowConfirmDialog}>
98
  <AlertDialogContent>
99
  <AlertDialogHeader>
100
  <AlertDialogTitle>{t.game.leaveGameTitle}</AlertDialogTitle>
src/components/game/guess-display/GuessDescription.tsx CHANGED
@@ -7,7 +7,6 @@ interface GuessDescriptionProps {
7
 
8
  export const GuessDescription = ({ sentence, aiGuess }: GuessDescriptionProps) => {
9
  const t = useTranslation();
10
- const isCheating = () => aiGuess === 'CHEATING';
11
 
12
  return (
13
  <div className="space-y-2">
@@ -17,10 +16,6 @@ export const GuessDescription = ({ sentence, aiGuess }: GuessDescriptionProps) =
17
  {sentence.join(" ")}
18
  </p>
19
  </div>
20
-
21
- <p className="text-sm text-gray-600">
22
- {isCheating() ? t.guess.cheatingDetected : t.guess.aiGuessedDescription}
23
- </p>
24
  </div>
25
  );
26
  };
 
7
 
8
  export const GuessDescription = ({ sentence, aiGuess }: GuessDescriptionProps) => {
9
  const t = useTranslation();
 
10
 
11
  return (
12
  <div className="space-y-2">
 
16
  {sentence.join(" ")}
17
  </p>
18
  </div>
 
 
 
 
19
  </div>
20
  );
21
  };
src/components/game/guess-display/GuessResult.tsx CHANGED
@@ -1,14 +1,23 @@
 
 
1
  interface GuessResultProps {
2
  aiGuess: string;
3
  isCorrect: boolean;
4
  }
5
 
6
  export const GuessResult = ({ aiGuess, isCorrect }: GuessResultProps) => {
 
 
7
  return (
8
- <div className={`rounded-lg ${isCorrect ? 'bg-green-50' : 'bg-red-50'}`}>
9
- <p className={`p-4 text-2xl font-bold tracking-wider ${isCorrect ? 'text-green-600' : 'text-red-600'}`}>
10
- {aiGuess}
11
- </p>
 
 
 
 
 
12
  </div>
13
  );
14
  };
 
1
+ import { useTranslation } from "@/hooks/useTranslation";
2
+
3
  interface GuessResultProps {
4
  aiGuess: string;
5
  isCorrect: boolean;
6
  }
7
 
8
  export const GuessResult = ({ aiGuess, isCorrect }: GuessResultProps) => {
9
+ const t = useTranslation();
10
+
11
  return (
12
+ <div className="space-y-2">
13
+ <p className="text-sm text-gray-600">
14
+ {t.guess.aiGuessedDescription}
15
+ </p>
16
+ <div className={`rounded-lg ${isCorrect ? 'bg-green-50' : 'bg-red-50'}`}>
17
+ <p className={`p-4 text-2xl font-bold tracking-wider ${isCorrect ? 'text-green-600' : 'text-red-600'}`}>
18
+ {aiGuess}
19
+ </p>
20
+ </div>
21
  </div>
22
  );
23
  };
src/components/game/sentence-builder/RoundHeader.tsx CHANGED
@@ -1,27 +1,49 @@
1
  import { House } from "lucide-react";
2
  import { Button } from "@/components/ui/button";
3
  import { useTranslation } from "@/hooks/useTranslation";
 
 
 
 
 
 
 
 
 
 
4
 
5
  interface RoundHeaderProps {
6
  successfulRounds: number;
7
- goToWelcomeScreen?: () => void;
8
  showConfirmDialog: boolean;
9
  setShowConfirmDialog: (show: boolean) => void;
10
  }
11
 
12
  export const RoundHeader = ({
13
  successfulRounds,
14
- goToWelcomeScreen,
15
  showConfirmDialog,
16
  setShowConfirmDialog
17
  }: RoundHeaderProps) => {
18
  const t = useTranslation();
19
-
20
  const handleHomeClick = () => {
 
21
  if (successfulRounds > 0) {
 
22
  setShowConfirmDialog(true);
23
  } else {
24
- goToWelcomeScreen?.();
 
 
 
 
 
 
 
 
 
 
25
  }
26
  };
27
 
@@ -43,8 +65,23 @@ export const RoundHeader = ({
43
  </Button>
44
 
45
  <h2 className="mb-4 text-2xl font-semibold text-gray-900">
46
- Think in Sync
47
  </h2>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  </div>
49
  );
50
  };
 
1
  import { House } from "lucide-react";
2
  import { Button } from "@/components/ui/button";
3
  import { useTranslation } from "@/hooks/useTranslation";
4
+ import {
5
+ AlertDialog,
6
+ AlertDialogAction,
7
+ AlertDialogCancel,
8
+ AlertDialogContent,
9
+ AlertDialogDescription,
10
+ AlertDialogFooter,
11
+ AlertDialogHeader,
12
+ AlertDialogTitle,
13
+ } from "@/components/ui/alert-dialog";
14
 
15
  interface RoundHeaderProps {
16
  successfulRounds: number;
17
+ onBack?: () => void;
18
  showConfirmDialog: boolean;
19
  setShowConfirmDialog: (show: boolean) => void;
20
  }
21
 
22
  export const RoundHeader = ({
23
  successfulRounds,
24
+ onBack,
25
  showConfirmDialog,
26
  setShowConfirmDialog
27
  }: RoundHeaderProps) => {
28
  const t = useTranslation();
29
+
30
  const handleHomeClick = () => {
31
+ console.log("RoundHeader - Home button clicked, successful rounds:", successfulRounds);
32
  if (successfulRounds > 0) {
33
+ console.log("RoundHeader - Setting showConfirmDialog to true");
34
  setShowConfirmDialog(true);
35
  } else {
36
+ console.log("RoundHeader - No successful rounds, navigating directly");
37
+ onBack?.();
38
+ }
39
+ };
40
+
41
+ const handleDialogChange = (open: boolean) => {
42
+ console.log("RoundHeader - Dialog state changing to:", open);
43
+ setShowConfirmDialog(open);
44
+ if (!open) { // Dialog is closing
45
+ console.log("RoundHeader - Dialog closing, triggering navigation");
46
+ onBack?.();
47
  }
48
  };
49
 
 
65
  </Button>
66
 
67
  <h2 className="mb-4 text-2xl font-semibold text-gray-900">
68
+ {t.game.title}
69
  </h2>
70
+
71
+ <AlertDialog open={showConfirmDialog} onOpenChange={handleDialogChange}>
72
+ <AlertDialogContent>
73
+ <AlertDialogHeader>
74
+ <AlertDialogTitle>{t.game.leaveGameTitle}</AlertDialogTitle>
75
+ <AlertDialogDescription>
76
+ {t.game.leaveGameDescription}
77
+ </AlertDialogDescription>
78
+ </AlertDialogHeader>
79
+ <AlertDialogFooter>
80
+ <AlertDialogCancel>{t.game.cancel}</AlertDialogCancel>
81
+ <AlertDialogAction>{t.game.confirm}</AlertDialogAction>
82
+ </AlertDialogFooter>
83
+ </AlertDialogContent>
84
+ </AlertDialog>
85
  </div>
86
  );
87
  };
src/i18n/translations/de.ts CHANGED
@@ -1,5 +1,6 @@
1
  export const de = {
2
  game: {
 
3
  round: "Runde",
4
  buildDescription: "Baut gemeinsam einen Satz",
5
  buildSubtitle: "Fügt abwechselnd Wörter hinzu, um einen Satz zu bilden",
 
1
  export const de = {
2
  game: {
3
+ title: "Think in Sync",
4
  round: "Runde",
5
  buildDescription: "Baut gemeinsam einen Satz",
6
  buildSubtitle: "Fügt abwechselnd Wörter hinzu, um einen Satz zu bilden",
src/i18n/translations/en.ts CHANGED
@@ -1,5 +1,6 @@
1
  export const en = {
2
  game: {
 
3
  round: "Round",
4
  buildDescription: "Build a sentence together",
5
  buildSubtitle: "Take turns adding words to create a sentence",
@@ -98,4 +99,4 @@ export const en = {
98
  ]
99
  }
100
  }
101
- };
 
1
  export const en = {
2
  game: {
3
+ title: "Think in Sync",
4
  round: "Round",
5
  buildDescription: "Build a sentence together",
6
  buildSubtitle: "Take turns adding words to create a sentence",
 
99
  ]
100
  }
101
  }
102
+ };
src/i18n/translations/es.ts CHANGED
@@ -1,5 +1,6 @@
1
  export const es = {
2
  game: {
 
3
  round: "Ronda",
4
  buildDescription: "Construyan una frase juntos",
5
  buildSubtitle: "Añadan palabras por turnos para crear una frase",
@@ -98,4 +99,4 @@ export const es = {
98
  ]
99
  }
100
  }
101
- };
 
1
  export const es = {
2
  game: {
3
+ title: "Think in Sync",
4
  round: "Ronda",
5
  buildDescription: "Construyan una frase juntos",
6
  buildSubtitle: "Añadan palabras por turnos para crear una frase",
 
99
  ]
100
  }
101
  }
102
+ };
src/i18n/translations/fr.ts CHANGED
@@ -1,5 +1,6 @@
1
  export const fr = {
2
  game: {
 
3
  round: "Tour",
4
  buildDescription: "Construisez une phrase ensemble",
5
  startSentence: "Commencez à construire votre phrase...",
 
1
  export const fr = {
2
  game: {
3
+ title: "Think in Sync",
4
  round: "Tour",
5
  buildDescription: "Construisez une phrase ensemble",
6
  startSentence: "Commencez à construire votre phrase...",
src/i18n/translations/it.ts CHANGED
@@ -1,5 +1,6 @@
1
  export const it = {
2
  game: {
 
3
  round: "Turno",
4
  buildDescription: "Costruite una frase insieme",
5
  buildSubtitle: "Aggiungete parole a turno per creare una frase",
 
1
  export const it = {
2
  game: {
3
+ title: "Think in Sync",
4
  round: "Turno",
5
  buildDescription: "Costruite una frase insieme",
6
  buildSubtitle: "Aggiungete parole a turno per creare una frase",