page.tsx87 lines, 2.8 KB
| 1 | import { Metadata } from "next"; |
| 2 | import { db } from "@/server/db"; |
| 3 | import { urls } from "@/server/db/schema"; |
| 4 | import { count, sql } from "drizzle-orm"; |
| 5 | import { |
| 6 | Card, |
| 7 | CardContent, |
| 8 | CardDescription, |
| 9 | CardHeader, |
| 10 | CardTitle, |
| 11 | } from "@/components/ui/card"; |
| 12 | import { Button } from "@/components/ui/button"; |
| 13 | import Link from "next/link"; |
| 14 | |
| 15 | export const metadata: Metadata = { |
| 16 | title: "Statistics | ShortLink", |
| 17 | description: "Statistics about our URL shortener service", |
| 18 | }; |
| 19 | |
| 20 | export default async function PublicStatsPage() { |
| 21 | // Get total number of URLs |
| 22 | const [urlCount] = await db.select({ value: count() }).from(urls); |
| 23 | const totalUrls = urlCount?.value || 0; |
| 24 | |
| 25 | // Get total number of clicks |
| 26 | const [clicksResult] = await db |
| 27 | .select({ total: sql<number>`sum(${urls.clicks})` }) |
| 28 | .from(urls); |
| 29 | const totalClicks = clicksResult?.total || 0; |
| 30 | |
| 31 | return ( |
| 32 | <div className="container max-w-4xl mx-auto py-10 px-4"> |
| 33 | <h1 className="text-3xl font-bold mb-2 text-center"> |
| 34 | Service Statistics |
| 35 | </h1> |
| 36 | <p className="text-center text-muted-foreground mb-8"> |
| 37 | General statistics about our URL shortener service |
| 38 | </p> |
| 39 | |
| 40 | <div className="grid gap-8 md:grid-cols-2 mb-8"> |
| 41 | <Card className="shadow-sm"> |
| 42 | <CardHeader className="pb-2"> |
| 43 | <CardTitle className="text-lg">Total URLs Shortened</CardTitle> |
| 44 | <CardDescription> |
| 45 | Number of URLs shortened with our service |
| 46 | </CardDescription> |
| 47 | </CardHeader> |
| 48 | <CardContent> |
| 49 | <p className="text-4xl font-bold">{totalUrls.toLocaleString()}</p> |
| 50 | </CardContent> |
| 51 | </Card> |
| 52 | |
| 53 | <Card className="shadow-sm"> |
| 54 | <CardHeader className="pb-2"> |
| 55 | <CardTitle className="text-lg">Total Clicks</CardTitle> |
| 56 | <CardDescription> |
| 57 | Total number of redirects through our service |
| 58 | </CardDescription> |
| 59 | </CardHeader> |
| 60 | <CardContent> |
| 61 | <p className="text-4xl font-bold">{totalClicks.toLocaleString()}</p> |
| 62 | </CardContent> |
| 63 | </Card> |
| 64 | </div> |
| 65 | |
| 66 | <div className="text-center"> |
| 67 | <Card className="shadow-sm mb-8"> |
| 68 | <CardHeader> |
| 69 | <CardTitle>Want to see your personal statistics?</CardTitle> |
| 70 | <CardDescription> |
| 71 | Sign up for an account to track your own shortened URLs and view |
| 72 | detailed statistics. |
| 73 | </CardDescription> |
| 74 | </CardHeader> |
| 75 | <CardContent className="flex justify-center gap-4"> |
| 76 | <Button asChild> |
| 77 | <Link href="/register">Sign Up</Link> |
| 78 | </Button> |
| 79 | <Button variant="outline" asChild> |
| 80 | <Link href="/login">Login</Link> |
| 81 | </Button> |
| 82 | </CardContent> |
| 83 | </Card> |
| 84 | </div> |
| 85 | </div> |
| 86 | ); |
| 87 | } |