enzostvs HF staff commited on
Commit
23efa9a
·
1 Parent(s): b2c00a3

manually redirection when game is lost

Browse files
components/quizz/card/index.tsx CHANGED
@@ -33,6 +33,7 @@ export const Card: React.FC<Props> = ({ prompt, onScore }) => {
33
  {result?.success && result?.id === prompt.id && (
34
  <Confetti
35
  height={340}
 
36
  numberOfPieces={100}
37
  className="w-full lg:w-[340px] h-full"
38
  />
 
33
  {result?.success && result?.id === prompt.id && (
34
  <Confetti
35
  height={340}
36
+ width={340}
37
  numberOfPieces={100}
38
  className="w-full lg:w-[340px] h-full"
39
  />
components/quizz/hooks/useQuizz.ts CHANGED
@@ -52,11 +52,9 @@ export const useQuizz = () => {
52
 
53
  setResult(response.ok ? id : response.resultId, response?.ok);
54
  await sleep(response.ok ? 2000 : 3000);
55
- setResult(null);
56
  if (response?.ok) {
 
57
  client.invalidateQueries(['quizz']);
58
- } else {
59
- return router.push('/results');
60
  }
61
  };
62
 
 
52
 
53
  setResult(response.ok ? id : response.resultId, response?.ok);
54
  await sleep(response.ok ? 2000 : 3000);
 
55
  if (response?.ok) {
56
+ setResult(null);
57
  client.invalidateQueries(['quizz']);
 
 
58
  }
59
  };
60
 
components/quizz/index.tsx CHANGED
@@ -6,9 +6,11 @@ import { RxLapTimer } from "react-icons/rx";
6
  import { useQuizz } from "./hooks/useQuizz";
7
  import { PromptType } from "@/utils/type";
8
  import { Card } from "./card";
 
 
9
 
10
  export const QuizzContent = () => {
11
- const { loading, prompts, question, onScore } = useQuizz();
12
  const [counter, setCounter] = useState(10);
13
  const [isRunning, toggleIsRunning] = useBoolean(true);
14
 
@@ -74,6 +76,11 @@ export const QuizzContent = () => {
74
  ))}
75
  </div>
76
  </div>
 
 
 
 
 
77
  </div>
78
  );
79
  };
 
6
  import { useQuizz } from "./hooks/useQuizz";
7
  import { PromptType } from "@/utils/type";
8
  import { Card } from "./card";
9
+ import { Button } from "../button/button";
10
+ import Link from "next/link";
11
 
12
  export const QuizzContent = () => {
13
+ const { loading, prompts, question, onScore, result } = useQuizz();
14
  const [counter, setCounter] = useState(10);
15
  const [isRunning, toggleIsRunning] = useBoolean(true);
16
 
 
76
  ))}
77
  </div>
78
  </div>
79
+ {result && !result?.success && (
80
+ <Link href="/results">
81
+ <Button>Go to results</Button>
82
+ </Link>
83
+ )}
84
  </div>
85
  );
86
  };
components/results/index.tsx CHANGED
@@ -22,70 +22,21 @@ export const Results = () => {
22
 
23
  const renderTitle = (score: number) => {
24
  if (score < 2) {
25
- return (
26
- <>
27
- You can do <br />
28
- <span className="bg-gradient-to-tr from-green to-cyan bg-clip-text">
29
- better
30
- </span>{" "}
31
- ! <span className="text-white">💪</span>
32
- </>
33
- );
34
  }
35
  if (score < 5) {
36
- return (
37
- <>
38
- Not bad! <br />
39
- <span className="bg-gradient-to-tr from-green to-cyan bg-clip-text">
40
- Keep going
41
- </span>{" "}
42
- ! <span className="text-white">🤗</span>
43
- </>
44
- );
45
  }
46
  if (score < 11) {
47
- return (
48
- <>
49
- You are <br />
50
- <span className="bg-gradient-to-tr from-green to-cyan bg-clip-text">
51
- good
52
- </span>{" "}
53
- ! <span className="text-white">🙂</span>
54
- </>
55
- );
56
  }
57
  if (score < 16) {
58
- return (
59
- <>
60
- You are <br />
61
- <span className="bg-gradient-to-tr from-green to-cyan bg-clip-text">
62
- amazing
63
- </span>{" "}
64
- ! <span className="text-white">🥳</span>
65
- </>
66
- );
67
  }
68
  if (score < 20) {
69
- return (
70
- <>
71
- You are <br />
72
- <span className="bg-gradient-to-tr from-green to-cyan bg-clip-text">
73
- incredible
74
- </span>{" "}
75
- ! <span className="text-white">🤯</span>
76
- </>
77
- );
78
  }
79
- return (
80
- <>
81
- Congrats! <br />
82
- You{" "}
83
- <span className="bg-gradient-to-tr from-green to-cyan bg-clip-text">
84
- killed
85
- </span>{" "}
86
- it! 🎉
87
- </>
88
- );
89
  };
90
 
91
  return (
@@ -99,7 +50,11 @@ export const Results = () => {
99
  alt="Sparkling effect"
100
  className="absolute top-8 left-0"
101
  />
102
- {renderTitle(score)}
 
 
 
 
103
  <Image
104
  src={SparklingEffect2}
105
  width={30}
@@ -110,11 +65,7 @@ export const Results = () => {
110
  </h1>
111
  <div className="w-full grid grid-cols-1 gap-2">
112
  <h2 className="text-white text-2xl md:text-4xl text-center font-semibold">
113
- You obtained{" "}
114
- <span className="bg-gradient-to-tr from-green to-cyan bg-clip-text font-bold text-transparent">
115
- {score} point{score > 1 ? "s" : ""}
116
- </span>{" "}
117
- !
118
  </h2>
119
  <p className="text-white text-xl md:text-2xl text-center font-light">
120
  Share your score with your friends and challenge them!
 
22
 
23
  const renderTitle = (score: number) => {
24
  if (score < 2) {
25
+ return <>You can do better! 💪</>;
 
 
 
 
 
 
 
 
26
  }
27
  if (score < 5) {
28
+ return <>Not bad! Keep going! 🤗</>;
 
 
 
 
 
 
 
 
29
  }
30
  if (score < 11) {
31
+ return <>You are good! 🙂</>;
 
 
 
 
 
 
 
 
32
  }
33
  if (score < 16) {
34
+ return <>You are amazing! 🥳</>;
 
 
 
 
 
 
 
 
35
  }
36
  if (score < 20) {
37
+ return <>You are incredible! 🤯</>;
 
 
 
 
 
 
 
 
38
  }
39
+ return <>Congrats! You killed it! 🎉</>;
 
 
 
 
 
 
 
 
 
40
  };
41
 
42
  return (
 
50
  alt="Sparkling effect"
51
  className="absolute top-8 left-0"
52
  />
53
+ You obtained <br />
54
+ <span className="bg-gradient-to-tr from-green to-cyan bg-clip-text font-bold text-transparent">
55
+ {score} point{score > 1 ? "s" : ""}
56
+ </span>{" "}
57
+ !
58
  <Image
59
  src={SparklingEffect2}
60
  width={30}
 
65
  </h1>
66
  <div className="w-full grid grid-cols-1 gap-2">
67
  <h2 className="text-white text-2xl md:text-4xl text-center font-semibold">
68
+ {renderTitle(score)}
 
 
 
 
69
  </h2>
70
  <p className="text-white text-xl md:text-2xl text-center font-light">
71
  Share your score with your friends and challenge them!