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"; // 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 state = getState(null); const userId = user?.id; // 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 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(""); 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:

); }