From f23f7d2f0106882183929c740e4862a1939900d0 Mon Sep 17 00:00:00 2001 From: polwex Date: Thu, 29 May 2025 15:37:22 +0700 Subject: me again but it works! --- src/pages/study.tsx | 87 ---------------------------------------------- src/pages/study/[slug].tsx | 82 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 87 deletions(-) delete mode 100644 src/pages/study.tsx create mode 100644 src/pages/study/[slug].tsx (limited to 'src/pages') diff --git a/src/pages/study.tsx b/src/pages/study.tsx deleted file mode 100644 index 68f781e..0000000 --- a/src/pages/study.tsx +++ /dev/null @@ -1,87 +0,0 @@ -import { getContextData } from "waku/middleware/context"; -import { getState } from "@/lib/db"; -import { startStudySession } from "@/actions/srs"; -import StudySession from "@/components/Flashcard/StudySession"; -import { Button } from "@/components/ui/button"; -import { Card } from "@/components/ui/card"; -import LessonSelector from "@/components/srs/LessonSelector"; - -// This is a server component that gets the initial data -export default async function StudyPage({ - searchParams, -}: { - searchParams: { lessonId?: string }; -}) { - const { user } = getContextData() as any; - const userId = user?.id; - // const state = getState(null); - - // If not logged in, show login required message - if (!userId) { - return ( -
- -

Login Required

-

- You need to be logged in to use the study session feature. -

- -
-
- ); - } - - const lessonId = searchParams?.lessonId - ? parseInt(searchParams.lessonId, 10) - : null; - - // If no lesson ID provided, show lesson selector - - // Get initial data for the study session - - return ( -
- -
- ); -} - -async function Inner({ - userId, - lessonId, -}: { - userId: number; - lessonId: number | null; -}) { - return ( - <> - {lessonId ? ( - - ) : ( - - )} - - ); -} -async function StudySessionOuter({ - userId, - lessonId, -}: { - userId: number; - lessonId: number; -}) { - const initialData = await startStudySession(userId, lessonId, true); - if ("ok" in initialData) - return ( - <> - - - ); - else return

idk

; -} diff --git a/src/pages/study/[slug].tsx b/src/pages/study/[slug].tsx new file mode 100644 index 0000000..a5af523 --- /dev/null +++ b/src/pages/study/[slug].tsx @@ -0,0 +1,82 @@ +import { getContextData } from "waku/middleware/context"; +import { getState } from "@/lib/db"; +import { startStudySession } from "@/actions/srs"; +import StudySession from "@/components/Flashcard/StudySession"; +import { Button } from "@/components/ui/button"; +import { Card } from "@/components/ui/card"; +import LessonSelector from "@/components/srs/LessonSelector"; +import type { PageProps } from "waku/router"; + +// This is a server component that gets the initial data +export default async function StudyPage(props: PageProps<"/study/[slug]">) { + const lessonId = props.slug; + const ctx = getContextData() as any; + const userId = ctx?.user?.id; + // const state = getState(null); + + // If not logged in, show login required message + if (!userId) { + return ( +
+ +

Login Required

+

+ You need to be logged in to use the study session feature. +

+ +
+
+ ); + } + + // If no lesson ID provided, show lesson selector + + // Get initial data for the study session + + return ( +
+ +
+ ); +} + +async function Inner({ + userId, + lessonId, +}: { + userId: number; + lessonId: string; +}) { + return ( + <> + {lessonId && Number(lessonId) ? ( + + ) : ( + + )} + + ); +} +async function StudySessionOuter({ + userId, + lessonId, +}: { + userId: number; + lessonId: number; +}) { + const initialData = await startStudySession(userId, lessonId, true); + console.log({ initialData }); + if ("ok" in initialData) + return ( + <> + + + ); + else return

idk

; +} -- cgit v1.2.3