fix: read analytics data directly on server

This commit is contained in:
Nice Try
2026-06-26 19:07:39 +00:00
parent 3effbdcb57
commit 33e5e61b11
3 changed files with 104 additions and 113 deletions
+1 -30
View File
@@ -1,5 +1,6 @@
import type { Metadata } from 'next'
import { Header } from '@/components/Header'
import { getAnalyticsData } from '@/lib/analytics'
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
import { Progress } from '@/components/ui/progress'
import { Badge } from '@/components/ui/badge'
@@ -23,36 +24,6 @@ export const metadata: Metadata = {
description: 'Learning analytics and progress overview.',
}
interface AnalyticsData {
totalCourses: number
completedCourses: number
inProgressCourses: number
totalLessons: number
completedLessons: number
inProgressLessons: number
notStartedLessons: number
totalWatchedHours: number
totalWatchedMinutes: number
weeklyWatchedHours: number
weeklyWatchedMinutes: number
weeklyCompletedLessons: number
lessonsByType: Array<{ type: string; _count: number }>
completedByType: Record<string, number>
completionRate: number
lessonCompletionRate: number
}
async function getAnalyticsData(): Promise<AnalyticsData> {
const res = await fetch('/api/progress?type=analytics', {
cache: 'no-store',
next: { tags: ['analytics'] },
})
if (!res.ok) {
throw new Error('Failed to fetch analytics')
}
return res.json()
}
const lessonTypeIcons: Record<string, React.ReactNode> = {
VIDEO: <Film className="h-4 w-4 text-red-400" />,
AUDIO: <Music className="h-4 w-4 text-purple-400" />,