The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
small improvement
Steven Teyc6fb8b0579b6
diff --git a/components/layout/app/index.tsx b/components/layout/app/index.tsxindex a6a2d0800f..68e69753d4 100644--- a/components/layout/app/index.tsx+++ b/components/layout/app/index.tsx@@ -22,11 +22,7 @@ import MaxWidthWrapper from "@/components/shared/max-width-wrapper";import { LoadingSpinner } from "#/ui/icons";import { FileX2 } from "lucide-react";import BlurImage from "#/ui/blur-image";--const NavTabs = dynamic(() => import("./nav-tabs"), {- ssr: false,- loading: () => <div className="-mb-0.5 h-12 w-full" />,-}); // dynamic import to avoid react hydration mismatch error+import NavTabs from "./nav-tabs";export default function AppLayout({children,@@ -124,43 +120,39 @@ export default function AppLayout({<Link href="/"><Logo className="h-8 w-8 transition-all duration-75 active:scale-95" /></Link>- {!loading && !error && (+ <Divider className="h-8 w-8 text-gray-200 sm:ml-3" />+ <ProjectSelect />+ {!error && key && (<>- <Divider className="h-8 w-8 text-gray-200 sm:ml-3" />- <ProjectSelect />- {key && (- <>- <Divider className="h-8 w-8 text-gray-200 sm:mr-3" />- <Link- href={- slug- ? `/${slug}/${domain}/${encodeURIComponent(key)}`- : `/links/${encodeURIComponent(key)}`- }- className="text-sm font-medium"- >- {linkConstructor({- domain: domain || "dub.sh",- key,- pretty: true,- })}- </Link>- </>- )}- {plan === "free" && showProBanner === false && (- <button- onClick={() => setShowUpgradePlanModal(true)}- className="mb-1 ml-3 hidden sm:block"- >- <Badge- text="Upgrade to Pro"- variant="blue"- className="px-3 py-1"- />- </button>- )}+ <Divider className="h-8 w-8 text-gray-200 sm:mr-3" />+ <Link+ href={+ slug+ ? `/${slug}/${domain}/${encodeURIComponent(key)}`+ : `/links/${encodeURIComponent(key)}`+ }+ className="text-sm font-medium"+ >+ {linkConstructor({+ domain: domain || "dub.sh",+ key,+ pretty: true,+ })}+ </Link></>)}+ {plan === "free" && showProBanner === false && (+ <button+ onClick={() => setShowUpgradePlanModal(true)}+ className="mb-1 ml-3 hidden sm:block"+ >+ <Badge+ text="Upgrade to Pro"+ variant="blue"+ className="px-3 py-1"+ />+ </button>+ )}</div><div className="flex items-center space-x-6"><a@@ -179,7 +171,7 @@ export default function AppLayout({<UserDropdown /></div></div>- {!loading && !error && <NavTabs />}+ <NavTabs /></MaxWidthWrapper></div>{loading || error?.status === 409 || error?.status === 410 ? (@@ -196,8 +188,9 @@ export default function AppLayout({Project Not Found</h1><p className="z-10 max-w-sm text-center text-sm text-gray-600">- The project you are looking for does not exist. Are you sure you- have the right link?+ Bummer! The project you are looking for does not exist. You+ either typed in the wrong URL or don't have access to this+ project.</p><BlurImagesrc="/_static/illustrations/coffee-call.svg"@@ -214,7 +207,7 @@ export default function AppLayout({</div></MaxWidthWrapper>) : (- <div>{children}</div>+ children)}</div></div>diff --git a/components/layout/app/nav-tabs.tsx b/components/layout/app/nav-tabs.tsxindex 9fa2b896d8..30ccf985b7 100644--- a/components/layout/app/nav-tabs.tsx+++ b/components/layout/app/nav-tabs.tsx@@ -6,6 +6,7 @@ import useDomains from "#/lib/swr/use-domains";import useLinksCount from "#/lib/swr/use-links-count";import useUsers from "#/lib/swr/use-users";import Badge from "#/ui/badge";+import useProject from "#/lib/swr/use-project";const TabsHelper = (router: NextRouter): { name: string; href: string }[] => {const { slug, domain, key } = router.query as {@@ -49,30 +50,38 @@ export default function NavTabs() {const { verified, loading } = useDomains();const { data: count } = useLinksCount();- return (- <div className="-mb-0.5 flex h-12 items-center justify-start space-x-2 overflow-x-auto scrollbar-hide">- {tabs.map(({ name, href }) => (- <Link- key={href}- href={href}- className={`border-b-2 p-1 ${- // hacky approach to getting the current tab – will replace with useSelectedLayoutSegments when upgrading to Next.js 13- router.asPath.split("?")[0].split("/").slice(0, 3).join("/") ===- href- ? "border-black text-black"- : "border-transparent text-gray-600 hover:text-black"- }`}- >- <div className="rounded-md px-3 py-2 transition-all duration-75 hover:bg-gray-100 active:bg-gray-200">- <p className="text-sm">{name}</p>- </div>- </Link>- ))}- {slug && !loading && (!verified || count === 0) && (- <OnboardingChecklist />- )}- </div>- );+ const { error, loading: projectLoading } = useProject();++ if (!router.isReady || projectLoading) {+ return <div className="-mb-0.5 h-12 w-full" />;+ }++ if (!error) {+ return (+ <div className="-mb-0.5 flex h-12 items-center justify-start space-x-2 overflow-x-auto scrollbar-hide">+ {tabs.map(({ name, href }) => (+ <Link+ key={href}+ href={href}+ className={`border-b-2 p-1 ${+ // hacky approach to getting the current tab – will replace with useSelectedLayoutSegments when upgrading to Next.js 13+ router.asPath.split("?")[0].split("/").slice(0, 3).join("/") ===+ href+ ? "border-black text-black"+ : "border-transparent text-gray-600 hover:text-black"+ }`}+ >+ <div className="rounded-md px-3 py-2 transition-all duration-75 hover:bg-gray-100 active:bg-gray-200">+ <p className="text-sm">{name}</p>+ </div>+ </Link>+ ))}+ {slug && !loading && (!verified || count === 0) && (+ <OnboardingChecklist />+ )}+ </div>+ );+ }}const OnboardingChecklist = () => {diff --git a/components/layout/app/project-select.tsx b/components/layout/app/project-select.tsxindex 4841b64084..105ca8d7a9 100644--- a/components/layout/app/project-select.tsx+++ b/components/layout/app/project-select.tsx@@ -11,9 +11,11 @@ import PlanBadge from "@/components/app/projects/plan-badge";import { GOOGLE_FAVICON_URL } from "#/lib/constants";import { ModalContext } from "#/ui/modal-provider";import Link from "next/link";+import useProject from "#/lib/swr/use-project";export default function ProjectSelect() {const { projects } = useProjects();+ const { error, loading } = useProject();const router = useRouter();const { slug, key } = router.query as {@@ -24,7 +26,7 @@ export default function ProjectSelect() {const { data: session } = useSession();const selected = useMemo(() => {- if (slug && projects) {+ if (slug && projects && !error) {const selectedProject = projects?.find((project) => project.slug === slug,);@@ -34,6 +36,8 @@ export default function ProjectSelect() {selectedProject?.logo ||`${GOOGLE_FAVICON_URL}${selectedProject?.primaryDomain?.slug}`,};++ // return personal account selector if there's no project or error (user doesn't have access to project)} else {return {name: session?.user?.name || session?.user?.email,@@ -44,7 +48,7 @@ export default function ProjectSelect() {plan: "free",};}- }, [slug, projects, session]) as {+ }, [slug, projects, session, error]) as {id?: string;name: string;slug: string;@@ -54,14 +58,15 @@ export default function ProjectSelect() {const [openPopover, setOpenPopover] = useState(false);- if (!projects || !router.isReady)+ if (!router.isReady || !projects || loading) {return (- <div className="flex animate-pulse items-center justify-end space-x-1.5 rounded-lg px-1.5 py-2 sm:w-60">+ <div className="flex animate-pulse items-center space-x-1.5 rounded-lg px-1.5 py-2 sm:w-60"><div className="h-8 w-8 animate-pulse rounded-full bg-gray-200" /><div className="hidden h-8 w-28 animate-pulse rounded-md bg-gray-200 sm:block sm:w-40" /><ChevronsUpDown className="h-4 w-4 text-gray-400" aria-hidden="true" /></div>);+ }return (<div>