From f243847216279cbd43879de8b5ef6dcceb3a2f1d Mon Sep 17 00:00:00 2001 From: polwex Date: Thu, 29 May 2025 14:08:02 +0700 Subject: lets see --- src/pages/lessons.tsx | 126 +++++++++++++++++++++++++++++++++++++++++++++++++ src/pages/study.tsx | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 254 insertions(+) create mode 100644 src/pages/lessons.tsx create mode 100644 src/pages/study.tsx (limited to 'src/pages') diff --git a/src/pages/lessons.tsx b/src/pages/lessons.tsx new file mode 100644 index 0000000..ef8aa49 --- /dev/null +++ b/src/pages/lessons.tsx @@ -0,0 +1,126 @@ +import { useState } from "react"; +import { getState } from "@/lib/db"; +import { getUserLessons, getLessonProgress } from "@/actions/srs"; +import { Button } from "@/components/ui/button"; +import { Card } from "@/components/ui/card"; +import { Progress } from "@/components/ui/progress"; + +// This is a server component that gets the initial data +export default async function LessonsPage() { + const state = getState(null); + const userId = state.user?.id; + + // If not logged in, show login required message + if (!userId) { + return ( +
+ +

Login Required

+

You need to be logged in to view your lessons.

+ +
+
+ ); + } + + // Get user lessons data + let lessons; + try { + lessons = await getUserLessons(userId); + } catch (error) { + console.error("Error fetching lessons:", error); + } + + return ( +
+
+

Your Lessons

+ +
+ + {!lessons || lessons.length === 0 ? ( + + ) : ( +
+ {lessons.map((lesson) => ( + + ))} +
+ )} +
+ ); +} + +// Component to display when no lessons are found +function NoLessonsFound() { + return ( + +

No Lessons Found

+

+ You don't have any lessons available yet. +

+
+ ); +} + +// Component to display a lesson card +function LessonCard({ lesson, userId }: { lesson: any; userId: number }) { + const [isHovered, setIsHovered] = useState(false); + + // Calculate progress percentage + const progressPercentage = lesson.progress || 0; + + // Determine progress color + const getProgressColor = (percentage: number) => { + if (percentage >= 80) return "bg-green-500"; + if (percentage >= 50) return "bg-yellow-500"; + return "bg-blue-500"; + }; + + return ( + setIsHovered(true)} + onMouseLeave={() => setIsHovered(false)} + > +
+

{lesson.name}

+

+ {lesson.description || "No description available."} +

+ +
+
+ {lesson.masteredCards} + / {lesson.totalCards} cards +
+
+ + {lesson.dueCards} due + +
+
+ +
+ +
+ +
+ + +
+
+
+ ); +} \ No newline at end of file diff --git a/src/pages/study.tsx b/src/pages/study.tsx new file mode 100644 index 0000000..db7dde7 --- /dev/null +++ b/src/pages/study.tsx @@ -0,0 +1,128 @@ +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 state = getState(null); + const userId = state.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: +

+
+ + + +
+ +
+ +
+
+
+
+ ); +} \ No newline at end of file -- cgit v1.2.3