Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

show usage stats on Project Card

Steven Tey4bf8f83aa1bd
diff --git a/components/app/project-card.tsx b/components/app/project-card.tsx
index 11c189a0f0..a421b553c2 100644
--- a/components/app/project-card.tsx
+++ b/components/app/project-card.tsx
@@ -1,15 +1,50 @@
import Link from "next/link";
import useSWR from "swr";
-import { fetcher } from "@/lib/utils";
+import { fetcher, nFormatter } from "@/lib/utils";
import { ProjectProps } from "@/lib/types";
+import { CheckCircleFill, XCircleFill, Chart } from "@/components/shared/icons";
+import BlurImage from "../shared/blur-image";
-export default function ProjectCard({ name, slug }: ProjectProps) {
+export default function ProjectCard({
+ name,
+ slug,
+ domain,
+ domainVerified,
+}: ProjectProps) {
+ const { data } = useSWR<{ totalClicks: number }>(
+ domainVerified && `/api/projects/${slug}/domains/${domain}/usage`,
+ fetcher
+ );
return (
<Link key={slug} href={`/${slug}`}>
<a>
- <div className="bg-white dark:bg-gray-800 shadow rounded-lg p-4 hover:shadow-md transition-all">
- <h2 className="text-xl font-bold">{name}</h2>
- <p className="text-gray-500 dark:text-gray-400">{slug}</p>
+ <div className="bg-white dark:bg-gray-800 shadow rounded-lg p-6 flex justify-between hover:shadow-md transition-all">
+ <div className="flex items-center space-x-3">
+ <BlurImage
+ src={`https://avatar.tobi.sh/${slug}`}
+ alt={name}
+ className="w-9 h-9 flex-shrink-0 rounded-full overflow-hidden border border-gray-300"
+ width={48}
+ height={48}
+ />
+ <div>
+ <h2 className="text-lg font-medium text-gray-700">{name}</h2>
+ <div className="flex space-x-1 items-center">
+ <p className="text-gray-500 dark:text-gray-400">{domain}</p>
+ {domainVerified ? (
+ <CheckCircleFill className="w-5 h-5 text-blue-500" />
+ ) : (
+ <XCircleFill className="w-5 h-5 text-gray-500" />
+ )}
+ </div>
+ </div>
+ </div>
+ <div className="flex items-center space-x-2">
+ <Chart className="text-gray-600 dark:text-gray-400 w-7 h-7" />
+ <h2 className="text-lg font-medium text-gray-700">
+ {nFormatter(data?.totalClicks!)}
+ </h2>
+ </div>
</div>
</a>
</Link>
diff --git a/pages/api/projects/[slug]/domains/[domain]/usage.ts b/pages/api/projects/[slug]/domains/[domain]/usage.ts
new file mode 100644
index 0000000000..51dc6197a8
--- /dev/null
+++ b/pages/api/projects/[slug]/domains/[domain]/usage.ts
@@ -0,0 +1,25 @@
+import { NextApiRequest, NextApiResponse } from "next";
+import { withProjectAuth } from "@/lib/auth";
+import { redis } from "@/lib/upstash";
+
+export default withProjectAuth(
+ async (req: NextApiRequest, res: NextApiResponse) => {
+ // GET /api/projects/[slug]/exists – check if a project exists
+ if (req.method === "GET") {
+ const { domain } = req.query as { domain: string };
+
+ const clicks = await redis.zrange(`${domain}:links:clicks`, 0, -1, {
+ withScores: true,
+ });
+ const totalClicks = (
+ clicks.filter((_, i) => i % 2 === 1) as number[]
+ ).reduce((a, b) => a + b, 0);
+ return res.status(200).json({ totalClicks });
+ } else {
+ res.setHeader("Allow", ["GET"]);
+ return res
+ .status(405)
+ .json({ error: `Method ${req.method} Not Allowed` });
+ }
+ }
+);
diff --git a/pages/app/index.tsx b/pages/app/index.tsx
index 34aabf95fd..8ddf37bd44 100644
--- a/pages/app/index.tsx
+++ b/pages/app/index.tsx
@@ -30,7 +30,7 @@ export default function App() {
<MaxWidthWrapper>
<div
className={`my-10 grid grid-cols-1 ${
- data?.length === 0 ? "" : "sm:grid-cols-3"
+ data?.length === 0 ? "" : "lg:grid-cols-3"
} gap-5`}
>
{data ? (