import { getContextData } from "waku/middleware/context";
import { Link } from "waku";
import { getUserLessons, getUserStudyStats } from "@/actions/srs";
import {
BookOpen,
GraduationCap,
Clock,
Star,
ChevronRight,
BrainCircuit,
Flame,
Layers,
CalendarDays
} from "lucide-react";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";
import { Progress } from "@/components/ui/progress";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { Badge } from "@/components/ui/badge";
import Navbar from "@/components/Navbar";
// This is a server component that gets the initial data
export default async function StudyPage() {
const { user } = getContextData() as any;
// Redirect to login if not authenticated
if (!user) {
return (
Login Required
You need to be logged in to access your study dashboard.
);
}
// Fetch user study data
let userStats;
let userLessons;
try {
// Get user stats and lessons in parallel
[userStats, userLessons] = await Promise.all([
getUserStudyStats(user.id),
getUserLessons(user.id)
]);
} catch (error) {
console.error("Error fetching study data:", error);
userStats = {
totalCards: 0,
masteredCards: 0,
dueCards: 0,
averageEaseFactor: 2.5,
successRate: 0,
streakDays: 0
};
userLessons = [];
}
// Calculate overall progress
const overallProgress = userStats.totalCards > 0
? Math.round((userStats.masteredCards / userStats.totalCards) * 100)
: 0;
// Sort lessons by different criteria
const dueLessons = [...userLessons].sort((a, b) => b.dueCards - a.dueCards).filter(l => l.dueCards > 0);
const inProgressLessons = userLessons.filter(lesson => lesson.progress > 0 && lesson.progress < 100);
const recentLessons = [...userLessons].sort((a, b) => b.id - a.id).slice(0, 4);
return (
{/* Dashboard Header */}
Study Dashboard
Track your progress, review due cards, and continue your language learning journey
{/* Main Content Tabs */}
All Lessons
Due for Review {dueLessons.length > 0 && `(${dueLessons.length})`}
In ProgressStudy Stats
{/* All Lessons Tab */}