diff --git a/app/game/[id]/AnswerPage.tsx b/app/game/[id]/AnswerPage.tsx new file mode 100644 index 0000000..4e29af0 --- /dev/null +++ b/app/game/[id]/AnswerPage.tsx @@ -0,0 +1,120 @@ +"use client"; +import Link from "next/link"; +import quizs from "@/lib/database"; +import { useRouter } from "next/navigation"; +import { useState } from "react"; +import { useSearchParams } from "next/navigation"; + +interface AnswerPageProps { + id: string; +} + +export function AnswerPage({ id }: AnswerPageProps) { + const searchParams = useSearchParams(); + const correct = searchParams.get("correctOrWrong") === "true"; + const view = searchParams.get("view") === "true"; + const currentQuiz = quizs.quizs[Number(id)]; + const [selectedOption, setSelectedOption] = useState(""); + const [score, setScore] = useState(0); + const router = useRouter(); + + return ( +
+
+ + + + + +

บริหารการเงิน

+
+

+ {currentQuiz.id} quiz +

+
+

+ {currentQuiz.question} +

+
+ {/* {correct && !view ? ( +
+ ถูก +

+1 coin

+
+ ) : ( +
+ ผิด +

-1 coin

+

เฉลย: {currentQuiz.answer}

+
+ )} */} + {correct && !view ? ( +
+ ถูก +

+1 coin

+
+ ) : !correct && !view ? ( +
+ ผิด +

-1 coin

+

เฉลย: {currentQuiz.answer}

+
+ ) : view ? ( +
+ {currentQuiz.options.map((option, index) => ( + + ))} +
+ ) : ( +
Error Occur!
+ )} +
+ {!view && ( + + Next + + )} +
+
+ ); +} diff --git a/app/game/[id]/page.tsx b/app/game/[id]/page.tsx index 6f9960b..ef960ed 100644 --- a/app/game/[id]/page.tsx +++ b/app/game/[id]/page.tsx @@ -1,91 +1,17 @@ -'use client' -import Link from "next/link"; import quizs from "@/lib/database"; -import { useRouter } from "next/navigation"; -import { useState } from "react"; -import { useSearchParams } from 'next/navigation' +import { AnswerPage } from "./AnswerPage"; +import { Suspense } from "react"; function Answer({ params }: { params: { id: string } }) { - const searchParams = useSearchParams() - const correct = searchParams.get('correctOrWrong') === 'true' - const view = searchParams.get('view') === 'true' - console.log("Param",params.id) - console.log("quizs",quizs) - const currentQuiz = quizs.quizs[Number(params.id)] - console.log(currentQuiz) - console.log(currentQuiz.id) - console.log("CorrectOrWrong Value:", correct, typeof correct) - console.log("View:", view) - const [selectedOption, setSelectedOption] = useState(""); - const [score, setScore] = useState(0); - const router = useRouter(); + return ( + + + + ); +} - return ( -
-
- - - - - -

บริหารการเงิน

-
-

{currentQuiz.id} quiz

-
-

{currentQuiz.question}

-
- {/* {correct && !view ? ( -
- ถูก -

+1 coin

-
- ) : ( -
- ผิด -

-1 coin

-

เฉลย: {currentQuiz.answer}

-
- )} */} - {correct && !view ? ( -
- ถูก -

+1 coin

-
- ) : !correct && !view ? ( -
- ผิด -

-1 coin

-

เฉลย: {currentQuiz.answer}

-
- ) : view ? ( -
- {currentQuiz.options.map((option, index) => ( - - ))} -
- ) : ( -
- Error Occur! -
- )} -
- {!view && Next} -
-
- ); +export function generateStaticParams() { + return quizs.quizs.map((_, index) => ({ id: String(index) })); } -export default Answer; \ No newline at end of file +export default Answer;