From 54aa4310ec3bab7ec9e1816d6514b9f93987fc6c Mon Sep 17 00:00:00 2001 From: FridaKroken Date: Sun, 27 Oct 2024 14:34:19 +0100 Subject: [PATCH 1/2] started on question game carousel --- src/app/question-game/page.tsx | 9 +++++++++ src/components/questiongame/card.tsx | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/components/questiongame/card.tsx diff --git a/src/app/question-game/page.tsx b/src/app/question-game/page.tsx index e69de29..d8f7c08 100644 --- a/src/app/question-game/page.tsx +++ b/src/app/question-game/page.tsx @@ -0,0 +1,9 @@ +import { QuestionCard } from "~/components/questiongame/card"; + +export default function Page() { + return ( +
+ +
+ ); +} \ No newline at end of file diff --git a/src/components/questiongame/card.tsx b/src/components/questiongame/card.tsx new file mode 100644 index 0000000..c6eabf9 --- /dev/null +++ b/src/components/questiongame/card.tsx @@ -0,0 +1,24 @@ + +import { Card, CardContent } from "../ui/card"; +import { Carousel, CarouselContent, CarouselItem, CarouselNext, CarouselPrevious } from "../ui/carousel"; + +export function QuestionCard() { + + return ( + + + +
+ + + {1} + + +
+
+
+ + +
+ ) +} From 8581724a6dd969925717b1fc1d90f035bb30efc5 Mon Sep 17 00:00:00 2001 From: FridaKroken Date: Sun, 27 Oct 2024 16:12:09 +0100 Subject: [PATCH 2/2] added first version of question carousel --- src/app/question-game/[id]/page.tsx | 64 +++++++++++++++++++ src/app/question-game/page.tsx | 11 +++- src/components/layout/footer.tsx | 4 +- .../question/controller/get-from-game.ts | 2 +- .../api/question-game/question/router.ts | 4 +- 5 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 src/app/question-game/[id]/page.tsx diff --git a/src/app/question-game/[id]/page.tsx b/src/app/question-game/[id]/page.tsx new file mode 100644 index 0000000..22b1028 --- /dev/null +++ b/src/app/question-game/[id]/page.tsx @@ -0,0 +1,64 @@ +import { Card, CardContent } from "~/components/ui/card"; +import { Carousel, CarouselContent, CarouselItem, CarouselNext, CarouselPrevious } from "~/components/ui/carousel"; +import { api } from "~/trpc/server"; + + +interface QuestionGameProps { + params: { + id: string; + }; +} + +interface Question { + id: number; + question: string; +} + +const QuestionGame = async ({ params }: QuestionGameProps) => { + const data = await api.questionGame.question.getAll({ + questionGameId: parseInt(params.id) + }); + + const shuffleArray = (arr: Question[]): Question[] => { + // Clone the array to avoid mutating the original + const array = [...arr]; + + // Loop through the array from the last to the second element + for (let i = array.length - 1; i > 0; i--) { + // Generate a random index from 0 to i + const j = Math.floor(Math.random() * (i + 1)); + + // Use type assertions to satisfy TypeScript + [array[i], array[j]] = [array[j] as Question, array[i] as Question]; + } + + return array; + } + + return ( +
+ + + {shuffleArray(data.questions).map((question, index) => ( + +
+ + + {question.question} + + +
+
+ ))} +
+
+ + +
+
+
+ ) +}; + + +export default QuestionGame; \ No newline at end of file diff --git a/src/app/question-game/page.tsx b/src/app/question-game/page.tsx index 526bc51..a9ff146 100644 --- a/src/app/question-game/page.tsx +++ b/src/app/question-game/page.tsx @@ -1,11 +1,20 @@ +import { Button } from "~/components/ui/button"; import GameLinkCard from "../../components/ui/game-link-card"; import { api } from "../../trpc/server"; +import Link from "next/link"; export default async function QuestionGamesPage() { const games = await api.questionGame.game.getAll(); return ( -
+
+
{games.map((g) => ( vercel diff --git a/src/server/api/question-game/question/controller/get-from-game.ts b/src/server/api/question-game/question/controller/get-from-game.ts index 2d56ddf..ce9357f 100644 --- a/src/server/api/question-game/question/controller/get-from-game.ts +++ b/src/server/api/question-game/question/controller/get-from-game.ts @@ -24,7 +24,7 @@ const handler: Controller< > = async ({ input, ctx }) => { const questions = await db.question.findMany({ where: { - id: input.questionGameId, + questionGameId: input.questionGameId, }, }) diff --git a/src/server/api/question-game/question/router.ts b/src/server/api/question-game/question/router.ts index 1287146..6730b1d 100644 --- a/src/server/api/question-game/question/router.ts +++ b/src/server/api/question-game/question/router.ts @@ -1,6 +1,8 @@ import { createTRPCRouter } from "../../trpc"; import create from "./controller/create"; +import getAll from "./controller/get-from-game"; export const questionRouter = createTRPCRouter({ - create + create, + getAll }) \ No newline at end of file