Spaces:
Running
Running
remove data
Browse files- .gitignore +1 -1
- components/quizz/card/index.tsx +2 -4
- components/quizz/hooks/useQuizz.ts +7 -2
- components/results/index.tsx +30 -10
- data/dev.db +0 -0
.gitignore
CHANGED
@@ -12,7 +12,7 @@
|
|
12 |
# next.js
|
13 |
/.next/
|
14 |
/out/
|
15 |
-
|
16 |
# production
|
17 |
/build
|
18 |
|
|
|
12 |
# next.js
|
13 |
/.next/
|
14 |
/out/
|
15 |
+
/data/*
|
16 |
# production
|
17 |
/build
|
18 |
|
components/quizz/card/index.tsx
CHANGED
@@ -21,12 +21,10 @@ export const Card: React.FC<Props> = ({ prompt }) => {
|
|
21 |
className={classNames(
|
22 |
"w-[340px] h-[340px] p-5 relative z-[1] cursor-pointer group",
|
23 |
{
|
24 |
-
"!cursor-not-allowed": result
|
25 |
}
|
26 |
)}
|
27 |
-
onClick={
|
28 |
-
result?.success ? () => {} : async () => await onScore(prompt.id)
|
29 |
-
}
|
30 |
>
|
31 |
<Success result={result} prompt={prompt} />
|
32 |
<Error result={result} prompt={prompt} />
|
|
|
21 |
className={classNames(
|
22 |
"w-[340px] h-[340px] p-5 relative z-[1] cursor-pointer group",
|
23 |
{
|
24 |
+
"!cursor-not-allowed": result,
|
25 |
}
|
26 |
)}
|
27 |
+
onClick={result ? () => {} : async () => await onScore(prompt.id)}
|
|
|
|
|
28 |
>
|
29 |
<Success result={result} prompt={prompt} />
|
30 |
<Error result={result} prompt={prompt} />
|
components/quizz/hooks/useQuizz.ts
CHANGED
@@ -50,10 +50,8 @@ export const useQuizz = () => {
|
|
50 |
setResult(response.ok ? id : response.resultId, response?.ok);
|
51 |
await sleep(3000);
|
52 |
setResult(null);
|
53 |
-
await sleep(100);
|
54 |
if (response?.ok) {
|
55 |
client.invalidateQueries(['quizz']);
|
56 |
-
await refetch()
|
57 |
} else {
|
58 |
return router.push('/results');
|
59 |
}
|
@@ -70,6 +68,12 @@ export const useQuizz = () => {
|
|
70 |
retry: false,
|
71 |
});
|
72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
return {
|
74 |
prompts: data?.prompts ?? [],
|
75 |
loading,
|
@@ -78,5 +82,6 @@ export const useQuizz = () => {
|
|
78 |
onScore,
|
79 |
score,
|
80 |
result,
|
|
|
81 |
}
|
82 |
}
|
|
|
50 |
setResult(response.ok ? id : response.resultId, response?.ok);
|
51 |
await sleep(3000);
|
52 |
setResult(null);
|
|
|
53 |
if (response?.ok) {
|
54 |
client.invalidateQueries(['quizz']);
|
|
|
55 |
} else {
|
56 |
return router.push('/results');
|
57 |
}
|
|
|
68 |
retry: false,
|
69 |
});
|
70 |
|
71 |
+
const reset = () => {
|
72 |
+
client.setQueryData(['score'], 0);
|
73 |
+
client.setQueryData(['success'], null);
|
74 |
+
window.location.href = '/';
|
75 |
+
}
|
76 |
+
|
77 |
return {
|
78 |
prompts: data?.prompts ?? [],
|
79 |
loading,
|
|
|
82 |
onScore,
|
83 |
score,
|
84 |
result,
|
85 |
+
reset
|
86 |
}
|
87 |
}
|
components/results/index.tsx
CHANGED
@@ -1,7 +1,9 @@
|
|
1 |
"use client";
|
2 |
import { redirect } from "next/navigation";
|
|
|
3 |
import { FaXTwitter, FaLinkedin } from "react-icons/fa6";
|
4 |
import Image from "next/image";
|
|
|
5 |
import { LinkedinShareButton, TwitterShareButton } from "react-share";
|
6 |
|
7 |
import { useQuizz } from "@/components/quizz/hooks/useQuizz";
|
@@ -11,33 +13,44 @@ import SparklingEffect2 from "@/assets/images/sparkles-2.svg";
|
|
11 |
import NoSSR from "@/components/no-ssr";
|
12 |
|
13 |
export const Results = () => {
|
14 |
-
const { score } = useQuizz();
|
15 |
|
16 |
-
if (!score
|
17 |
redirect("/");
|
18 |
return null;
|
19 |
}
|
20 |
|
21 |
const renderTitle = (score: number) => {
|
22 |
-
if (score <
|
23 |
return (
|
24 |
<>
|
25 |
You can do <br />
|
26 |
<span className="bg-gradient-to-tr from-green to-cyan bg-clip-text">
|
27 |
better
|
28 |
</span>{" "}
|
29 |
-
!
|
30 |
</>
|
31 |
);
|
32 |
}
|
33 |
-
if (score <
|
34 |
return (
|
35 |
<>
|
36 |
Not bad! <br />
|
37 |
<span className="bg-gradient-to-tr from-green to-cyan bg-clip-text">
|
38 |
Keep going
|
39 |
</span>{" "}
|
40 |
-
!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
</>
|
42 |
);
|
43 |
}
|
@@ -48,7 +61,7 @@ export const Results = () => {
|
|
48 |
<span className="bg-gradient-to-tr from-green to-cyan bg-clip-text">
|
49 |
amazing
|
50 |
</span>{" "}
|
51 |
-
!
|
52 |
</>
|
53 |
);
|
54 |
}
|
@@ -59,7 +72,7 @@ export const Results = () => {
|
|
59 |
<span className="bg-gradient-to-tr from-green to-cyan bg-clip-text">
|
60 |
incredible
|
61 |
</span>{" "}
|
62 |
-
!
|
63 |
</>
|
64 |
);
|
65 |
}
|
@@ -98,9 +111,9 @@ export const Results = () => {
|
|
98 |
<h2 className="text-white text-xl md:text-2xl text-center font-light">
|
99 |
You obtained{" "}
|
100 |
<span className="bg-gradient-to-tr from-green to-cyan bg-clip-text font-bold text-transparent">
|
101 |
-
{score}
|
102 |
</span>{" "}
|
103 |
-
|
104 |
<br />
|
105 |
Share your score with your friends and challenge them!
|
106 |
</h2>
|
@@ -130,6 +143,13 @@ export const Results = () => {
|
|
130 |
</TwitterShareButton>
|
131 |
</div>
|
132 |
</NoSSR>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
<div className="absolute top-1/2 left-1/2 will-transform -translate-x-1/2 -translate-y-1/2 bg-gradient-to-br from-green to-cyan blur-[120px] md:blur-[140px] w-full h-full max-h-[250px] rounded-full z-[-1] opacity-40"></div>
|
134 |
</div>
|
135 |
</div>
|
|
|
1 |
"use client";
|
2 |
import { redirect } from "next/navigation";
|
3 |
+
import { IoReload } from "react-icons/io5";
|
4 |
import { FaXTwitter, FaLinkedin } from "react-icons/fa6";
|
5 |
import Image from "next/image";
|
6 |
+
import Link from "next/link";
|
7 |
import { LinkedinShareButton, TwitterShareButton } from "react-share";
|
8 |
|
9 |
import { useQuizz } from "@/components/quizz/hooks/useQuizz";
|
|
|
13 |
import NoSSR from "@/components/no-ssr";
|
14 |
|
15 |
export const Results = () => {
|
16 |
+
const { score, reset, result } = useQuizz();
|
17 |
|
18 |
+
if (!score && score !== 0) {
|
19 |
redirect("/");
|
20 |
return null;
|
21 |
}
|
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 |
}
|
|
|
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 |
}
|
|
|
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 |
}
|
|
|
111 |
<h2 className="text-white text-xl md:text-2xl text-center font-light">
|
112 |
You obtained{" "}
|
113 |
<span className="bg-gradient-to-tr from-green to-cyan bg-clip-text font-bold text-transparent">
|
114 |
+
{score} point{score > 1 ? "s" : ""}
|
115 |
</span>{" "}
|
116 |
+
!
|
117 |
<br />
|
118 |
Share your score with your friends and challenge them!
|
119 |
</h2>
|
|
|
143 |
</TwitterShareButton>
|
144 |
</div>
|
145 |
</NoSSR>
|
146 |
+
<p
|
147 |
+
className="text-white text-base flex items-center justify-center gap-3 hover:underline cursor-pointer"
|
148 |
+
onClick={reset}
|
149 |
+
>
|
150 |
+
<IoReload className="text-xl" />
|
151 |
+
Play again
|
152 |
+
</p>
|
153 |
<div className="absolute top-1/2 left-1/2 will-transform -translate-x-1/2 -translate-y-1/2 bg-gradient-to-br from-green to-cyan blur-[120px] md:blur-[140px] w-full h-full max-h-[250px] rounded-full z-[-1] opacity-40"></div>
|
154 |
</div>
|
155 |
</div>
|
data/dev.db
DELETED
Binary file (57.3 kB)
|
|