From 8e0965f5274635f609972ef85802675af64df0f4 Mon Sep 17 00:00:00 2001 From: polwex Date: Thu, 29 May 2025 15:16:41 +0700 Subject: this is mostly me --- src/pages/study.tsx | 124 ++++++++++++++++------------------------------------ 1 file changed, 38 insertions(+), 86 deletions(-) (limited to 'src/pages') diff --git a/src/pages/study.tsx b/src/pages/study.tsx index f818b4b..68f781e 100644 --- a/src/pages/study.tsx +++ b/src/pages/study.tsx @@ -1,12 +1,10 @@ import { getContextData } from "waku/middleware/context"; -import { useState } from "react"; 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 { Input } from "@/components/ui/input"; -import { Label } from "@/components/ui/label"; +import LessonSelector from "@/components/srs/LessonSelector"; // This is a server component that gets the initial data export default async function StudyPage({ @@ -15,8 +13,8 @@ export default async function StudyPage({ searchParams: { lessonId?: string }; }) { const { user } = getContextData() as any; - // const state = getState(null); const userId = user?.id; + // const state = getState(null); // If not logged in, show login required message if (!userId) { @@ -35,101 +33,55 @@ export default async function StudyPage({ ); } - const lessonId = searchParams.lessonId + const lessonId = searchParams?.lessonId ? parseInt(searchParams.lessonId, 10) : null; // If no lesson ID provided, show lesson selector - if (!lessonId) { - return ; - } // Get initial data for the study session - let initialData; - try { - initialData = await startStudySession(userId, lessonId, true); - } catch (error) { - console.error("Error starting study session:", error); - } return (
- +
); } -// Client component for selecting a lesson -function LessonSelector({ userId }: { userId: number }) { - const [lessonId, setLessonId] = useState(""); - +async function Inner({ + userId, + lessonId, +}: { + userId: number; + lessonId: number | null; +}) { return ( -
- -

Start Study Session

- -
-
-
- - setLessonId(e.target.value)} - placeholder="Enter lesson ID" - type="number" - required - /> -
- - -
-
- -
-

Available Lessons

-

- Here are some example lesson IDs you can use: -

-
- - - -
- -
- -
-
-
-
+ <> + {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

; +} -- cgit v1.2.3