enzostvs HF Staff commited on
Commit
d7b1e3e
·
1 Parent(s): c0f4534

countdown wip

Browse files
Files changed (2) hide show
  1. README.md +1 -1
  2. components/quizz/index.tsx +26 -1
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: Guess The Image
3
  emoji: 🤯
4
  colorFrom: blue
5
  colorTo: green
 
1
  ---
2
+ title: guess the image —
3
  emoji: 🤯
4
  colorFrom: blue
5
  colorTo: green
components/quizz/index.tsx CHANGED
@@ -1,18 +1,43 @@
1
  "use client";
 
 
2
 
3
  import { useQuizz } from "./hooks/useQuizz";
4
  import { PromptType } from "@/utils/type";
5
  import { Card } from "./card";
 
6
 
7
  export const QuizzContent = () => {
8
  const { loading, prompts, question } = useQuizz();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  return (
11
  <div className="flex flex-col-reverse lg:flex-col items-center justify-center gap-10 lg:gap-12">
12
  <div className="grid grid-cols-1 gap-0 lg:gap-12">
13
- <p className="text-white font-normal text-lg lg:text-2xl text-center">
14
  Guess which image is related to the prompt above
15
  </p>
 
 
 
 
16
  <div className="flex flex-col lg:flex-row items-center justify-center gap-0 lg:gap-16">
17
  {loading
18
  ? Array.from({ length: 3 }).map((_, i: number) => (
 
1
  "use client";
2
+ import { useEffect, useState } from "react";
3
+ import { RxLapTimer } from "react-icons/rx";
4
 
5
  import { useQuizz } from "./hooks/useQuizz";
6
  import { PromptType } from "@/utils/type";
7
  import { Card } from "./card";
8
+ import { useUpdateEffect } from "react-use";
9
 
10
  export const QuizzContent = () => {
11
  const { loading, prompts, question } = useQuizz();
12
+ const [counter, setCounter] = useState(10);
13
+
14
+ // TODO: use useInterval hook + stop counter when result or when user click on a card
15
+ // trigger an aumatic cancel when the counter is done
16
+
17
+ useEffect(() => {
18
+ if (!counter) {
19
+ console.log("counter end");
20
+ return;
21
+ }
22
+ const timer =
23
+ counter > 0 && setInterval(() => setCounter(counter - 1), 1000);
24
+ return () => clearInterval(timer || 0);
25
+ }, [counter]);
26
+
27
+ useUpdateEffect(() => {
28
+ setCounter(10);
29
+ }, [question]);
30
 
31
  return (
32
  <div className="flex flex-col-reverse lg:flex-col items-center justify-center gap-10 lg:gap-12">
33
  <div className="grid grid-cols-1 gap-0 lg:gap-12">
34
+ <p className="text-white font-normal text-lg lg:text-2xl text-center mb-5 lg:mb-0">
35
  Guess which image is related to the prompt above
36
  </p>
37
+ <p className="text-white text-center text-3xl font-extrabold max-w-max mx-auto flex items-center justify-between gap-4 relative">
38
+ <RxLapTimer className="inline-block mb-4 lg:mb-2 text-3xl lg:text-4xl" />
39
+ {counter}
40
+ </p>
41
  <div className="flex flex-col lg:flex-row items-center justify-center gap-0 lg:gap-16">
42
  {loading
43
  ? Array.from({ length: 3 }).map((_, i: number) => (