The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Added placeholder for project cards, links/count endpoint
Steven Teyd2a089ff5e06
diff --git a/components/app/placeholder-card.tsx b/components/app/link-card-placeholder.tsxsimilarity index 95%rename from components/app/placeholder-card.tsxrename to components/app/link-card-placeholder.tsxindex 8a91ceec58..d613ce89e0 100644--- a/components/app/placeholder-card.tsx+++ b/components/app/link-card-placeholder.tsx@@ -1,7 +1,7 @@import { motion } from "framer-motion";import { FRAMER_MOTION_LIST_ITEM_VARIANTS } from "@/lib/constants";-export default function PlaceholderCard() {+export default function LinkCardPlaceholder() {return (<motion.livariants={FRAMER_MOTION_LIST_ITEM_VARIANTS}diff --git a/components/app/project-card-placeholder.tsx b/components/app/project-card-placeholder.tsxnew file mode 100644index 0000000000..6b4f77d7c5--- /dev/null+++ b/components/app/project-card-placeholder.tsx@@ -0,0 +1,19 @@+export default function ProjectCardPlaceholder() {+ return (+ <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">+ <div className="w-12 h-12 rounded-full bg-gray-200 animate-pulse" />+ <div className="flex flex-col space-y-2.5">+ <div className="w-36 h-5 rounded-md bg-gray-200 animate-pulse" />+ <div className="flex space-x-2 items-center">+ <div className="w-20 h-5 rounded-md bg-gray-200 animate-pulse" />+ <div className="w-5 h-5 rounded-full bg-gray-200 animate-pulse" />+ </div>+ </div>+ </div>+ <div className="flex items-center space-x-2">+ <div className="w-10 h-5 rounded-md bg-gray-200 animate-pulse" />+ </div>+ </div>+ );+}diff --git a/components/app/project-card.tsx b/components/app/project-card.tsxindex a421b553c2..d1f73c875a 100644--- a/components/app/project-card.tsx+++ b/components/app/project-card.tsx@@ -2,7 +2,11 @@ import Link from "next/link";import useSWR from "swr";import { fetcher, nFormatter } from "@/lib/utils";import { ProjectProps } from "@/lib/types";-import { CheckCircleFill, XCircleFill, Chart } from "@/components/shared/icons";+import {+ CheckCircleFill,+ XCircleFill,+ Link as LinkIcon,+} from "@/components/shared/icons";import BlurImage from "../shared/blur-image";export default function ProjectCard({@@ -11,8 +15,8 @@ export default function ProjectCard({domain,domainVerified,}: ProjectProps) {- const { data } = useSWR<{ totalClicks: number }>(- domainVerified && `/api/projects/${slug}/domains/${domain}/usage`,+ const { data: count, isValidating } = useSWR<number>(+ domainVerified && `/api/projects/${slug}/domains/${domain}/links/count`,fetcher);return (@@ -34,16 +38,20 @@ export default function ProjectCard({{domainVerified ? (<CheckCircleFill className="w-5 h-5 text-blue-500" />) : (- <XCircleFill className="w-5 h-5 text-gray-500" />+ <XCircleFill className="w-5 h-5 text-gray-300" />)}</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>+ <LinkIcon className="text-gray-600 dark:text-gray-400 w-5 h-5" />+ {isValidating ? (+ <div className="w-4 h-5 rounded-md bg-gray-200 animate-pulse" />+ ) : (+ <h2 className="text-lg font-medium text-gray-700">+ {nFormatter(count)}+ </h2>+ )}</div></div></a>diff --git a/components/shared/icons/index.tsx b/components/shared/icons/index.tsxindex 5499fd3bd5..7fff13d2fb 100644--- a/components/shared/icons/index.tsx+++ b/components/shared/icons/index.tsx@@ -16,3 +16,4 @@ export { default as AlertCircleFill } from "./alert-circle-fill";export { default as ExternalLink } from "./external-link";export { default as XCircleFill } from "./x-circle-fill";export { default as CheckCircleFill } from "./check-circle-fill";+export { default as Link } from "./link";diff --git a/components/shared/icons/link.tsx b/components/shared/icons/link.tsxnew file mode 100644index 0000000000..c5c188780b--- /dev/null+++ b/components/shared/icons/link.tsx@@ -0,0 +1,19 @@+export default function Link({ className }: { className: string }) {+ return (+ <svg+ fill="none"+ shapeRendering="geometricPrecision"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ viewBox="0 0 24 24"+ width="24"+ height="24"+ className={className}+ >+ <path d="M15 7h3a5 5 0 015 5 5 5 0 01-5 5h-3m-6 0H6a5 5 0 01-5-5 5 5 0 015-5h3" />+ <path d="M8 12h8" />+ </svg>+ );+}diff --git a/lib/upstash.ts b/lib/upstash.tsindex 8f2abec648..88b562d59b 100644--- a/lib/upstash.ts+++ b/lib/upstash.ts@@ -125,6 +125,13 @@ export async function getLinksForProject(return links;}+/**+ * Get the number of links that a project has+ **/+export async function getLinkCountForProject(slug: string) {+ return await redis.zcard(`${slug}:links:timestamps`);+}+export async function addLink(hostname: string,url: string,diff --git a/lib/utils.ts b/lib/utils.tsindex d67565365a..80ba6fd612 100644--- a/lib/utils.ts+++ b/lib/utils.ts@@ -24,6 +24,7 @@ export async function fetcher<JSON = any>(}export function nFormatter(num: number, digits?: number) {+ if (!num) return "0";const lookup = [{ value: 1, symbol: "" },{ value: 1e3, symbol: "K" },diff --git a/pages/api/projects/[slug]/domains/[domain]/links/count.ts b/pages/api/projects/[slug]/domains/[domain]/links/count.tsnew file mode 100644index 0000000000..38a27aea99--- /dev/null+++ b/pages/api/projects/[slug]/domains/[domain]/links/count.ts@@ -0,0 +1,22 @@+import { NextApiRequest, NextApiResponse } from "next";+import { getLinkCountForProject } from "@/lib/upstash";+import { withProjectAuth } from "@/lib/auth";++export default withProjectAuth(+ async (req: NextApiRequest, res: NextApiResponse) => {+ // GET /api/projects/[slug]/domains/[domain]/links/count – count the number of links for a project+ if (req.method === "GET") {+ const { domain } = req.query as { domain: string };+ if (!domain) {+ return res.status(400).json({ error: "Missing hostname" });+ }+ const count = await getLinkCountForProject(domain);+ return res.status(200).json(count);+ } else {+ res.setHeader("Allow", ["GET"]);+ return res+ .status(405)+ .json({ error: `Method ${req.method} Not Allowed` });+ }+ }+);diff --git a/pages/api/projects/[slug]/domains/[domain]/links/random.ts b/pages/api/projects/[slug]/domains/[domain]/links/random.tsindex 816e167afa..2c5fe137d0 100644--- a/pages/api/projects/[slug]/domains/[domain]/links/random.ts+++ b/pages/api/projects/[slug]/domains/[domain]/links/random.ts@@ -4,7 +4,7 @@ import { withProjectAuth } from "@/lib/auth";export default withProjectAuth(async (req: NextApiRequest, res: NextApiResponse) => {- // POST /api/links – create a new link+ // GET /api/projects/[slug]/domains/[domain]/links/random – get a random linkif (req.method === "GET") {const { domain } = req.query as { domain: string };if (!domain) {diff --git a/pages/app/[slug]/index.tsx b/pages/app/[slug]/index.tsxindex 06d42ecfda..03d8678d0f 100644--- a/pages/app/[slug]/index.tsx+++ b/pages/app/[slug]/index.tsx@@ -3,7 +3,7 @@ import { useRouter } from "next/router";import useSWR from "swr";import { fetcher } from "@/lib/utils";import LinkCard from "@/components/app/link-card";-import PlaceholderCard from "@/components/app/placeholder-card";+import LinkCardPlaceholder from "@/components/app/link-card-placeholder";import { useEffect } from "react";import { ProjectProps } from "@/lib/types";import MaxWidthWrapper from "@/components/shared/max-width-wrapper";@@ -70,7 +70,9 @@ export default function ProjectLinks() {/>)) : (- Array.from({ length: 3 }).map((_, i) => <PlaceholderCard key={i} />)+ Array.from({ length: 3 }).map((_, i) => (+ <LinkCardPlaceholder key={i} />+ )))}</div></MaxWidthWrapper>diff --git a/pages/app/index.tsx b/pages/app/index.tsxindex 8ddf37bd44..0af919b092 100644--- a/pages/app/index.tsx+++ b/pages/app/index.tsx@@ -6,6 +6,7 @@ import { ProjectProps } from "@/lib/types";import ProjectCard from "@/components/app/project-card";import { useAddProjectModal } from "@/components/app/add-project-modal";import NoProjectsPlaceholder from "@/components/app/no-projects-placeholder";+import ProjectCardPlaceholder from "@/components/app/project-card-placeholder";export default function App() {const { data } = useSWR<ProjectProps[]>(`/api/projects`, fetcher);@@ -41,7 +42,11 @@ export default function App() {setShowAddProjectModal={setShowAddProjectModal}/>)- ) : null}+ ) : (+ Array.from({ length: 6 }).map((_, i) => (+ <ProjectCardPlaceholder key={i} />+ ))+ )}</div></MaxWidthWrapper></AppLayout>diff --git a/pages/app/links/index.tsx b/pages/app/links/index.tsxindex 8acb4cfe74..b9c5e96019 100644--- a/pages/app/links/index.tsx+++ b/pages/app/links/index.tsx@@ -4,7 +4,7 @@ import { useRouter } from "next/router";import useSWR from "swr";import { fetcher } from "@/lib/utils";import LinkCard from "@/components/app/link-card";-import PlaceholderCard from "@/components/app/placeholder-card";+import LinkCardPlaceholder from "@/components/app/link-card-placeholder";import { LinkProps } from "@/lib/types";import { useAddLinkModal } from "@/components/app/add-link-modal";import NoLinksPlaceholder from "@/components/app/no-links-placeholder";@@ -41,7 +41,9 @@ export default function Links() {<NoLinksPlaceholder setShowAddLinkModal={setShowAddLinkModal} />)) : (- Array.from({ length: 3 }).map((_, i) => <PlaceholderCard key={i} />)+ Array.from({ length: 3 }).map((_, i) => (+ <LinkCardPlaceholder key={i} />+ )))}</div></MaxWidthWrapper>