import { createClient } from "@/utils/supabase/server"; import Link from "next/link"; export default async function AdminDashboardPage() { const supabase = await createClient(); const [postsRes, commentsRes, subsRes, authorsRes] = await Promise.all([ supabase.from("posts").select("id", { count: "exact", head: true }), supabase.from("comments").select("id", { count: "exact", head: true }), supabase.from("subscriptions").select("id", { count: "exact", head: true }), supabase.from("authors").select("name", { count: "exact", head: true }), ]); const stats = [ { label: "Posts", count: postsRes.count || 0, href: "/admin/posts" }, { label: "Comments", count: commentsRes.count || 0, href: "/admin/comments", }, { label: "Subscribers", count: subsRes.count || 0, href: "/admin/subscriptions", }, { label: "Authors", count: authorsRes.count || 0, href: "/admin/authors" }, ]; // Recent posts const { data: recentPosts } = await supabase .from("posts") .select("id, title, date, published") .order("created_at", { ascending: false }) .limit(5); // Recent comments const { data: recentComments } = await supabase .from("comments") .select("id, name, comment, post_id, created_at") .order("created_at", { ascending: false }) .limit(5); return (
{stat.label}
{stat.count}
))}{new Date(post.date).toLocaleDateString()}
No posts yet.
)}{comment.name}
{comment.comment}
on {comment.post_id} ·{" "} {new Date(comment.created_at).toLocaleDateString()}
No comments yet.
)}