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.

looking good :eyes:

Steven Tey813f603b0137
diff --git a/components/app/add-modal.tsx b/components/app/add-modal.tsx
index fe0a3cc963..040b7d5ac3 100644
--- a/components/app/add-modal.tsx
+++ b/components/app/add-modal.tsx
@@ -1,63 +1,268 @@
import Modal from "@/components/shared/modal";
import {
useCallback,
+ useEffect,
useMemo,
useState,
Dispatch,
SetStateAction,
} from "react";
-import LoadingDots from "@/components/shared/icons/loading-dots";
+import BlurImage from "@/components/shared/blur-image";
+import { LinkProps } from "@/lib/types";
+import {
+ LoadingDots,
+ LoadingCircle,
+ AlertCircleFill,
+} from "@/components/shared/icons";
+import { useDebounce } from "use-debounce";
+import TextareaAutosize from "react-textarea-autosize";
+import { mutate } from "swr";
function AddModalHelper({
showAddModal,
setShowAddModal,
+ slug,
}: {
showAddModal: boolean;
setShowAddModal: Dispatch<SetStateAction<boolean>>;
+ slug?: string;
}) {
- const [signInClicked, setSignInClicked] = useState(false);
- const [buttonText, setButtonText] = useState("Sign in with magic link");
+ const [keyExistsError, setKeyExistsError] = useState(false);
+ const [generatingSlug, setGeneratingSlug] = useState(false);
+ const [generatingTitle, setGeneratingTitle] = useState(false);
+ const [buttonText, setButtonText] = useState("Save changes");
+ const [saving, setSaving] = useState(false);
+
+ const [data, setData] = useState<LinkProps>({
+ key: "",
+ url: "",
+ title: "",
+ timestamp: Date.now(),
+ });
+ const { key, url, title } = data;
+
+ const [debouncedKey] = useDebounce(key, 500);
+ useEffect(() => {
+ if (debouncedKey.length > 0) {
+ fetch(
+ slug
+ ? `/api/projects/${slug}/links/${debouncedKey}/exists`
+ : `/api/edge/links/${debouncedKey}/exists`
+ ).then(async (res) => {
+ if (res.status === 200) {
+ const exists = await res.json();
+ setKeyExistsError(exists === 1);
+ }
+ });
+ }
+ }, [debouncedKey]);
+
+ const generateRandomSlug = useCallback(async () => {
+ setGeneratingSlug(true);
+ const res = await fetch(
+ slug ? `/api/projects/${slug}/links/random` : `/api/edge/links/random`
+ );
+ const key = await res.json();
+ setData((prev) => ({ ...prev, key }));
+ setGeneratingSlug(false);
+ }, []);
+
+ const [debouncedUrl] = useDebounce(url, 500);
+ useEffect(() => {
+ if (debouncedUrl.length > 0 && title.length === 0) {
+ // only fetch title if user hasn't entered one
+ generateTitleFromUrl(debouncedUrl);
+ }
+ }, [debouncedUrl]);
+
+ const generateTitleFromUrl = useCallback(
+ (debouncedUrl: string) => {
+ setGeneratingTitle(true);
+ fetch(`/api/edge/title?url=${debouncedUrl}`).then(async (res) => {
+ if (res.status === 200) {
+ const results = await res.json();
+ setData((prev) => ({ ...prev, title: results }));
+ setGeneratingTitle(false);
+ }
+ });
+ },
+ [debouncedUrl]
+ );
return (
<Modal showModal={showAddModal} setShowModal={setShowAddModal}>
- <div className="inline-block w-full max-w-md py-8 px-4 sm:px-16 overflow-hidden text-center align-middle transition-all transform bg-white shadow-xl rounded-2xl">
- <div>
- <h3 className="font-serif font-bold text-3xl mb-4 tracking-wide">
- Add a new link
- </h3>
- <p className="text-sm text-gray-500">
- Shorten a link and give it a custom URL.
- </p>
+ <div className="inline-block w-full max-w-md overflow-hidden align-middle transition-all transform bg-white shadow-xl rounded-2xl">
+ <div className="flex flex-col justify-center items-center space-y-3 sm:px-16 px-4 pt-8 py-4 border-b border-gray-200">
+ <BlurImage
+ src={`/static/logo.png`}
+ alt={"dub.sh"}
+ className="w-10 h-10 rounded-full border border-gray-200 dark:border-gray-600"
+ width={20}
+ height={20}
+ />
+ <h3 className="font-medium text-lg">Add a new link</h3>
</div>
<form
onSubmit={async (e) => {
e.preventDefault();
- setSignInClicked(true);
+ setSaving(true);
+ fetch(slug ? `/api/projects/${slug}/links` : `/api/links`, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify(data),
+ })
+ .then((res) => {
+ setSaving(false);
+ if (res.status === 200) {
+ setButtonText("Saved!");
+ mutate(slug ? `/api/projects/${slug}` : `/api/links`);
+ setTimeout(() => {
+ setButtonText("Save changes");
+ });
+ setShowAddModal(false);
+ }
+ })
+ .catch(() => {
+ setSaving(false);
+ setButtonText("Save changes");
+ setKeyExistsError(true);
+ });
}}
- className="mt-5 flex flex-col space-y-4"
+ className="flex flex-col space-y-6 text-left bg-gray-50 sm:px-16 px-4 py-8"
>
- <input
- name="email"
- type="email"
- placeholder="Email Address"
- autoComplete="email"
- required
- className="appearance-none block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-black focus:border-black sm:text-sm"
- />
+ <div>
+ <div className="flex justify-between items-center">
+ <label
+ htmlFor="key"
+ className="block text-sm font-medium text-gray-700"
+ >
+ Short Link
+ </label>
+ <button
+ className="hover:text-black active:scale-95 flex items-center text-gray-500 text-sm transition-all duration-75"
+ onClick={generateRandomSlug}
+ disabled={generatingSlug}
+ type="button"
+ >
+ {generatingSlug && <LoadingCircle />}
+ <p>{generatingSlug ? "Generating" : "Generate random slug"}</p>
+ </button>
+ </div>
+ <div className="relative flex mt-1 rounded-md shadow-sm">
+ <span className="inline-flex items-center rounded-l-md border border-r-0 border-gray-300 bg-gray-50 px-5 text-gray-500 sm:text-sm">
+ {slug || "dub.sh"}
+ </span>
+ <input
+ type="text"
+ name="key"
+ id="key"
+ required
+ autoFocus={false}
+ className={`${
+ keyExistsError
+ ? "border-red-300 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
+ : "border-gray-300 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:ring-gray-500"
+ } pr-10 block w-full rounded-r-md focus:outline-none sm:text-sm`}
+ placeholder="github"
+ value={key}
+ onChange={(e) => {
+ setKeyExistsError(false);
+ setData({ ...data, key: e.target.value });
+ }}
+ aria-invalid="true"
+ aria-describedby="key-error"
+ />
+ {keyExistsError && (
+ <div className="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3">
+ <AlertCircleFill
+ className="h-5 w-5 text-red-500"
+ aria-hidden="true"
+ />
+ </div>
+ )}
+ </div>
+ {keyExistsError && (
+ <p className="mt-2 text-sm text-red-600" id="key-error">
+ Short link is already in use.
+ </p>
+ )}
+ </div>
+
+ <div>
+ <label
+ htmlFor="url"
+ className="block text-sm font-medium text-gray-700"
+ >
+ Destination URL
+ </label>
+ <div className="flex mt-1 rounded-md shadow-sm">
+ <input
+ name="url"
+ id="url"
+ type="url"
+ required
+ className="border-gray-300 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:ring-gray-500 block w-full rounded-md focus:outline-none sm:text-sm"
+ placeholder="https://github.com/steven-tey/dub"
+ value={url}
+ onChange={(e) => {
+ setData({ ...data, url: e.target.value });
+ }}
+ aria-invalid="true"
+ />
+ </div>
+ </div>
+
+ <div>
+ <div className="flex justify-between items-center">
+ <label
+ htmlFor="title"
+ className="block text-sm font-medium text-gray-700"
+ >
+ Title
+ </label>
+ <button
+ className={`${
+ url.length === 0
+ ? "cursor-not-allowed text-gray-300"
+ : "hover:text-black active:scale-95"
+ } flex items-center text-gray-500 text-sm transition-all duration-75`}
+ onClick={() => generateTitleFromUrl(url)}
+ disabled={url.length === 0 || generatingTitle}
+ type="button"
+ >
+ {generatingTitle && <LoadingCircle />}
+ <p>{generatingTitle ? "Generating" : "Generate from URL"}</p>
+ </button>
+ </div>
+ <div className="flex mt-1 rounded-md shadow-sm">
+ <TextareaAutosize
+ name="title"
+ id="title"
+ required
+ minRows={3}
+ className="border-gray-300 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:ring-gray-500 pr-10 block w-full rounded-md focus:outline-none sm:text-sm"
+ placeholder="Dub - an open-source link shortener with built-in analytics + free custom domains."
+ value={title}
+ onChange={(e) => {
+ setData({ ...data, title: e.target.value });
+ }}
+ aria-invalid="true"
+ />
+ </div>
+ </div>
+
<button
- disabled={signInClicked}
+ disabled={saving || keyExistsError}
className={`${
- signInClicked
- ? "cursor-not-allowed bg-gray-100 border-gray-200"
- : "bg-black hover:bg-white text-white hover:text-black border-black"
+ saving || keyExistsError
+ ? "cursor-not-allowed bg-gray-100 border-gray-200 text-gray-400"
+ : "bg-black hover:bg-white hover:text-black border-black text-white"
} flex justify-center items-center w-full text-sm h-10 rounded-md border transition-all focus:outline-none`}
>
- {signInClicked ? (
- <LoadingDots color="#808080" />
- ) : (
- <p>{buttonText}</p>
- )}
+ {saving ? <LoadingDots color="#808080" /> : <p>{buttonText}</p>}
</button>
</form>
</div>
@@ -65,7 +270,7 @@ function AddModalHelper({
);
}
-export function useAddModal() {
+export function useAddModal({ slug }: { slug?: string }) {
const [showAddModal, setShowAddModal] = useState(false);
const AddModal = useCallback(() => {
@@ -73,9 +278,10 @@ export function useAddModal() {
<AddModalHelper
showAddModal={showAddModal}
setShowAddModal={setShowAddModal}
+ slug={slug}
/>
);
- }, [showAddModal, setShowAddModal]);
+ }, [showAddModal, setShowAddModal, slug]);
return useMemo(
() => ({ setShowAddModal, AddModal }),
diff --git a/components/layout/app/index.tsx b/components/layout/app/index.tsx
index 65bd1e46fa..0f9546452d 100644
--- a/components/layout/app/index.tsx
+++ b/components/layout/app/index.tsx
@@ -33,7 +33,7 @@ export default function AppLayout({ children }: { children: ReactNode }) {
<NavTabs />
</div>
</div>
- <div className="max-w-screen-xl mx-auto px-5 sm:px-20">{children}</div>
+ <div>{children}</div>
</div>
</div>
);
diff --git a/components/shared/icons/index.tsx b/components/shared/icons/index.tsx
index a2b50ca675..03f6e099e4 100644
--- a/components/shared/icons/index.tsx
+++ b/components/shared/icons/index.tsx
@@ -1,4 +1,5 @@
export { default as LoadingDots } from "./loading-dots";
+export { default as LoadingCircle } from "./loading-circle";
export { default as ExpandingArrow } from "./expanding-arrow";
export { default as Tick } from "./tick";
export { default as Copy } from "./copy";
diff --git a/components/shared/icons/loading-circle.tsx b/components/shared/icons/loading-circle.tsx
new file mode 100644
index 0000000000..8926f0eae8
--- /dev/null
+++ b/components/shared/icons/loading-circle.tsx
@@ -0,0 +1,20 @@
+export default function LoadingCircle({ className }: { className?: string }) {
+ return (
+ <svg
+ aria-hidden="true"
+ className="mr-2 w-4 h-4 text-gray-200 animate-spin dark:text-gray-600 fill-gray-600"
+ viewBox="0 0 100 101"
+ fill="none"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
+ fill="currentColor"
+ />
+ <path
+ d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
+ fill="currentFill"
+ />
+ </svg>
+ );
+}
diff --git a/components/shared/max-width-wrapper.tsx b/components/shared/max-width-wrapper.tsx
new file mode 100644
index 0000000000..4df68d04ab
--- /dev/null
+++ b/components/shared/max-width-wrapper.tsx
@@ -0,0 +1,9 @@
+import { ReactNode } from "react";
+
+export default function MaxWidthWrapper({ children }: { children: ReactNode }) {
+ return (
+ <div className="w-full max-w-screen-xl mx-auto px-5 sm:px-20">
+ {children}
+ </div>
+ );
+}
diff --git a/lib/upstash.ts b/lib/upstash.ts
index 8e466ecdc2..f195351484 100644
--- a/lib/upstash.ts
+++ b/lib/upstash.ts
@@ -53,6 +53,18 @@ export async function setRandomKey(
}
}
+export async function getRandomKey(hostname: string): Promise<string> {
+ /* recursively get random key till it gets one that's avaialble */
+ const key = nanoid();
+ const response = await redis.hexists(`${hostname}:links`, key); // check if key exists
+ if (response === 1) {
+ // by the off chance that key already exists
+ return getRandomKey(hostname);
+ } else {
+ return key;
+ }
+}
+
export async function checkIfKeyExists(hostname: string, key: string) {
return await redis.hexists(`${hostname}:links`, key);
}
diff --git a/pages/api/edge/links/random.ts b/pages/api/edge/links/random.ts
new file mode 100644
index 0000000000..4ec6374a73
--- /dev/null
+++ b/pages/api/edge/links/random.ts
@@ -0,0 +1,15 @@
+import type { NextRequest } from "next/server";
+import { getRandomKey } from "@/lib/upstash";
+
+export const config = {
+ runtime: "experimental-edge",
+};
+
+export default async function handler(req: NextRequest) {
+ if (req.method === "GET") {
+ const key = await getRandomKey("dub.sh");
+ return new Response(JSON.stringify(key), { status: 200 });
+ } else {
+ return new Response(`Method ${req.method} Not Allowed`, { status: 405 });
+ }
+}
diff --git a/pages/api/edge/title.ts b/pages/api/edge/title.ts
new file mode 100644
index 0000000000..1a33bd8164
--- /dev/null
+++ b/pages/api/edge/title.ts
@@ -0,0 +1,19 @@
+import type { NextRequest } from "next/server";
+import { getTitleFromUrl } from "@/lib/utils";
+
+export const config = {
+ runtime: "experimental-edge",
+};
+
+export default async function handler(req: NextRequest) {
+ if (req.method === "GET") {
+ const url = req.nextUrl.searchParams.get("url");
+ if (!url) {
+ return new Response("Missing url", { status: 400 });
+ }
+ const title = await getTitleFromUrl(url);
+ return new Response(JSON.stringify(title), { status: 200 });
+ } else {
+ return new Response(`Method ${req.method} Not Allowed`, { status: 405 });
+ }
+}
diff --git a/pages/api/links/index.ts b/pages/api/links/index.ts
index b1352c906a..a034369e5b 100644
--- a/pages/api/links/index.ts
+++ b/pages/api/links/index.ts
@@ -20,7 +20,7 @@ export default async function handler(
} else if (req.method === "POST") {
let { key, url, title } = req.body;
if (!url) {
- return res.status(400).json({ error: "Missing key or url" });
+ return res.status(400).json({ error: "Missing url" });
}
const response = await addLink("dub.sh", url, key, title, session.user.id);
if (response === null) {
diff --git a/pages/api/projects/[slug]/links/index.ts b/pages/api/projects/[slug]/links/index.ts
index b82927cb6c..bc5e1bb508 100644
--- a/pages/api/projects/[slug]/links/index.ts
+++ b/pages/api/projects/[slug]/links/index.ts
@@ -1,38 +1,23 @@
import { NextApiRequest, NextApiResponse } from "next";
-import { redis, setKey } from "@/lib/upstash";
+import { addLink } from "@/lib/upstash";
import { withProjectAuth } from "@/lib/auth";
export default withProjectAuth(
async (req: NextApiRequest, res: NextApiResponse) => {
// POST /api/links – create a new link
if (req.method === "POST") {
- let { hostname, key, url } = req.body;
- if (!hostname || !key || !url) {
- return res.status(400).json({ error: "Missing hostname, key or url" });
+ const { slug } = req.query as { slug: string };
+ let { key, url, title } = req.body;
+ if (!slug || !url) {
+ return res.status(400).json({ error: "Missing hostname or url" });
}
-
- const response = await setKey(hostname, key, url);
- if (response === 1) {
- const pipeline = redis.pipeline();
- pipeline.zadd(`${hostname}:links:timestamps`, {
- score: Date.now(),
- member: key,
- });
- pipeline.zadd(`${hostname}:links:clicks`, {
- score: 0,
- member: key,
- });
- return res.status(200).json({
- key,
- url,
- });
- } else {
- return res.status(500).json({
- error: "Failed to save link",
- });
+ const response = await addLink(slug, url, key, title);
+ if (response === null) {
+ return res.status(400).json({ error: "Key already exists" });
}
+ return res.status(200).json({ key, url, title });
} else {
- res.setHeader("Allow", ["GET", "POST"]);
+ res.setHeader("Allow", ["POST"]);
return res
.status(405)
.json({ error: `Method ${req.method} Not Allowed` });
diff --git a/pages/api/projects/[slug]/links/random.ts b/pages/api/projects/[slug]/links/random.ts
new file mode 100644
index 0000000000..26269e4c82
--- /dev/null
+++ b/pages/api/projects/[slug]/links/random.ts
@@ -0,0 +1,22 @@
+import { NextApiRequest, NextApiResponse } from "next";
+import { getRandomKey } from "@/lib/upstash";
+import { withProjectAuth } from "@/lib/auth";
+
+export default withProjectAuth(
+ async (req: NextApiRequest, res: NextApiResponse) => {
+ // POST /api/links – create a new link
+ if (req.method === "GET") {
+ const { slug } = req.query as { slug: string };
+ if (!slug) {
+ return res.status(400).json({ error: "Missing hostname" });
+ }
+ const key = await getRandomKey(slug);
+ return res.status(200).json(key);
+ } else {
+ res.setHeader("Allow", ["GET"]);
+ return res
+ .status(405)
+ .json({ error: `Method ${req.method} Not Allowed` });
+ }
+ }
+);
diff --git a/pages/app/[slug]/[key].tsx b/pages/app/[slug]/[key].tsx
index a845933500..4a00f1bdbd 100644
--- a/pages/app/[slug]/[key].tsx
+++ b/pages/app/[slug]/[key].tsx
@@ -1,10 +1,10 @@
import Stats from "@/components/stats";
-import HomeLayout from "@/components/layout/home";
+import AppLayout from "@/components/layout/app";
export default function StatsPage() {
return (
- <HomeLayout>
+ <AppLayout>
<Stats />
- </HomeLayout>
+ </AppLayout>
);
}
diff --git a/pages/app/[slug]/index.tsx b/pages/app/[slug]/index.tsx
index d5c856cbaa..697c46a102 100644
--- a/pages/app/[slug]/index.tsx
+++ b/pages/app/[slug]/index.tsx
@@ -6,6 +6,8 @@ import LinkCard from "@/components/app/link-card";
import PlaceholderCard from "@/components/app/placeholder-card";
import { useEffect } from "react";
import { ProjectProps } from "@/lib/types";
+import MaxWidthWrapper from "@/components/shared/max-width-wrapper";
+import { useAddModal } from "@/components/app/add-modal";
export default function ProjectLinks() {
const router = useRouter();
@@ -24,17 +26,35 @@ export default function ProjectLinks() {
}
}, [error]);
+ const { setShowAddModal, AddModal } = useAddModal({ slug });
+
return (
<AppLayout>
- <div className="my-10 grid grid-cols-1 gap-3">
- {data?.links && data.links.length > 0
- ? data.links.map((props) => (
- <LinkCard key={props.key} props={props} slug={slug} />
- ))
- : Array.from({ length: 3 }).map((_, i) => (
- <PlaceholderCard key={i} />
- ))}
+ <AddModal />
+ <div className="py-12 bg-white border-b border-gray-200">
+ <MaxWidthWrapper>
+ <div className="flex justify-between items-center">
+ <h1 className="text-2xl text-gray-600">Links</h1>
+ <button
+ onClick={() => setShowAddModal(true)}
+ className="font-medium text-sm text-gray-500 px-5 py-2 border rounded-md border-gray-200 dark:border-gray-600 hover:border-black dark:hover:border-white active:scale-95 transition-all duration-75"
+ >
+ Add
+ </button>
+ </div>
+ </MaxWidthWrapper>
</div>
+ <MaxWidthWrapper>
+ <div className="my-10 grid grid-cols-1 gap-3">
+ {data?.links && data.links.length > 0
+ ? data.links.map((props) => (
+ <LinkCard key={props.key} props={props} slug={slug} />
+ ))
+ : Array.from({ length: 3 }).map((_, i) => (
+ <PlaceholderCard key={i} />
+ ))}
+ </div>
+ </MaxWidthWrapper>
</AppLayout>
);
}
diff --git a/pages/app/index.tsx b/pages/app/index.tsx
index eadb5fb462..665011008f 100644
--- a/pages/app/index.tsx
+++ b/pages/app/index.tsx
@@ -1,5 +1,5 @@
import AppLayout from "components/layout/app";
-import Link from "next/link";
+import MaxWidthWrapper from "@/components/shared/max-width-wrapper";
import useSWR from "swr";
import { fetcher } from "@/lib/utils";
import { ProjectProps } from "@/lib/types";
@@ -10,9 +10,11 @@ export default function App() {
return (
<AppLayout>
- <div className="my-10 grid grid-cols-1 sm:grid-cols-3 gap-5">
- {data ? data.map((d) => <ProjectCard {...d} />) : null}
- </div>
+ <MaxWidthWrapper>
+ <div className="my-10 grid grid-cols-1 sm:grid-cols-3 gap-5">
+ {data ? data.map((d) => <ProjectCard {...d} />) : null}
+ </div>
+ </MaxWidthWrapper>
</AppLayout>
);
}
diff --git a/pages/app/links/[key].tsx b/pages/app/links/[key].tsx
index a845933500..4a00f1bdbd 100644
--- a/pages/app/links/[key].tsx
+++ b/pages/app/links/[key].tsx
@@ -1,10 +1,10 @@
import Stats from "@/components/stats";
-import HomeLayout from "@/components/layout/home";
+import AppLayout from "@/components/layout/app";
export default function StatsPage() {
return (
- <HomeLayout>
+ <AppLayout>
<Stats />
- </HomeLayout>
+ </AppLayout>
);
}
diff --git a/pages/app/links/index.tsx b/pages/app/links/index.tsx
index 0dac85fcf4..44bc4c6946 100644
--- a/pages/app/links/index.tsx
+++ b/pages/app/links/index.tsx
@@ -1,25 +1,45 @@
import AppLayout from "components/layout/app";
+import MaxWidthWrapper from "@/components/shared/max-width-wrapper";
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 { LinkProps } from "@/lib/types";
+import { useAddModal } from "@/components/app/add-modal";
export default function Links() {
const router = useRouter();
const { data } = useSWR<LinkProps[]>(router.isReady && `/api/links`, fetcher);
+ const { setShowAddModal, AddModal } = useAddModal({});
+
return (
<AppLayout>
- <div className="my-10 grid grid-cols-1 gap-3">
- {data && data.length > 0
- ? data.map((props) => <LinkCard key={props.key} props={props} />)
- : Array.from({ length: 3 }).map((_, i) => (
- <PlaceholderCard key={i} />
- ))}
+ <AddModal />
+ <div className="py-12 bg-white border-b border-gray-200">
+ <MaxWidthWrapper>
+ <div className="flex justify-between items-center">
+ <h1 className="text-2xl text-gray-600">Links</h1>
+ <button
+ onClick={() => setShowAddModal(true)}
+ className="font-medium text-sm text-gray-500 px-5 py-2 border rounded-md border-gray-200 dark:border-gray-600 hover:border-black dark:hover:border-white active:scale-95 transition-all duration-75"
+ >
+ Add
+ </button>
+ </div>
+ </MaxWidthWrapper>
</div>
+ <MaxWidthWrapper>
+ <div className="my-10 grid grid-cols-1 gap-3">
+ {data && data.length > 0
+ ? data.map((props) => <LinkCard key={props.key} props={props} />)
+ : Array.from({ length: 3 }).map((_, i) => (
+ <PlaceholderCard key={i} />
+ ))}
+ </div>
+ </MaxWidthWrapper>
</AppLayout>
);
}