|
1 | 1 |
|
| 2 | +'use client'; |
| 3 | + |
| 4 | +import { useState, useEffect } from 'react'; |
2 | 5 | import Link from 'next/link'; |
3 | | -import prisma from '@/lib/db'; |
4 | | -import { Footprints, Lightbulb, Book, Ticket, Activity, MessageSquare } from 'lucide-react'; |
| 6 | +import { Footprints, Lightbulb, Book, Ticket, Activity, MessageSquare, Loader2 } from 'lucide-react'; |
| 7 | +import { getAdminDashboardStats } from '@/actions/content'; |
| 8 | + |
| 9 | +export default function AdminDashboard() { |
| 10 | + const [statsData, setStatsData] = useState<any>(null); |
| 11 | + const [isLoading, setIsLoading] = useState(true); |
| 12 | + |
| 13 | + useEffect(() => { |
| 14 | + fetchStats(); |
| 15 | + }, []); |
| 16 | + |
| 17 | + const fetchStats = async () => { |
| 18 | + try { |
| 19 | + const data = await getAdminDashboardStats(); |
| 20 | + setStatsData(data); |
| 21 | + } catch (error) { |
| 22 | + console.error('Error fetching dashboard stats:', error); |
| 23 | + } finally { |
| 24 | + setIsLoading(false); |
| 25 | + } |
| 26 | + }; |
| 27 | + |
| 28 | + if (isLoading || !statsData) { |
| 29 | + return ( |
| 30 | + <div className="flex flex-col items-center justify-center min-h-[60vh] text-gray-400 animate-in fade-in duration-700"> |
| 31 | + <Loader2 className="w-10 h-10 animate-spin mb-4 text-ochre" /> |
| 32 | + <p className="text-lg uppercase font-black tracking-widest">Loading Dashboard...</p> |
| 33 | + </div> |
| 34 | + ); |
| 35 | + } |
5 | 36 |
|
6 | | -export default async function AdminDashboard() { |
7 | | - // Fetch stats for the dashboard |
8 | | - const [leelaCount, bodhakathaCount, glossaryCount, ticketCount, openTickets] = await Promise.all([ |
9 | | - prisma.leela.count(), |
10 | | - prisma.bodhakatha.count(), |
11 | | - prisma.glossary.count(), |
12 | | - prisma.ticket.count(), |
13 | | - prisma.ticket.count({ where: { status: 'OPEN' } }) |
14 | | - ]); |
| 37 | + const { leelaCount, bodhakathaCount, glossaryCount, ticketCount, openTickets } = statsData; |
15 | 38 |
|
16 | 39 | const stats = [ |
17 | 40 | { label: 'Content', value: leelaCount + bodhakathaCount + glossaryCount, icon: Activity, color: 'text-blue-600', href: '/admin/leela' }, |
@@ -63,7 +86,7 @@ export default async function AdminDashboard() { |
63 | 86 | ]; |
64 | 87 |
|
65 | 88 | return ( |
66 | | - <div className="max-w-7xl mx-auto p-4 md:p-8 space-y-6 md:space-y-12"> |
| 89 | + <div className="max-w-7xl mx-auto p-4 md:p-8 space-y-6 md:space-y-12 animate-in fade-in duration-1000"> |
67 | 90 | {/* Header Content */} |
68 | 91 | <div className="flex flex-col md:flex-row md:items-end justify-between gap-4 md:pb-2"> |
69 | 92 | <div className="space-y-1"> |
|
0 commit comments