From 490388360a0852bcf8ee054e96fa90e166df5792 Mon Sep 17 00:00:00 2001
From: polwex <polwex@sortug.com>
Date: Thu, 29 May 2025 14:52:38 +0700
Subject: fucker actually solved the cookies, love ya man

---
 src/pages/study.tsx | 53 ++++++++++++++++++++++++++++++-----------------------
 1 file changed, 30 insertions(+), 23 deletions(-)

(limited to 'src/pages/study.tsx')

diff --git a/src/pages/study.tsx b/src/pages/study.tsx
index db7dde7..f818b4b 100644
--- a/src/pages/study.tsx
+++ b/src/pages/study.tsx
@@ -1,3 +1,4 @@
+import { getContextData } from "waku/middleware/context";
 import { useState } from "react";
 import { getState } from "@/lib/db";
 import { startStudySession } from "@/actions/srs";
@@ -8,17 +9,24 @@ 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 state = getState(null);
-  const userId = state.user?.id;
-  
+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 (
       <div className="container mx-auto py-8">
         <Card className="p-6 text-center">
           <h1 className="text-2xl font-bold mb-4">Login Required</h1>
-          <p className="mb-4">You need to be logged in to use the study session feature.</p>
+          <p className="mb-4">
+            You need to be logged in to use the study session feature.
+          </p>
           <Button asChild>
             <a href="/login">Login</a>
           </Button>
@@ -26,14 +34,16 @@ export default async function StudyPage({ searchParams }: { searchParams: { less
       </div>
     );
   }
-  
-  const lessonId = searchParams.lessonId ? parseInt(searchParams.lessonId, 10) : null;
-  
+
+  const lessonId = searchParams.lessonId
+    ? parseInt(searchParams.lessonId, 10)
+    : null;
+
   // If no lesson ID provided, show lesson selector
   if (!lessonId) {
     return <LessonSelector userId={userId} />;
   }
-  
+
   // Get initial data for the study session
   let initialData;
   try {
@@ -41,13 +51,15 @@ export default async function StudyPage({ searchParams }: { searchParams: { less
   } catch (error) {
     console.error("Error starting study session:", error);
   }
-  
+
   return (
     <div className="container mx-auto py-8">
       <StudySession
         userId={userId}
         lessonId={lessonId}
-        initialData={initialData && !('error' in initialData) ? initialData : undefined}
+        initialData={
+          initialData && !("error" in initialData) ? initialData : undefined
+        }
       />
     </div>
   );
@@ -56,12 +68,12 @@ export default async function StudyPage({ searchParams }: { searchParams: { less
 // Client component for selecting a lesson
 function LessonSelector({ userId }: { userId: number }) {
   const [lessonId, setLessonId] = useState<string>("");
-  
+
   return (
     <div className="container mx-auto py-8">
       <Card className="p-6 max-w-md mx-auto">
         <h1 className="text-2xl font-bold mb-6">Start Study Session</h1>
-        
+
         <form action={`/study?lessonId=${lessonId}`}>
           <div className="space-y-4">
             <div>
@@ -75,13 +87,13 @@ function LessonSelector({ userId }: { userId: number }) {
                 required
               />
             </div>
-            
+
             <Button type="submit" className="w-full">
               Start Study Session
             </Button>
           </div>
         </form>
-        
+
         <div className="mt-6 pt-6 border-t border-gray-200">
           <h2 className="text-lg font-medium mb-3">Available Lessons</h2>
           <p className="text-sm text-gray-500 mb-4">
@@ -110,14 +122,9 @@ function LessonSelector({ userId }: { userId: number }) {
               Lesson 5
             </Button>
           </div>
-          
+
           <div className="mt-4">
-            <Button
-              variant="ghost"
-              size="sm"
-              asChild
-              className="text-blue-500"
-            >
+            <Button variant="ghost" size="sm" asChild className="text-blue-500">
               <a href="/">Back to Home</a>
             </Button>
           </div>
@@ -125,4 +132,4 @@ function LessonSelector({ userId }: { userId: number }) {
       </Card>
     </div>
   );
-}
\ No newline at end of file
+}
-- 
cgit v1.2.3

