The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fix / bug, disable link preview tooltip on mobile
Steven Teyb08df65d5cef
diff --git a/apps/web/ui/stats/bar-list.tsx b/apps/web/ui/stats/bar-list.tsxindex 08a30da7ea..07d1fb2617 100644--- a/apps/web/ui/stats/bar-list.tsx+++ b/apps/web/ui/stats/bar-list.tsx@@ -1,25 +1,12 @@"use client";-import { UserProps } from "@/lib/types";-import { Avatar, CopyButton, NumberTooltip, Tooltip } from "@dub/ui";-import {- GOOGLE_FAVICON_URL,- cn,- fetcher,- getApexDomain,- linkConstructor,- nFormatter,- timeAgo,-} from "@dub/utils";-import { Link as LinkProps } from "@prisma/client";+import { NumberTooltip, Tooltip } from "@dub/ui";+import { cn, nFormatter } from "@dub/utils";import { motion } from "framer-motion";-import { Archive, EyeOff, Globe, Search, Trash } from "lucide-react";+import { Search } from "lucide-react";import Link from "next/link";-import { useParams } from "next/navigation";import { Dispatch, ReactNode, SetStateAction, useMemo, useState } from "react";-import useSWR from "swr";-import { BlurImage } from "../shared/blur-image";-import punycode from "punycode/";+import LinkPreviewTooltip from "./link-preview";export default function BarList({tab,@@ -82,14 +69,7 @@ export default function BarList({<div key={idx} className="group flex items-center justify-between"><div className="relative z-10 flex w-full max-w-[calc(100%-2rem)] items-center">{tab === "Top Links" ? (- <Tooltip- content={- <LinkPreviewTooltip- domain={title.split("/")[0]}- _key={title.split("/")[1]}- />- }- >+ <Tooltip content={<LinkPreviewTooltip link={title} />}>{lineItem}</Tooltip>) : (@@ -152,157 +132,3 @@ export default function BarList({);}}--const LinkPreviewTooltip = ({- domain,- _key,-}: {- domain: string;- _key?: string;-}) => {- const key = _key;- const { slug } = useParams() as { slug?: string };- const { data, isLoading } = useSWR<- LinkProps & {- user: UserProps;- }- >(- key- ? `/api${- slug ? `/projects/${slug}` : ""- }/links/info?domain=${domain}&key=${key}`- : `/api/projects/${slug}/domains/${domain}`,- fetcher,- {- dedupingInterval: 60000,- },- );- if (isLoading) {- return (- <div className="relative flex w-[28rem] items-center px-4 py-2">- <div className="mr-2 h-8 w-8 animate-pulse rounded-full bg-gray-200 sm:h-10 sm:w-10" />- <div className="flex flex-col space-y-2">- <div className="flex items-center space-x-2">- <div className="h-5 w-40 animate-pulse rounded-md bg-gray-200" />- <div className="h-5 w-5 animate-pulse rounded-full bg-gray-200" />- </div>- <div className="flex items-center space-x-2">- <div className="h-5 w-5 animate-pulse rounded-full bg-gray-200" />- <div className="h-5 w-20 animate-pulse rounded-md bg-gray-200" />- <div className="h-5 w-48 animate-pulse rounded-md bg-gray-200" />- </div>- </div>- </div>- );- }- if (!data) {- return (- <div className="relative flex w-[28rem] items-center space-x-3 px-4 py-2">- <div className="flex h-8 w-8 items-center justify-center rounded-full bg-gray-300 px-0 sm:h-10 sm:w-10">- <Trash className="h-4 w-4 text-gray-500 sm:h-5 sm:w-5" />- </div>- <div className="flex flex-col space-y-1">- <p className="w-full max-w-[140px] truncate text-sm font-semibold text-gray-500 line-through sm:max-w-[300px] sm:text-base md:max-w-[360px] xl:max-w-[500px]">- {linkConstructor({- domain: punycode.toUnicode(domain || ""),- key,- pretty: true,- })}- </p>- <p className="text-sm text-gray-500">This link has been deleted.</p>- </div>- </div>- );- }-- const { url, rewrite, createdAt, archived, user } = data;- const apexDomain = getApexDomain(url);-- return (- <div className="relative flex w-[28rem] items-center justify-between px-4 py-2">- <div className="relative flex shrink items-center">- {archived ? (- <div className="flex h-8 w-8 items-center justify-center rounded-full bg-gray-300 px-0 sm:h-10 sm:w-10">- <Archive className="h-4 w-4 text-gray-500 sm:h-5 sm:w-5" />- </div>- ) : url ? (- <BlurImage- src={`${GOOGLE_FAVICON_URL}${apexDomain}`}- alt={apexDomain}- className="h-8 w-8 rounded-full sm:h-10 sm:w-10"- width={20}- height={20}- />- ) : (- <div className="flex h-8 w-8 items-center justify-center rounded-full border border-gray-300 px-0 sm:h-10 sm:w-10">- <Globe className="h-4 w-4 text-gray-500 sm:h-5 sm:w-5" />- </div>- )}- {/*- Here, we're manually setting ml-* values because if we do space-x-* in the parent div,- it messes up the tooltip positioning.- */}- <div className="ml-2 sm:ml-4">- <div className="flex max-w-fit items-center space-x-2">- <a- className={cn(- "w-full max-w-[140px] truncate text-sm font-semibold text-blue-800 sm:max-w-[300px] sm:text-base md:max-w-[360px] xl:max-w-[500px]",- {- "text-gray-500": archived,- },- )}- href={linkConstructor({ domain, key })}- target="_blank"- rel="noreferrer"- onClick={(e) => e.stopPropagation()}- >- {linkConstructor({- domain: punycode.toUnicode(domain || ""),- key,- pretty: true,- })}- </a>- <CopyButton value={linkConstructor({ domain, key })} />- </div>- <div className="flex max-w-fit items-center space-x-1">- {user && (- <>- <Avatar user={user} className="h-4 w-4" />- <p>•</p>- </>- )}- {createdAt && (- <>- <p- className="whitespace-nowrap text-sm text-gray-500"- suppressHydrationWarning- >- {timeAgo(createdAt)}- </p>- <p>•</p>- </>- )}- {rewrite && (- <EyeOff className="xs:block hidden h-4 w-4 text-gray-500" />- )}- {url ? (- <a- href={url}- target="_blank"- rel="noopener noreferrer"- onClick={(e) => e.stopPropagation()}- className="xs:block hidden max-w-[240px] truncate text-sm font-medium text-gray-700 underline-offset-2 hover:underline"- >- {url}- </a>- ) : (- <p className="xs:block hidden max-w-[240px] truncate text-sm font-medium text-gray-700 underline-offset-2 hover:underline">- No redirect configured- </p>- )}- </div>- </div>- </div>- </div>- );-};diff --git a/apps/web/ui/stats/link-preview.tsx b/apps/web/ui/stats/link-preview.tsxnew file mode 100644index 0000000000..2346b89cfb--- /dev/null+++ b/apps/web/ui/stats/link-preview.tsx@@ -0,0 +1,170 @@+import { UserProps } from "@/lib/types";+import { Avatar, CopyButton } from "@dub/ui";+import {+ GOOGLE_FAVICON_URL,+ cn,+ fetcher,+ getApexDomain,+ linkConstructor,+ timeAgo,+} from "@dub/utils";+import { Link as LinkProps } from "@prisma/client";+import { Archive, EyeOff, Globe, Trash } from "lucide-react";+import { useParams } from "next/navigation";+import useSWR from "swr";+import { BlurImage } from "../shared/blur-image";+import punycode from "punycode/";++export default function LinkPreviewTooltip({+ link,+}: {+ // link is in the format dub.sh/github+ link: string;+}) {+ const domain = link.split("/")[0];+ const key = link.split("/").slice(1).join("/");+ const { slug } = useParams() as { slug?: string };+ const { data, isLoading } = useSWR<+ LinkProps & {+ user: UserProps;+ }+ >(+ key+ ? `/api${+ slug ? `/projects/${slug}` : ""+ }/links/info?domain=${domain}&key=${key}`+ : `/api/projects/${slug}/domains/${domain}`,+ fetcher,+ {+ dedupingInterval: 60000,+ },+ );+ if (isLoading) {+ return (+ <div className="relative flex w-[28rem] items-center px-4 py-2">+ <div className="mr-2 h-8 w-8 animate-pulse rounded-full bg-gray-200 sm:h-10 sm:w-10" />+ <div className="flex flex-col space-y-2">+ <div className="flex items-center space-x-2">+ <div className="h-5 w-40 animate-pulse rounded-md bg-gray-200" />+ <div className="h-5 w-5 animate-pulse rounded-full bg-gray-200" />+ </div>+ <div className="flex items-center space-x-2">+ <div className="h-5 w-5 animate-pulse rounded-full bg-gray-200" />+ <div className="h-5 w-20 animate-pulse rounded-md bg-gray-200" />+ <div className="h-5 w-48 animate-pulse rounded-md bg-gray-200" />+ </div>+ </div>+ </div>+ );+ }+ if (!data) {+ return (+ <div className="relative flex w-[28rem] items-center space-x-3 px-4 py-2">+ <div className="flex h-8 w-8 items-center justify-center rounded-full bg-gray-300 px-0 sm:h-10 sm:w-10">+ <Trash className="h-4 w-4 text-gray-500 sm:h-5 sm:w-5" />+ </div>+ <div className="flex flex-col space-y-1">+ <p className="w-full max-w-[140px] truncate text-sm font-semibold text-gray-500 line-through sm:max-w-[300px] sm:text-base md:max-w-[360px] xl:max-w-[500px]">+ {linkConstructor({+ domain: punycode.toUnicode(domain || ""),+ key,+ pretty: true,+ })}+ </p>+ <p className="text-sm text-gray-500">This link has been deleted.</p>+ </div>+ </div>+ );+ }++ const { url, rewrite, createdAt, archived, user } = data;+ const apexDomain = getApexDomain(url);++ return (+ <div className="relative flex w-[28rem] items-center justify-between px-4 py-2">+ <div className="relative flex shrink items-center">+ {archived ? (+ <div className="flex h-8 w-8 items-center justify-center rounded-full bg-gray-300 px-0 sm:h-10 sm:w-10">+ <Archive className="h-4 w-4 text-gray-500 sm:h-5 sm:w-5" />+ </div>+ ) : url ? (+ <BlurImage+ src={`${GOOGLE_FAVICON_URL}${apexDomain}`}+ alt={apexDomain}+ className="h-8 w-8 rounded-full sm:h-10 sm:w-10"+ width={20}+ height={20}+ />+ ) : (+ <div className="flex h-8 w-8 items-center justify-center rounded-full border border-gray-300 px-0 sm:h-10 sm:w-10">+ <Globe className="h-4 w-4 text-gray-500 sm:h-5 sm:w-5" />+ </div>+ )}+ {/*+ Here, we're manually setting ml-* values because if we do space-x-* in the parent div,+ it messes up the tooltip positioning.+ */}+ <div className="ml-2 sm:ml-4">+ <div className="flex max-w-fit items-center space-x-2">+ <a+ className={cn(+ "w-full max-w-[140px] truncate text-sm font-semibold text-blue-800 sm:max-w-[300px] sm:text-base md:max-w-[360px] xl:max-w-[500px]",+ {+ "text-gray-500": archived,+ },+ )}+ href={linkConstructor({ domain, key })}+ target="_blank"+ rel="noreferrer"+ onClick={(e) => e.stopPropagation()}+ >+ {linkConstructor({+ domain: punycode.toUnicode(domain || ""),+ key,+ pretty: true,+ })}+ </a>+ <CopyButton value={linkConstructor({ domain, key })} />+ </div>+ <div className="flex max-w-fit items-center space-x-1">+ {user && (+ <>+ <Avatar user={user} className="h-4 w-4" />+ <p>•</p>+ </>+ )}+ {createdAt && (+ <>+ <p+ className="whitespace-nowrap text-sm text-gray-500"+ suppressHydrationWarning+ >+ {timeAgo(createdAt)}+ </p>+ <p>•</p>+ </>+ )}+ {rewrite && (+ <EyeOff className="xs:block hidden h-4 w-4 text-gray-500" />+ )}+ {url ? (+ <a+ href={url}+ target="_blank"+ rel="noopener noreferrer"+ onClick={(e) => e.stopPropagation()}+ className="xs:block hidden max-w-[240px] truncate text-sm font-medium text-gray-700 underline-offset-2 hover:underline"+ >+ {url}+ </a>+ ) : (+ <p className="xs:block hidden max-w-[240px] truncate text-sm font-medium text-gray-700 underline-offset-2 hover:underline">+ No redirect configured+ </p>+ )}+ </div>+ </div>+ </div>+ </div>+ );+}diff --git a/packages/ui/src/modal.tsx b/packages/ui/src/modal.tsxindex e585231335..f03eade8ec 100644--- a/packages/ui/src/modal.tsx+++ b/packages/ui/src/modal.tsx@@ -10,18 +10,18 @@ import { useMediaQuery } from "./hooks";export function Modal({children,className,- dialogOnly,showModal,setShowModal,onClose,+ desktopOnly,preventDefaultClose,}: {children: React.ReactNode;className?: string;- dialogOnly?: boolean;showModal?: boolean;setShowModal?: Dispatch<SetStateAction<boolean>>;onClose?: () => void;+ desktopOnly?: boolean;preventDefaultClose?: boolean;}) {const router = useRouter();@@ -43,7 +43,7 @@ export function Modal({};const { isMobile } = useMediaQuery();- if (isMobile && !dialogOnly) {+ if (isMobile && !desktopOnly) {return (<Drawer.Rootopen={setShowModal ? showModal : true}diff --git a/packages/ui/src/tooltip.tsx b/packages/ui/src/tooltip.tsxindex dcee8ae194..50774a2071 100644--- a/packages/ui/src/tooltip.tsx+++ b/packages/ui/src/tooltip.tsx@@ -12,16 +12,18 @@ export function Tooltip({children,content,side = "top",+ desktopOnly,fullWidth,}: {children: ReactNode;content: ReactNode | string;side?: "top" | "bottom" | "left" | "right";+ desktopOnly?: boolean;fullWidth?: boolean;}) {const { isMobile } = useMediaQuery();- if (isMobile) {+ if (isMobile && !desktopOnly) {return (<Drawer.Root><Drawer.Trigger