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.

refactored popovers

Steven Tey81c9249381bc
diff --git a/app/ui/modal.tsx b/app/ui/modal.tsx
index 0c807714b1..f26239d58f 100644
--- a/app/ui/modal.tsx
+++ b/app/ui/modal.tsx
@@ -54,7 +54,7 @@ export default function Modal({
const { isMobile } = useWindowSize();
- if (isMobile)
+ if (isMobile) {
return (
<Drawer.Root
open={showModal}
@@ -75,6 +75,7 @@ export default function Modal({
</Drawer.Portal>
</Drawer.Root>
);
+ }
return (
<AnimatePresence>
diff --git a/app/ui/popover.tsx b/app/ui/popover.tsx
index 8ff5e51e43..d70a54d999 100644
--- a/app/ui/popover.tsx
+++ b/app/ui/popover.tsx
@@ -1,7 +1,6 @@
"use client";
-import { useParams } from "next/navigation";
-import { ReactNode, useEffect } from "react";
+import { ReactNode } from "react";
import * as PopoverPrimitive from "@radix-ui/react-popover";
import { Drawer } from "vaul";
import useWindowSize from "#/lib/hooks/use-window-size";
@@ -19,33 +18,31 @@ export default function Popover({
openPopover;
setOpenPopover;
}) {
- const { slug } = useParams() as { slug?: string };
const { isMobile } = useWindowSize();
- // workaround to make popover close when route changes on desktop
- useEffect(() => {
- setOpenPopover(false);
- }, [slug]);
+ if (isMobile) {
+ return (
+ <Drawer.Root
+ open={openPopover}
+ onOpenChange={setOpenPopover}
+ shouldScaleBackground
+ >
+ <div className="sm:hidden">{children}</div>
+ <Drawer.Overlay className="fixed inset-0 z-30 bg-gray-100 bg-opacity-10 backdrop-blur" />
+ <Drawer.Portal>
+ <Drawer.Content className="fixed bottom-0 left-0 right-0 z-40 mt-24 rounded-t-[10px] border-t border-gray-200 bg-white">
+ <div className="mx-auto my-3 h-1 w-12 rounded-full bg-gray-300" />
+ <div className="flex min-h-[150px] w-full items-center justify-center overflow-hidden bg-white pb-8 align-middle shadow-xl">
+ {content}
+ </div>
+ </Drawer.Content>
+ <Drawer.Overlay />
+ </Drawer.Portal>
+ </Drawer.Root>
+ );
+ }
- return isMobile ? (
- <Drawer.Root
- open={openPopover}
- onOpenChange={setOpenPopover}
- shouldScaleBackground
- >
- <div className="sm:hidden">{children}</div>
- <Drawer.Overlay className="fixed inset-0 z-30 bg-gray-100 bg-opacity-10 backdrop-blur" />
- <Drawer.Portal>
- <Drawer.Content className="fixed bottom-0 left-0 right-0 z-40 mt-24 rounded-t-[10px] border-t border-gray-200 bg-white">
- <div className="mx-auto my-3 h-1 w-12 rounded-full bg-gray-300" />
- <div className="flex min-h-[150px] w-full items-center justify-center overflow-hidden bg-white pb-8 align-middle shadow-xl">
- {content}
- </div>
- </Drawer.Content>
- <Drawer.Overlay />
- </Drawer.Portal>
- </Drawer.Root>
- ) : (
+ return (
<PopoverPrimitive.Root open={openPopover} onOpenChange={setOpenPopover}>
<PopoverPrimitive.Trigger className="hidden sm:inline-flex" asChild>
{children}
diff --git a/components/app/links/link-card.tsx b/components/app/links/link-card.tsx
index 71754729e1..a77996ae74 100644
--- a/components/app/links/link-card.tsx
+++ b/components/app/links/link-card.tsx
@@ -10,7 +10,7 @@ import IconMenu from "@/components/shared/icon-menu";
import BlurImage from "#/ui/blur-image";
import CopyButton from "@/components/shared/copy-button";
import { Chart, Delete, ThreeDots } from "@/components/shared/icons";
-import Popover from "@/components/shared/popover";
+import Popover from "#/ui/popover";
import Tooltip, { TooltipContent } from "#/ui/tooltip";
import useProject from "#/lib/swr/use-project";
import { LinkProps } from "#/lib/types";
diff --git a/components/app/links/link-filters.tsx b/components/app/links/link-filters.tsx
index 98801633e3..3abd810f6c 100644
--- a/components/app/links/link-filters.tsx
+++ b/components/app/links/link-filters.tsx
@@ -25,7 +25,7 @@ import useTags from "#/lib/swr/use-tags";
import TagBadge, { COLORS_LIST } from "@/components/app/links/tag-badge";
import { TagProps } from "#/lib/types";
import { ThreeDots } from "@/components/shared/icons";
-import Popover from "@/components/shared/popover";
+import Popover from "#/ui/popover";
import IconMenu from "@/components/shared/icon-menu";
import { mutate } from "swr";
diff --git a/components/app/links/link-sort.tsx b/components/app/links/link-sort.tsx
index 9ce3b1d7d5..74ccbfdbbf 100644
--- a/components/app/links/link-sort.tsx
+++ b/components/app/links/link-sort.tsx
@@ -3,7 +3,7 @@ import { useMemo, useState } from "react";
import IconMenu from "@/components/shared/icon-menu";
import { Sort, Tick } from "@/components/shared/icons";
import { ChevronDown, SortDesc } from "lucide-react";
-import Popover from "@/components/shared/popover";
+import Popover from "#/ui/popover";
const sortOptions = [
{
diff --git a/components/app/modals/link-qr-modal.tsx b/components/app/modals/link-qr-modal.tsx
index 50a5b62d79..2050b0f406 100644
--- a/components/app/modals/link-qr-modal.tsx
+++ b/components/app/modals/link-qr-modal.tsx
@@ -19,7 +19,7 @@ import useProject from "#/lib/swr/use-project";
import { SimpleLinkProps } from "#/lib/types";
import { getApexDomain, linkConstructor } from "#/lib/utils";
import IconMenu from "@/components/shared/icon-menu";
-import Popover from "@/components/shared/popover";
+import Popover from "#/ui/popover";
import { toast } from "sonner";
import { GOOGLE_FAVICON_URL } from "#/lib/constants";
diff --git a/components/layout/app/project-select.tsx b/components/layout/app/project-select.tsx
index f0b335b774..07cd29285e 100644
--- a/components/layout/app/project-select.tsx
+++ b/components/layout/app/project-select.tsx
@@ -4,7 +4,7 @@ import { useSession } from "next-auth/react";
import BlurImage from "#/ui/blur-image";
import { Tick } from "@/components/shared/icons";
import { ChevronsUpDown, PlusCircle } from "lucide-react";
-import Popover from "@/components/shared/popover";
+import Popover from "#/ui/popover";
import { PlanProps, ProjectWithDomainProps } from "#/lib/types";
import useProjects from "#/lib/swr/use-projects";
import PlanBadge from "@/components/app/projects/settings/plan-badge";
diff --git a/components/layout/app/user-dropdown.tsx b/components/layout/app/user-dropdown.tsx
index e22134f280..11893e7533 100644
--- a/components/layout/app/user-dropdown.tsx
+++ b/components/layout/app/user-dropdown.tsx
@@ -1,7 +1,7 @@
import { Suspense, useEffect, useMemo, useState } from "react";
import { signOut, useSession } from "next-auth/react";
import { Logout } from "@/components/shared/icons";
-import Popover from "@/components/shared/popover";
+import Popover from "#/ui/popover";
import IconMenu from "../../shared/icon-menu";
import Image from "next/image";
import va from "@vercel/analytics";
diff --git a/components/shared/popover.tsx b/components/shared/popover.tsx
deleted file mode 100644
index 82e42eb814..0000000000
--- a/components/shared/popover.tsx
+++ /dev/null
@@ -1,60 +0,0 @@
-import { useRouter } from "next/router";
-import { ReactNode, useEffect, useRef } from "react";
-import * as PopoverPrimitive from "@radix-ui/react-popover";
-import { Drawer } from "vaul";
-import useWindowSize from "#/lib/hooks/use-window-size";
-
-export default function Popover({
- children,
- content,
- align = "center",
- openPopover,
- setOpenPopover,
-}: {
- children: ReactNode;
- content: ReactNode | string;
- align?: "center" | "start" | "end";
- openPopover: boolean;
- setOpenPopover: (open: boolean) => void;
-}) {
- const router = useRouter();
- const { isMobile } = useWindowSize();
-
- // workaround to make popover close when route changes on desktop
- useEffect(() => {
- setOpenPopover(false);
- }, [router.query.slug]);
-
- return isMobile ? (
- <Drawer.Root
- open={openPopover}
- onOpenChange={setOpenPopover}
- shouldScaleBackground
- >
- <div className="sm:hidden">{children}</div>
- <Drawer.Overlay className="fixed inset-0 z-30 bg-gray-100 bg-opacity-10 backdrop-blur" />
- <Drawer.Portal>
- <Drawer.Content className="fixed bottom-0 left-0 right-0 z-40 mt-24 rounded-t-[10px] border-t border-gray-200 bg-white">
- <div className="mx-auto my-3 h-1 w-12 rounded-full bg-gray-300" />
- <div className="flex min-h-[150px] w-full items-center justify-center overflow-hidden bg-white pb-8 align-middle shadow-xl">
- {content}
- </div>
- </Drawer.Content>
- <Drawer.Overlay />
- </Drawer.Portal>
- </Drawer.Root>
- ) : (
- <PopoverPrimitive.Root open={openPopover} onOpenChange={setOpenPopover}>
- <PopoverPrimitive.Trigger className="hidden sm:inline-flex" asChild>
- {children}
- </PopoverPrimitive.Trigger>
- <PopoverPrimitive.Content
- sideOffset={4}
- align={align}
- className="z-20 hidden animate-slide-up-fade items-center rounded-md border border-gray-200 bg-white drop-shadow-lg sm:block"
- >
- {content}
- </PopoverPrimitive.Content>
- </PopoverPrimitive.Root>
- );
-}
diff --git a/components/stats/toggle.tsx b/components/stats/toggle.tsx
index 4b86130190..d4665753ed 100644
--- a/components/stats/toggle.tsx
+++ b/components/stats/toggle.tsx
@@ -7,7 +7,7 @@ import { INTERVALS } from "#/lib/stats";
import useScroll from "#/lib/hooks/use-scroll";
import { linkConstructor } from "#/lib/utils";
import IconMenu from "@/components/shared/icon-menu";
-import Popover from "@/components/shared/popover";
+import Popover from "#/ui/popover";
import useSWR, { mutate } from "swr";
import { fetcher } from "#/lib/utils";
import { toast } from "sonner";
diff --git a/lib/hooks/use-window-size.ts b/lib/hooks/use-window-size.ts
index e6b87c08ac..cc75212b78 100644
--- a/lib/hooks/use-window-size.ts
+++ b/lib/hooks/use-window-size.ts
@@ -37,10 +37,9 @@ export default function useWindowSize(): {
const memoizedWindowSize = useMemo(() => {
return {
...windowSize,
- isMobile:
- typeof windowSize?.width === "number" && windowSize?.width < 768,
+ isMobile: typeof windowSize?.width === "number" && windowSize.width < 768,
isDesktop:
- typeof windowSize?.width === "number" && windowSize?.width >= 768,
+ typeof windowSize?.width === "number" && windowSize.width >= 768,
};
}, [windowSize]);
diff --git a/pages/app/[slug]/index.tsx b/pages/app/[slug]/index.tsx
index 3dd5d06f45..94c72f3664 100644
--- a/pages/app/[slug]/index.tsx
+++ b/pages/app/[slug]/index.tsx
@@ -4,7 +4,7 @@ import MaxWidthWrapper from "@/components/shared/max-width-wrapper";
import AppLayout from "components/layout/app";
import useProject from "#/lib/swr/use-project";
import { useState } from "react";
-import Popover from "@/components/shared/popover";
+import Popover from "#/ui/popover";
import IconMenu from "@/components/shared/icon-menu";
import { ChevronDown, FilePlus2, Import } from "lucide-react";
import { useRouter } from "next/router";
diff --git a/pages/app/[slug]/settings/people.tsx b/pages/app/[slug]/settings/people.tsx
index 03ec8489a3..536c2b87b3 100644
--- a/pages/app/[slug]/settings/people.tsx
+++ b/pages/app/[slug]/settings/people.tsx
@@ -4,7 +4,7 @@ import { useState } from "react";
import BlurImage from "#/ui/blur-image";
import { UserProps } from "#/lib/types";
import { timeAgo } from "#/lib/utils";
-import Popover from "@/components/shared/popover";
+import Popover from "#/ui/popover";
import IconMenu from "@/components/shared/icon-menu";
import { UserMinus } from "lucide-react";
import { ThreeDots } from "@/components/shared/icons";