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.

Added detailed stats modal, fixed media query bug

Steven Teya7a36a2e4846
diff --git a/app/providers.tsx b/app/providers.tsx
index e4c40bd7fa..cb102274e6 100644
--- a/app/providers.tsx
+++ b/app/providers.tsx
@@ -3,7 +3,7 @@
import { Dispatch, ReactNode, SetStateAction, createContext } from "react";
import { Toaster } from "sonner";
import { Analytics } from "@vercel/analytics/react";
-import useCMDK from "./ui/cmdk";
+import useCMDK from "#/ui/cmdk";
export const AppContext = createContext<{
setShowCMDK: Dispatch<SetStateAction<boolean>>;
@@ -13,6 +13,7 @@ export const AppContext = createContext<{
export default function Providers({ children }: { children: ReactNode }) {
const { CMDK, setShowCMDK } = useCMDK();
+
return (
<AppContext.Provider
value={{
diff --git a/app/ui/cmdk.tsx b/app/ui/cmdk.tsx
index 3ae7e711c6..7c91b28e96 100644
--- a/app/ui/cmdk.tsx
+++ b/app/ui/cmdk.tsx
@@ -93,9 +93,13 @@ const CommandResults = ({
),
];
- const fuse = new Fuse(allItems, {
- keys: ["title", "description"],
- });
+ const fuse = useMemo(
+ () =>
+ new Fuse(allItems, {
+ keys: ["title", "description"],
+ }),
+ [allItems],
+ );
const search = useCommandState((state) => state.search);
diff --git a/app/ui/content/mdx.tsx b/app/ui/content/mdx.tsx
index 2eb5855678..a64b348e5c 100644
--- a/app/ui/content/mdx.tsx
+++ b/app/ui/content/mdx.tsx
@@ -6,7 +6,7 @@ import GithubRepo, { GithubRepoProps } from "@/components/shared/github-repo";
import BlurImage from "#/ui/blur-image";
import MDXTweet from "#/ui/tweet";
import { Tweet as TweetProps } from "react-tweet/api";
-import useWindowSize from "#/lib/hooks/use-window-size";
+import useMediaQuery from "#/lib/hooks/use-media-query";
import { cn } from "#/lib/utils";
import Zoom from "react-medium-image-zoom";
import "react-medium-image-zoom/dist/styles.css";
@@ -69,7 +69,7 @@ interface MDXProps {
export function MDX({ code, images, tweets, repos, className }: MDXProps) {
const Component = useMDXComponent(code);
- const { width } = useWindowSize();
+ const { isDesktop } = useMediaQuery();
const MDXImage = (props: any) => {
if (!images) return null;
@@ -81,7 +81,7 @@ export function MDX({ code, images, tweets, repos, className }: MDXProps) {
// we need to wrap the image in a HTML element or showModal will throw errors
<>
<figure className="not-prose flex flex-col items-center justify-center space-y-3">
- <Zoom zoomMargin={width > 640 ? 45 : undefined}>
+ <Zoom zoomMargin={isDesktop ? 45 : undefined}>
<BlurImage
{...props}
className="rounded-lg border border-gray-200"
diff --git a/app/ui/modal-provider.tsx b/app/ui/modal-provider.tsx
index 66e48723de..61e476742b 100644
--- a/app/ui/modal-provider.tsx
+++ b/app/ui/modal-provider.tsx
@@ -53,7 +53,7 @@ export default function ModalProvider({ children }: { children: ReactNode }) {
const { AcceptInviteModal, setShowAcceptInviteModal } =
useAcceptInviteModal();
const { setShowAddEditDomainModal, AddEditDomainModal } =
- useAddEditDomainModal({});
+ useAddEditDomainModal();
const { CMDK, setShowCMDK } = useCMDK();
const { setShowAddEditLinkModal, AddEditLinkModal } = useAddEditLinkModal();
diff --git a/app/ui/modal.tsx b/app/ui/modal.tsx
index d1521f86fc..b906641973 100644
--- a/app/ui/modal.tsx
+++ b/app/ui/modal.tsx
@@ -1,12 +1,11 @@
"use client";
-import { Dispatch, SetStateAction, useEffect, useRef } from "react";
+import { Dispatch, SetStateAction } from "react";
import { useRouter } from "next/navigation";
-import FocusTrap from "focus-trap-react";
-import { AnimatePresence, motion, useAnimation } from "framer-motion";
import { cn } from "#/lib/utils";
import { Drawer } from "vaul";
-import useWindowSize from "#/lib/hooks/use-window-size";
+import * as Dialog from "@radix-ui/react-dialog";
+import useMediaQuery from "#/lib/hooks/use-media-query";
export default function Modal({
children,
@@ -14,19 +13,19 @@ export default function Modal({
setShowModal,
className,
onClose,
- disableDefaultHide,
+ preventDefaultClose,
}: {
children: React.ReactNode;
showModal?: boolean;
setShowModal?: Dispatch<SetStateAction<boolean>>;
className?: string;
onClose?: () => void;
- disableDefaultHide?: boolean;
+ preventDefaultClose?: boolean;
}) {
const router = useRouter();
const closeModal = ({ dragged }: { dragged?: boolean } = {}) => {
- if (disableDefaultHide && !dragged) {
+ if (preventDefaultClose && !dragged) {
return;
}
// fire onClose event if provided
@@ -40,89 +39,58 @@ export default function Modal({
router.back();
}
};
+ const { isMobile } = useMediaQuery();
- useEffect(() => {
- function onKeyDown(e: KeyboardEvent) {
- if (e.key === "Escape") {
- closeModal();
- }
- }
- // only add listener if modal is open
- if (showModal) document.addEventListener("keydown", onKeyDown);
- return () => document.removeEventListener("keydown", onKeyDown);
- }, [showModal, closeModal]);
-
- const { isMobile } = useWindowSize();
-
- if (isMobile) {
- return (
- <Drawer.Root
- open={setShowModal ? showModal : true}
- onOpenChange={(open) => {
- if (!open) {
- closeModal({ dragged: true });
- }
- }}
- shouldScaleBackground
- >
- <Drawer.Overlay className="fixed inset-0 z-40 bg-gray-100 bg-opacity-10 backdrop-blur" />
- <Drawer.Portal>
- <Drawer.Content
- className={cn(
- "fixed bottom-0 left-0 right-0 z-50 mt-24 rounded-t-[10px] border-t border-gray-200 bg-white",
- className,
- )}
- >
- <div className="sticky top-0 z-20 flex w-full items-center justify-center rounded-t-[10px] bg-inherit">
- <div className="my-3 h-1 w-12 rounded-full bg-gray-300" />
- </div>
- {children}
- </Drawer.Content>
- <Drawer.Overlay />
- </Drawer.Portal>
- </Drawer.Root>
- );
- }
-
- return (
- <AnimatePresence>
- {(setShowModal ? showModal : true) && (
- <FocusTrap
- focusTrapOptions={{
- initialFocus: false,
- clickOutsideDeactivates: true,
- onActivate: () => {
- // prevent scroll outside of modal when modal is open
- document.body.style.overflow = "hidden";
- },
- onDeactivate: () => {
- // allow scroll outside of modal when modal is closed
- document.body.style.overflow = "auto";
- },
- }}
+ return isMobile ? (
+ <Drawer.Root
+ open={setShowModal ? showModal : true}
+ onOpenChange={(open) => {
+ if (!open) {
+ closeModal({ dragged: true });
+ }
+ }}
+ >
+ <Drawer.Overlay className="fixed inset-0 z-40 bg-gray-100 bg-opacity-10 backdrop-blur" />
+ <Drawer.Portal>
+ <Drawer.Content
+ className={cn(
+ "fixed bottom-0 left-0 right-0 z-50 mt-24 rounded-t-[10px] border-t border-gray-200 bg-white",
+ className,
+ )}
>
- <div className="absolute">
- <motion.dialog
- key="desktop-modal"
- className={cn(
- "fixed inset-0 z-50 m-auto hidden max-h-fit w-full max-w-md animate-scale-in overflow-hidden rounded-2xl border border-gray-200 bg-white p-0 shadow-xl md:block",
- className,
- )}
- >
- {children}
- </motion.dialog>
- <motion.div
- id="modal-backdrop"
- key="backdrop"
- className="fixed inset-0 z-40 bg-gray-100 bg-opacity-50 backdrop-blur-md"
- initial={{ opacity: 0 }}
- animate={{ opacity: 1 }}
- exit={{ opacity: 0 }}
- onClick={() => closeModal()}
- />
+ <div className="sticky top-0 z-20 flex w-full items-center justify-center rounded-t-[10px] bg-inherit">
+ <div className="my-3 h-1 w-12 rounded-full bg-gray-300" />
</div>
- </FocusTrap>
- )}
- </AnimatePresence>
+ {children}
+ </Drawer.Content>
+ <Drawer.Overlay />
+ </Drawer.Portal>
+ </Drawer.Root>
+ ) : (
+ <Dialog.Root
+ open={setShowModal ? showModal : true}
+ onOpenChange={(open) => {
+ if (!open) {
+ closeModal();
+ }
+ }}
+ >
+ <Dialog.Portal>
+ <Dialog.Overlay
+ id="modal-backdrop"
+ className="fixed inset-0 z-40 animate-fade-in bg-gray-100 bg-opacity-50 backdrop-blur-md"
+ />
+ <Dialog.Content
+ onOpenAutoFocus={(e) => e.preventDefault()}
+ onCloseAutoFocus={(e) => e.preventDefault()}
+ className={cn(
+ "fixed inset-0 z-50 m-auto max-h-fit w-full max-w-md animate-scale-in overflow-hidden rounded-2xl border border-gray-200 bg-white p-0 shadow-xl",
+ className,
+ )}
+ >
+ {children}
+ </Dialog.Content>
+ </Dialog.Portal>
+ </Dialog.Root>
);
}
diff --git a/app/ui/modals/add-edit-link-modal/index.tsx b/app/ui/modals/add-edit-link-modal/index.tsx
index 92e0b68177..3eaccd7cfd 100644
--- a/app/ui/modals/add-edit-link-modal/index.tsx
+++ b/app/ui/modals/add-edit-link-modal/index.tsx
@@ -264,7 +264,7 @@ function AddEditLinkModal({
showModal={showAddEditLinkModal}
setShowModal={setShowAddEditLinkModal}
className="max-w-screen-lg"
- disableDefaultHide={homepageDemo ? false : true}
+ preventDefaultClose={homepageDemo ? false : true}
>
<div className="relative grid max-h-[80vh] divide-x divide-gray-100 overflow-scroll scrollbar-hide md:max-h-[min(906px,_90vh)] md:grid-cols-2">
{!hideXButton && !homepageDemo && (
diff --git a/app/ui/popover.tsx b/app/ui/popover.tsx
index 21e2d84251..681a016f13 100644
--- a/app/ui/popover.tsx
+++ b/app/ui/popover.tsx
@@ -3,7 +3,7 @@
import { Dispatch, ReactNode, SetStateAction } from "react";
import * as PopoverPrimitive from "@radix-ui/react-popover";
import { Drawer } from "vaul";
-import useWindowSize from "#/lib/hooks/use-window-size";
+import useMediaQuery from "#/lib/hooks/use-media-query";
export default function Popover({
children,
@@ -18,15 +18,11 @@ export default function Popover({
openPopover: boolean;
setOpenPopover: Dispatch<SetStateAction<boolean>>;
}) {
- const { isMobile } = useWindowSize();
+ const { isMobile } = useMediaQuery();
if (isMobile) {
return (
- <Drawer.Root
- open={openPopover}
- onOpenChange={setOpenPopover}
- shouldScaleBackground
- >
+ <Drawer.Root open={openPopover} onOpenChange={setOpenPopover}>
<div className="md:hidden">{children}</div>
<Drawer.Overlay className="fixed inset-0 z-30 bg-gray-100 bg-opacity-10 backdrop-blur" />
<Drawer.Portal>
@@ -49,13 +45,15 @@ export default function Popover({
<PopoverPrimitive.Trigger className="hidden md: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 md:block"
- >
- {content}
- </PopoverPrimitive.Content>
+ <PopoverPrimitive.Portal>
+ <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 md:block"
+ >
+ {content}
+ </PopoverPrimitive.Content>
+ </PopoverPrimitive.Portal>
</PopoverPrimitive.Root>
);
}
diff --git a/app/ui/stats/bar-chart.tsx b/app/ui/stats/bar-chart.tsx
index 15768b29ab..4d1c872ebd 100644
--- a/app/ui/stats/bar-chart.tsx
+++ b/app/ui/stats/bar-chart.tsx
@@ -12,7 +12,7 @@ import useSWR from "swr";
import { fetcher } from "#/lib/utils";
import { LoadingCircle } from "#/ui/icons";
import { StatsContext } from ".";
-import useWindowSize from "#/lib/hooks/use-window-size";
+import useMediaQuery from "#/lib/hooks/use-media-query";
const LEFT_AXIS_WIDTH = 30;
const CHART_MAX_HEIGHT = 400;
@@ -41,7 +41,7 @@ export default function BarChart() {
fetcher,
);
- const { width: screenWidth } = useWindowSize();
+ const { width: screenWidth } = useMediaQuery();
const [CHART_WIDTH, CHART_HEIGHT] = useMemo(() => {
const width = screenWidth
diff --git a/app/ui/stats/bar-list.tsx b/app/ui/stats/bar-list.tsx
new file mode 100644
index 0000000000..ac41fe7069
--- /dev/null
+++ b/app/ui/stats/bar-list.tsx
@@ -0,0 +1,101 @@
+"use client";
+
+import { cn, nFormatter } from "#/lib/utils";
+import { ReactNode, useMemo, useState } from "react";
+import { motion } from "framer-motion";
+import { Search } from "lucide-react";
+import Fuse from "fuse.js";
+
+export default function BarList({
+ tab,
+ data,
+ barBackground,
+ totalClicks,
+ limit,
+}: {
+ tab: string;
+ data: {
+ icon: ReactNode;
+ title: string;
+ clicks: number;
+ }[];
+ totalClicks: number;
+ barBackground: string;
+ limit?: number;
+}) {
+ const [search, setSearch] = useState("");
+
+ const fuse = useMemo(() => {
+ if (limit) {
+ return null;
+ }
+ return new Fuse(data, {
+ keys: ["title"],
+ });
+ }, [limit, data]);
+
+ const filteredData = useMemo(() => {
+ if (limit) {
+ return data.slice(0, limit);
+ } else {
+ return search ? fuse!.search(search).map((r) => r.item) : data;
+ }
+ }, [data, limit, search, fuse]);
+
+ const bars = (
+ <div className="grid gap-4">
+ {filteredData.map(({ icon, title, clicks }, idx) => (
+ <div key={idx} className="flex items-center justify-between">
+ <div className="relative z-10 flex w-full max-w-[calc(100%-3rem)] items-center">
+ <span className="z-10 flex items-center space-x-2 px-2">
+ {icon}
+ <p className="text-sm text-gray-800">{title}</p>
+ </span>
+ <motion.div
+ style={{
+ width: `${(clicks / (totalClicks || 0)) * 100}%`,
+ }}
+ className={cn("absolute h-8 origin-left", barBackground)}
+ transition={{ ease: "easeOut", duration: 0.3 }}
+ initial={{ transform: "scaleX(0)" }}
+ animate={{ transform: "scaleX(1)" }}
+ />
+ </div>
+ <p className="z-10 text-sm text-gray-600">{nFormatter(clicks)}</p>
+ </div>
+ ))}
+ </div>
+ );
+
+ if (limit) {
+ return bars;
+ } else {
+ return (
+ <>
+ <div className="relative p-4">
+ <div className="pointer-events-none absolute inset-y-0 left-7 flex items-center">
+ <Search className="h-4 w-4 text-gray-400" />
+ </div>
+ <input
+ type="text"
+ autoFocus
+ className="w-full rounded-md border border-gray-300 py-2 pl-10 text-black placeholder:text-gray-400 focus:border-black focus:outline-none focus:ring-gray-600 sm:text-sm"
+ placeholder={`Search ${tab}...`}
+ onChange={(e) => setSearch(e.target.value)}
+ />
+ </div>
+ <div>
+ <div className="flex justify-between px-4 pb-1 pt-0">
+ <p className="text-xs font-semibold uppercase text-gray-600">
+ {tab}
+ </p>
+ <p className="text-xs font-semibold uppercase text-gray-600">
+ Clicks
+ </p>
+ </div>
+ <div className="h-[50vh] overflow-auto p-4 md:h-[40vh]">{bars}</div>
+ </div>
+ </>
+ );
+ }
+}
diff --git a/app/ui/stats/devices.tsx b/app/ui/stats/devices.tsx
index 0c5419214d..305d52d15c 100644
--- a/app/ui/stats/devices.tsx
+++ b/app/ui/stats/devices.tsx
@@ -1,18 +1,19 @@
import { useContext, useState } from "react";
-import { motion } from "framer-motion";
import TabSelect from "@/components/shared/tab-select";
import { LoadingCircle } from "#/ui/icons";
import { DeviceTabs, uaToBot } from "#/lib/stats";
-import { nFormatter } from "#/lib/utils";
import DeviceIcon from "./device-icon";
import useSWR from "swr";
import { fetcher } from "#/lib/utils";
import { StatsContext } from ".";
+import BarList from "./bar-list";
+import { Maximize } from "lucide-react";
+import Modal from "#/ui/modal";
export default function Devices() {
const [tab, setTab] = useState<DeviceTabs>("device");
- const { endpoint, queryString } = useContext(StatsContext);
+ const { endpoint, queryString, modal } = useContext(StatsContext);
const { data } = useSWR<
({
@@ -24,71 +25,75 @@ export default function Devices() {
`${endpoint}/clicks${queryString}`,
fetcher,
);
+ const [showModal, setShowModal] = useState(false);
+
+ const barList = (limit?: number) => (
+ <BarList
+ tab={tab}
+ data={
+ data?.map((d) => ({
+ icon: (
+ <DeviceIcon
+ display={tab === "bot" ? uaToBot(d.ua) : d[tab]}
+ tab={tab}
+ className="h-4 w-4"
+ />
+ ),
+ title: tab === "bot" ? uaToBot(d.ua) : d[tab],
+ clicks: d.clicks,
+ })) || []
+ }
+ totalClicks={totalClicks || 0}
+ barBackground="bg-green-100"
+ {...(limit && { limit })}
+ />
+ );
return (
- <div className="relative z-0 h-[420px] overflow-scroll border border-gray-200 bg-white px-7 py-5 scrollbar-hide sm:rounded-lg sm:border-gray-100 sm:shadow-lg">
- <div className="mb-5 flex justify-between">
- <h1 className="text-xl font-semibold">Devices</h1>
- <TabSelect
- options={["device", "browser", "os", "bot"]}
- selected={tab}
- // @ts-ignore
- selectAction={setTab}
- />
- </div>
- <div
- className={
- data && data.length > 0
- ? "grid gap-4"
- : "flex h-[300px] items-center justify-center"
- }
+ <>
+ <Modal
+ showModal={showModal}
+ setShowModal={setShowModal}
+ className="max-w-lg"
>
+ <div className="border-b border-gray-200 px-6 py-4">
+ <h1 className="text-xl font-semibold">Devices</h1>
+ </div>
+ {barList()}
+ </Modal>
+ <div className="relative z-0 h-[400px] overflow-scroll border border-gray-200 bg-white px-7 py-5 scrollbar-hide sm:rounded-lg sm:border-gray-100 sm:shadow-lg">
+ <div className="mb-5 flex justify-between">
+ <h1 className="text-xl font-semibold">Devices</h1>
+ <TabSelect
+ options={["device", "browser", "os", "bot"]}
+ selected={tab}
+ // @ts-ignore
+ selectAction={setTab}
+ />
+ </div>
{data ? (
data.length > 0 ? (
- data.map((d, idx) => (
- <div key={idx} className="flex items-center justify-between">
- <div className="relative z-10 flex w-full max-w-[calc(100%-3rem)] items-center">
- <span className="z-10 flex items-center space-x-2 px-2">
- <DeviceIcon
- display={tab === "bot" ? uaToBot(d.ua) : d[tab]}
- tab={tab}
- className="h-4 w-4"
- />
- <p className="text-sm text-gray-800">
- {tab === "bot" ? uaToBot(d.ua) : d[tab]}
- </p>
- </span>
- <motion.div
- style={{
- width: `${
- (d.clicks /
- (tab === "bot"
- ? data?.reduce(
- (acc, curr) => acc + curr.clicks,
- 0,
- ) || 0
- : totalClicks || 0)) *
- 100
- }%`,
- }}
- className="absolute h-8 origin-left bg-green-100"
- transition={{ ease: "easeOut", duration: 0.3 }}
- initial={{ transform: "scaleX(0)" }}
- animate={{ transform: "scaleX(1)" }}
- />
- </div>
- <p className="z-10 text-sm text-gray-600">
- {nFormatter(d.clicks)}
- </p>
- </div>
- ))
+ barList(9)
) : (
- <p className="text-sm text-gray-600">No data available</p>
+ <div className="flex h-[300px] items-center justify-center">
+ <p className="text-sm text-gray-600">No data available</p>
+ </div>
)
) : (
- <LoadingCircle />
+ <div className="flex h-[300px] items-center justify-center">
+ <LoadingCircle />
+ </div>
+ )}
+ {!modal && data && data.length > 9 && (
+ <button
+ onClick={() => setShowModal(true)}
+ className="absolute inset-x-0 bottom-4 z-10 mx-auto flex max-w-fit items-center space-x-2 rounded-md bg-white px-4 py-1.5 text-gray-500 transition-all hover:text-gray-800 active:scale-95"
+ >
+ <Maximize className="h-4 w-4" />
+ <p className="text-xs font-semibold uppercase">View all</p>
+ </button>
)}
</div>
- </div>
+ </>
);
}
diff --git a/app/ui/stats/feedback/index.tsx b/app/ui/stats/feedback/index.tsx
index b0f49ab340..f210ff88f6 100644
--- a/app/ui/stats/feedback/index.tsx
+++ b/app/ui/stats/feedback/index.tsx
@@ -11,7 +11,7 @@ export default function Feedback() {
const [submitted, setSubmitted] = useState(false);
return (
- <div className="relative z-0 h-[420px] overflow-scroll border border-gray-200 bg-white px-7 py-5 scrollbar-hide sm:rounded-lg sm:border-gray-100 sm:shadow-lg">
+ <div className="relative z-0 h-[400px] overflow-scroll border border-gray-200 bg-white px-7 py-5 scrollbar-hide sm:rounded-lg sm:border-gray-100 sm:shadow-lg">
<div className="mb-5 flex">
<h1 className="text-xl font-semibold">Feedback</h1>
</div>
diff --git a/app/ui/stats/locations.tsx b/app/ui/stats/locations.tsx
index 9992228ed4..889c859c61 100644
--- a/app/ui/stats/locations.tsx
+++ b/app/ui/stats/locations.tsx
@@ -1,18 +1,19 @@
import { useContext, useState } from "react";
-import { motion } from "framer-motion";
import TabSelect from "@/components/shared/tab-select";
import { COUNTRIES } from "#/lib/constants";
import { LocationTabs } from "#/lib/stats";
-import { nFormatter } from "#/lib/utils";
import { LoadingCircle } from "#/ui/icons";
import useSWR from "swr";
import { fetcher } from "#/lib/utils";
import { StatsContext } from ".";
+import { Maximize } from "lucide-react";
+import BarList from "./bar-list";
+import Modal from "#/ui/modal";
export default function Locations() {
const [tab, setTab] = useState<LocationTabs>("country");
- const { endpoint, queryString } = useContext(StatsContext);
+ const { endpoint, queryString, modal } = useContext(StatsContext);
const { data } = useSWR<{ country: string; city: string; clicks: number }[]>(
`${endpoint}/${tab}${queryString}`,
@@ -24,61 +25,75 @@ export default function Locations() {
fetcher,
);
+ const [showModal, setShowModal] = useState(false);
+
+ const barList = (limit?: number) => (
+ <BarList
+ tab={tab}
+ data={
+ data?.map((d) => ({
+ icon: (
+ <img
+ alt={d.country}
+ src={`https://flag.vercel.app/m/${d.country}.svg`}
+ className="h-3 w-5"
+ />
+ ),
+ title: tab === "country" ? COUNTRIES[d.country] : d.city,
+ clicks: d.clicks,
+ })) || []
+ }
+ totalClicks={totalClicks || 0}
+ barBackground="bg-orange-100"
+ {...(limit && { limit })}
+ />
+ );
+
return (
- <div className="relative z-0 h-[420px] overflow-scroll border border-gray-200 bg-white px-7 py-5 scrollbar-hide sm:rounded-lg sm:border-gray-100 sm:shadow-lg">
- <div className="mb-5 flex justify-between">
- <h1 className="text-xl font-semibold">Locations</h1>
- <TabSelect
- options={["country", "city"]}
- selected={tab}
- // @ts-ignore
- selectAction={setTab}
- />
- </div>
- <div
- className={
- data && data.length > 0
- ? "grid gap-4"
- : "flex h-[300px] items-center justify-center"
- }
+ <>
+ <Modal
+ showModal={showModal}
+ setShowModal={setShowModal}
+ className="max-w-lg"
>
+ <div className="border-b border-gray-200 px-6 py-4">
+ <h1 className="text-xl font-semibold">Locations</h1>
+ </div>
+ {barList()}
+ </Modal>
+ <div className="relative z-0 h-[400px] overflow-scroll border border-gray-200 bg-white px-7 py-5 scrollbar-hide sm:rounded-lg sm:border-gray-100 sm:shadow-lg">
+ <div className="mb-5 flex justify-between">
+ <h1 className="text-xl font-semibold">Locations</h1>
+ <TabSelect
+ options={["country", "city"]}
+ selected={tab}
+ // @ts-ignore
+ selectAction={setTab}
+ />
+ </div>
{data ? (
data.length > 0 ? (
- data.map(({ country, city, clicks }, idx) => (
- <div key={idx} className="flex items-center justify-between">
- <div className="relative z-10 flex w-full max-w-[calc(100%-3rem)] items-center">
- <span className="z-10 flex items-center space-x-2 px-2">
- <img
- alt={country}
- src={`https://flag.vercel.app/m/${country}.svg`}
- className="h-3 w-5"
- />
- <p className="text-sm text-gray-800">
- {tab === "country" ? COUNTRIES[country] : city}
- </p>
- </span>
- <motion.div
- style={{
- width: `${(clicks / (totalClicks || 0)) * 100}%`,
- }}
- className="absolute h-8 origin-left bg-orange-100"
- transition={{ ease: "easeOut", duration: 0.3 }}
- initial={{ transform: "scaleX(0)" }}
- animate={{ transform: "scaleX(1)" }}
- />
- </div>
- <p className="z-10 text-sm text-gray-600">
- {nFormatter(clicks)}
- </p>
- </div>
- ))
+ barList(9)
) : (
- <p className="text-sm text-gray-600">No data available</p>
+ <div className="flex h-[300px] items-center justify-center">
+ <p className="text-sm text-gray-600">No data available</p>
+ </div>
)
) : (
- <LoadingCircle />
+ <div className="flex h-[300px] items-center justify-center">
+ <LoadingCircle />
+ </div>
+ )}
+ {!modal && data && data.length > 9 && (
+ <button
+ onClick={() => setShowModal(true)}
+ className="absolute inset-x-0 bottom-4 z-10 mx-auto flex max-w-fit items-center space-x-2 rounded-md bg-white px-4 py-1.5 text-gray-500 transition-all hover:text-gray-800 active:scale-95"
+ >
+ <Maximize className="h-4 w-4" />
+ <p className="text-xs font-semibold uppercase">View all</p>
+ </button>
)}
</div>
- </div>
+ </>
);
}
diff --git a/app/ui/stats/referer.tsx b/app/ui/stats/referer.tsx
index 8619d4d1ad..8a03655138 100644
--- a/app/ui/stats/referer.tsx
+++ b/app/ui/stats/referer.tsx
@@ -1,16 +1,17 @@
-import { motion } from "framer-motion";
import BlurImage from "#/ui/blur-image";
import { Link2 } from "lucide-react";
import { LoadingCircle } from "#/ui/icons";
-import { nFormatter } from "#/lib/utils";
import useSWR from "swr";
import { fetcher } from "#/lib/utils";
import { GOOGLE_FAVICON_URL } from "#/lib/constants";
import { StatsContext } from ".";
-import { useContext } from "react";
+import { useContext, useState } from "react";
+import BarList from "./bar-list";
+import { Maximize } from "lucide-react";
+import Modal from "#/ui/modal";
export default function Referer() {
- const { endpoint, queryString } = useContext(StatsContext);
+ const { endpoint, queryString, modal } = useContext(StatsContext);
const { data } = useSWR<{ referer: string; clicks: number }[]>(
`${endpoint}/referer${queryString}`,
@@ -22,59 +23,74 @@ export default function Referer() {
fetcher,
);
+ const [showModal, setShowModal] = useState(false);
+
+ const barList = (limit?: number) => (
+ <BarList
+ tab="Referrer"
+ data={
+ data?.map((d) => ({
+ icon:
+ d.referer === "(direct)" ? (
+ <Link2 className="h-4 w-4" />
+ ) : (
+ <BlurImage
+ src={`${GOOGLE_FAVICON_URL}${d.referer}`}
+ alt={d.referer}
+ width={20}
+ height={20}
+ className="h-4 w-4 rounded-full"
+ />
+ ),
+ title: d.referer,
+ clicks: d.clicks,
+ })) || []
+ }
+ totalClicks={totalClicks || 0}
+ barBackground="bg-red-100"
+ {...(limit && { limit })}
+ />
+ );
+
return (
- <div className="relative z-0 h-[420px] overflow-scroll border border-gray-200 bg-white px-7 py-5 scrollbar-hide sm:rounded-lg sm:border-gray-100 sm:shadow-lg">
- <div className="mb-5 flex">
- <h1 className="text-xl font-semibold">Referrers</h1>
- </div>
- <div
- className={
- data && data.length > 0
- ? "grid gap-4"
- : "flex h-[300px] items-center justify-center"
- }
+ <>
+ <Modal
+ showModal={showModal}
+ setShowModal={setShowModal}
+ className="max-w-lg"
>
+ <div className="border-b border-gray-200 px-6 py-4">
+ <h1 className="text-xl font-semibold">Referrers</h1>
+ </div>
+ {barList()}
+ </Modal>
+ <div className="relative z-0 h-[400px] overflow-scroll border border-gray-200 bg-white px-7 py-5 scrollbar-hide sm:rounded-lg sm:border-gray-100 sm:shadow-lg">
+ <div className="mb-5 flex">
+ <h1 className="text-xl font-semibold">Referrers</h1>
+ </div>
{data ? (
data.length > 0 ? (
- data.map(({ referer, clicks }, idx) => (
- <div key={idx} className="flex items-center justify-between">
- <div className="relative z-10 flex w-full max-w-[calc(100%-3rem)] items-center">
- <span className="z-10 flex items-center space-x-2 px-2">
- {referer === "(direct)" ? (
- <Link2 className="h-4 w-4" />
- ) : (
- <BlurImage
- src={`${GOOGLE_FAVICON_URL}${referer}`}
- alt={referer}
- width={20}
- height={20}
- className="h-4 w-4 rounded-full"
- />
- )}
- <p className="text-sm text-gray-800">{referer}</p>
- </span>
- <motion.div
- style={{
- width: `${(clicks / (totalClicks || 0)) * 100}%`,
- }}
- className="absolute h-8 origin-left rounded bg-red-100"
- transition={{ ease: "easeOut", duration: 0.3 }}
- initial={{ transform: "scaleX(0)" }}
- animate={{ transform: "scaleX(1)" }}
- />
- </div>
- <p className="z-10 text-sm text-gray-600">
- {nFormatter(clicks)}
- </p>
- </div>
- ))
+ barList(9)
) : (
- <p className="text-sm text-gray-600">No data available</p>
+ <div className="flex h-[300px] items-center justify-center">
+ <p className="text-sm text-gray-600">No data available</p>
+ </div>
)
) : (
- <LoadingCircle />
+ <div className="flex h-[300px] items-center justify-center">
+ <LoadingCircle />
+ </div>
+ )}
+ {!modal && data && data.length > 9 && (
+ <button
+ onClick={() => setShowModal(true)}
+ className="absolute inset-x-0 bottom-4 z-10 mx-auto flex max-w-fit items-center space-x-2 rounded-md bg-white px-4 py-1.5 text-gray-500 transition-all hover:text-gray-800 active:scale-95"
+ >
+ <Maximize className="h-4 w-4" />
+ <p className="text-xs font-semibold uppercase">View all</p>
+ </button>
)}
</div>
- </div>
+ </>
);
}
diff --git a/app/ui/stats/toggle.tsx b/app/ui/stats/toggle.tsx
index 53ba6987fe..37ffd88c0f 100644
--- a/app/ui/stats/toggle.tsx
+++ b/app/ui/stats/toggle.tsx
@@ -36,11 +36,11 @@ export default function Toggle() {
<div
className={cn("sticky top-[6.95rem] z-20 mb-5 bg-gray-50 py-3 md:py-5", {
"top-14": basePath.startsWith("/stats"),
- "top-6": modal,
+ "top-6 md:top-0": modal,
"shadow-md": scrolled && !modal,
})}
>
- <div className="mx-auto flex max-w-4xl flex-col items-center justify-between space-y-3 px-2.5 md:flex-row md:space-y-0 lg:px-0">
+ <div className="mx-auto flex h-20 max-w-4xl flex-col items-center justify-between space-y-3 px-2.5 md:h-10 md:flex-row md:space-y-0 lg:px-0">
<a
className="group flex text-lg font-semibold text-gray-800 md:text-xl"
href={linkConstructor({ key, domain })}
diff --git a/app/ui/tooltip.tsx b/app/ui/tooltip.tsx
index 3a153bc563..86ccdcaf20 100644
--- a/app/ui/tooltip.tsx
+++ b/app/ui/tooltip.tsx
@@ -12,7 +12,7 @@ import { ExternalLink, Globe, GlobeIcon, HelpCircle } from "lucide-react";
import { DomainProps } from "#/lib/types";
import { CheckCircleFill, XCircleFill } from "@/components/shared/icons";
import { Drawer } from "vaul";
-import useWindowSize from "#/lib/hooks/use-window-size";
+import useMediaQuery from "#/lib/hooks/use-media-query";
export default function Tooltip({
children,
@@ -23,11 +23,11 @@ export default function Tooltip({
content: ReactNode | string;
fullWidth?: boolean;
}) {
- const { isMobile } = useWindowSize();
+ const { isMobile } = useMediaQuery();
if (isMobile) {
return (
- <Drawer.Root shouldScaleBackground>
+ <Drawer.Root>
<Drawer.Trigger
className={`${fullWidth ? "w-full" : "inline-flex"} sm:hidden`}
onClick={(e) => {
diff --git a/components/app/links/link-card.tsx b/components/app/links/link-card.tsx
index a77996ae74..67c49f1117 100644
--- a/components/app/links/link-card.tsx
+++ b/components/app/links/link-card.tsx
@@ -170,11 +170,15 @@ export default function LinkCard({ props }: { props: LinkProps }) {
selected ? "border-black" : "border-gray-50"
} relative rounded-lg border-2 bg-white p-3 pr-1 shadow transition-all hover:shadow-md sm:p-4`}
>
- <LinkQRModal />
- <AddEditLinkModal />
- <DuplicateLinkModal />
- <ArchiveLinkModal />
- <DeleteLinkModal />
+ {isVisible && (
+ <>
+ <LinkQRModal />
+ <AddEditLinkModal />
+ <DuplicateLinkModal />
+ <ArchiveLinkModal />
+ <DeleteLinkModal />
+ </>
+ )}
<li className="relative flex items-center justify-between">
<div className="relative flex shrink items-center">
{archived ? (
diff --git a/components/app/links/links-container.tsx b/components/app/links/links-container.tsx
index b92385ff98..5362516f05 100644
--- a/components/app/links/links-container.tsx
+++ b/components/app/links/links-container.tsx
@@ -19,7 +19,7 @@ export default function LinksContainer({
<>
<LinkFiltersModal />
<MaxWidthWrapper className="pb-10">
- <div className="my-5 flex w-full justify-center lg:justify-end">
+ <div className="my-5 flex h-10 w-full justify-center lg:justify-end">
<LinkFiltersButton />
<LinkSort />
</div>
diff --git a/components/app/modals/add-edit-link-modal/index.tsx b/components/app/modals/add-edit-link-modal/index.tsx
index 406c9c2260..035f838402 100644
--- a/components/app/modals/add-edit-link-modal/index.tsx
+++ b/components/app/modals/add-edit-link-modal/index.tsx
@@ -272,7 +272,7 @@ function AddEditLinkModal({
showModal={showAddEditLinkModal}
setShowModal={setShowAddEditLinkModal}
className="max-w-screen-lg"
- disableDefaultHide={homepageDemo ? false : true}
+ preventDefaultClose={homepageDemo ? false : true}
{...(welcomeFlow && { onClose: () => router.back() })}
>
<div className="relative grid max-h-[min(906px,_90vh)] w-full divide-x divide-gray-100 overflow-auto scrollbar-hide md:grid-cols-2">
diff --git a/components/app/modals/add-project-modal.tsx b/components/app/modals/add-project-modal.tsx
index 24c71d7fb2..4c185e108d 100644
--- a/components/app/modals/add-project-modal.tsx
+++ b/components/app/modals/add-project-modal.tsx
@@ -86,7 +86,7 @@ function AddProjectModalHelper({
<Modal
showModal={showAddProjectModal}
setShowModal={setShowAddProjectModal}
- disableDefaultHide={welcomeFlow}
+ preventDefaultClose={welcomeFlow}
{...(welcomeFlow && { onClose: () => router.back() })}
>
<div className="flex flex-col items-center justify-center space-y-3 border-b border-gray-200 px-4 py-4 pt-8 sm:px-16">
diff --git a/components/app/modals/upgrade-plan-modal.tsx b/components/app/modals/upgrade-plan-modal.tsx
index dd43507b8b..67d5399a1b 100644
--- a/components/app/modals/upgrade-plan-modal.tsx
+++ b/components/app/modals/upgrade-plan-modal.tsx
@@ -56,7 +56,7 @@ function UpgradePlanModal({
showModal={showUpgradePlanModal}
setShowModal={setShowUpgradePlanModal}
className="max-w-lg"
- disableDefaultHide={welcomeFlow}
+ preventDefaultClose={welcomeFlow}
{...(welcomeFlow && { onClose: () => router.back() })}
>
<motion.div
diff --git a/components/stats/devices.tsx b/components/stats/devices.tsx
index 771b8b969d..89db1d63af 100644
--- a/components/stats/devices.tsx
+++ b/components/stats/devices.tsx
@@ -1,20 +1,21 @@
-import { useContext, useMemo, useState } from "react";
+import { useContext, useState } from "react";
import { useRouter } from "next/router";
-import { motion } from "framer-motion";
import TabSelect from "@/components/shared/tab-select";
import { LoadingCircle } from "#/ui/icons";
import { DeviceTabs, uaToBot } from "#/lib/stats";
-import { nFormatter } from "#/lib/utils";
import DeviceIcon from "./device-icon";
import useSWR from "swr";
import { fetcher } from "#/lib/utils";
import { StatsContext } from ".";
+import BarList from "#/ui/stats/bar-list";
+import { Maximize } from "lucide-react";
+import Modal from "#/ui/modal";
export default function Devices() {
const [tab, setTab] = useState<DeviceTabs>("device");
const router = useRouter();
- const { endpoint, queryString } = useContext(StatsContext);
+ const { endpoint, queryString, modal } = useContext(StatsContext);
const { data } = useSWR<
({
@@ -26,71 +27,75 @@ export default function Devices() {
router.isReady && `${endpoint}/clicks${queryString}`,
fetcher,
);
+ const [showModal, setShowModal] = useState(false);
+
+ const barList = (limit?: number) => (
+ <BarList
+ tab={tab}
+ data={
+ data?.map((d) => ({
+ icon: (
+ <DeviceIcon
+ display={tab === "bot" ? uaToBot(d.ua) : d[tab]}
+ tab={tab}
+ className="h-4 w-4"
+ />
+ ),
+ title: tab === "bot" ? uaToBot(d.ua) : d[tab],
+ clicks: d.clicks,
+ })) || []
+ }
+ totalClicks={totalClicks || 0}
+ barBackground="bg-green-100"
+ {...(limit && { limit })}
+ />
+ );
return (
- <div className="relative z-0 h-[420px] overflow-scroll border border-gray-200 bg-white px-7 py-5 scrollbar-hide sm:rounded-lg sm:border-gray-100 sm:shadow-lg">
- <div className="mb-5 flex justify-between">
- <h1 className="text-xl font-semibold">Devices</h1>
- <TabSelect
- options={["device", "browser", "os", "bot"]}
- selected={tab}
- // @ts-ignore
- selectAction={setTab}
- />
- </div>
- <div
- className={
- data && data.length > 0
- ? "grid gap-4"
- : "flex h-[300px] items-center justify-center"
- }
+ <>
+ <Modal
+ showModal={showModal}
+ setShowModal={setShowModal}
+ className="max-w-lg"
>
+ <div className="border-b border-gray-200 px-6 py-4">
+ <h1 className="text-xl font-semibold">Devices</h1>
+ </div>
+ {barList()}
+ </Modal>
+ <div className="relative z-0 h-[400px] overflow-scroll border border-gray-200 bg-white px-7 py-5 scrollbar-hide sm:rounded-lg sm:border-gray-100 sm:shadow-lg">
+ <div className="mb-5 flex justify-between">
+ <h1 className="text-xl font-semibold">Devices</h1>
+ <TabSelect
+ options={["device", "browser", "os", "bot"]}
+ selected={tab}
+ // @ts-ignore
+ selectAction={setTab}
+ />
+ </div>
{data ? (
data.length > 0 ? (
- data.map((d, idx) => (
- <div key={idx} className="flex items-center justify-between">
- <div className="relative z-10 flex w-full max-w-[calc(100%-3rem)] items-center">
- <span className="z-10 flex items-center space-x-2 px-2">
- <DeviceIcon
- display={tab === "bot" ? uaToBot(d.ua) : d[tab]}
- tab={tab}
- className="h-4 w-4"
- />
- <p className="text-sm text-gray-800">
- {tab === "bot" ? uaToBot(d.ua) : d[tab]}
- </p>
- </span>
- <motion.div
- style={{
- width: `${
- (d.clicks /
- (tab === "bot"
- ? data?.reduce(
- (acc, curr) => acc + curr.clicks,
- 0,
- ) || 0
- : totalClicks || 0)) *
- 100
- }%`,
- }}
- className="absolute h-8 origin-left bg-green-100"
- transition={{ ease: "easeOut", duration: 0.3 }}
- initial={{ transform: "scaleX(0)" }}
- animate={{ transform: "scaleX(1)" }}
- />
- </div>
- <p className="z-10 text-sm text-gray-600">
- {nFormatter(d.clicks)}
- </p>
- </div>
- ))
+ barList(9)
) : (
- <p className="text-sm text-gray-600">No data available</p>
+ <div className="flex h-[300px] items-center justify-center">
+ <p className="text-sm text-gray-600">No data available</p>
+ </div>
)
) : (
- <LoadingCircle />
+ <div className="flex h-[300px] items-center justify-center">
+ <LoadingCircle />
+ </div>
+ )}
+ {!modal && data && data.length > 9 && (
+ <button
+ onClick={() => setShowModal(true)}
+ className="absolute inset-x-0 bottom-4 z-10 mx-auto flex max-w-fit items-center space-x-2 rounded-md bg-white px-4 py-1.5 text-gray-500 transition-all hover:text-gray-800 active:scale-95"
+ >
+ <Maximize className="h-4 w-4" />
+ <p className="text-xs font-semibold uppercase">View all</p>
+ </button>
)}
</div>
- </div>
+ </>
);
}
diff --git a/components/stats/feedback.tsx b/components/stats/feedback.tsx
index 94c96a9610..88694c769f 100644
--- a/components/stats/feedback.tsx
+++ b/components/stats/feedback.tsx
@@ -54,7 +54,7 @@ export default function Feedback() {
);
return (
- <div className="relative z-0 h-[420px] overflow-scroll border border-gray-200 bg-white px-7 py-5 scrollbar-hide sm:rounded-lg sm:border-gray-100 sm:shadow-lg">
+ <div className="relative z-0 h-[400px] overflow-scroll border border-gray-200 bg-white px-7 py-5 scrollbar-hide sm:rounded-lg sm:border-gray-100 sm:shadow-lg">
<div className="mb-5 flex">
<h1 className="text-xl font-semibold">Feedback</h1>
</div>
diff --git a/components/stats/locations.tsx b/components/stats/locations.tsx
index 133fab7107..0da43be635 100644
--- a/components/stats/locations.tsx
+++ b/components/stats/locations.tsx
@@ -1,20 +1,21 @@
import { useContext, useState } from "react";
-import { motion } from "framer-motion";
import TabSelect from "@/components/shared/tab-select";
import { COUNTRIES } from "#/lib/constants";
import { LocationTabs } from "#/lib/stats";
-import { nFormatter } from "#/lib/utils";
import { LoadingCircle } from "#/ui/icons";
import { useRouter } from "next/router";
import useSWR from "swr";
import { fetcher } from "#/lib/utils";
import { StatsContext } from ".";
+import { Maximize } from "lucide-react";
+import BarList from "#/ui/stats/bar-list";
+import Modal from "#/ui/modal";
export default function Locations() {
const [tab, setTab] = useState<LocationTabs>("country");
const router = useRouter();
- const { endpoint, queryString } = useContext(StatsContext);
+ const { endpoint, queryString, modal } = useContext(StatsContext);
const { data } = useSWR<{ country: string; city: string; clicks: number }[]>(
router.isReady && `${endpoint}/${tab}${queryString}`,
@@ -26,61 +27,75 @@ export default function Locations() {
fetcher,
);
+ const [showModal, setShowModal] = useState(false);
+
+ const barList = (limit?: number) => (
+ <BarList
+ tab={tab}
+ data={
+ data?.map((d) => ({
+ icon: (
+ <img
+ alt={d.country}
+ src={`https://flag.vercel.app/m/${d.country}.svg`}
+ className="h-3 w-5"
+ />
+ ),
+ title: tab === "country" ? COUNTRIES[d.country] : d.city,
+ clicks: d.clicks,
+ })) || []
+ }
+ totalClicks={totalClicks || 0}
+ barBackground="bg-orange-100"
+ {...(limit && { limit })}
+ />
+ );
+
return (
- <div className="relative z-0 h-[420px] overflow-scroll border border-gray-200 bg-white px-7 py-5 scrollbar-hide sm:rounded-lg sm:border-gray-100 sm:shadow-lg">
- <div className="mb-5 flex justify-between">
- <h1 className="text-xl font-semibold">Locations</h1>
- <TabSelect
- options={["country", "city"]}
- selected={tab}
- // @ts-ignore
- selectAction={setTab}
- />
- </div>
- <div
- className={
- data && data.length > 0
- ? "grid gap-4"
- : "flex h-[300px] items-center justify-center"
- }
+ <>
+ <Modal
+ showModal={showModal}
+ setShowModal={setShowModal}
+ className="max-w-lg"
>
+ <div className="border-b border-gray-200 px-6 py-4">
+ <h1 className="text-xl font-semibold">Locations</h1>
+ </div>
+ {barList()}
+ </Modal>
+ <div className="relative z-0 h-[400px] overflow-scroll border border-gray-200 bg-white px-7 py-5 scrollbar-hide sm:rounded-lg sm:border-gray-100 sm:shadow-lg">
+ <div className="mb-5 flex justify-between">
+ <h1 className="text-xl font-semibold">Locations</h1>
+ <TabSelect
+ options={["country", "city"]}
+ selected={tab}
+ // @ts-ignore
+ selectAction={setTab}
+ />
+ </div>
{data ? (
data.length > 0 ? (
- data.map(({ country, city, clicks }, idx) => (
- <div key={idx} className="flex items-center justify-between">
- <div className="relative z-10 flex w-full max-w-[calc(100%-3rem)] items-center">
- <span className="z-10 flex items-center space-x-2 px-2">
- <img
- alt={country}
- src={`https://flag.vercel.app/m/${country}.svg`}
- className="h-3 w-5"
- />
- <p className="text-sm text-gray-800">
- {tab === "country" ? COUNTRIES[country] : city}
- </p>
- </span>
- <motion.div
- style={{
- width: `${(clicks / (totalClicks || 0)) * 100}%`,
- }}
- className="absolute h-8 origin-left bg-orange-100"
- transition={{ ease: "easeOut", duration: 0.3 }}
- initial={{ transform: "scaleX(0)" }}
- animate={{ transform: "scaleX(1)" }}
- />
- </div>
- <p className="z-10 text-sm text-gray-600">
- {nFormatter(clicks)}
- </p>
- </div>
- ))
+ barList(9)
) : (
- <p className="text-sm text-gray-600">No data available</p>
+ <div className="flex h-[300px] items-center justify-center">
+ <p className="text-sm text-gray-600">No data available</p>
+ </div>
)
) : (
- <LoadingCircle />
+ <div className="flex h-[300px] items-center justify-center">
+ <LoadingCircle />
+ </div>
+ )}
+ {!modal && data && data.length > 9 && (
+ <button
+ onClick={() => setShowModal(true)}
+ className="absolute inset-x-0 bottom-4 z-10 mx-auto flex max-w-fit items-center space-x-2 rounded-md bg-white px-4 py-1.5 text-gray-500 transition-all hover:text-gray-800 active:scale-95"
+ >
+ <Maximize className="h-4 w-4" />
+ <p className="text-xs font-semibold uppercase">View all</p>
+ </button>
)}
</div>
- </div>
+ </>
);
}
diff --git a/components/stats/referer.tsx b/components/stats/referer.tsx
index cdeb3e6d43..bcb82c7dcc 100644
--- a/components/stats/referer.tsx
+++ b/components/stats/referer.tsx
@@ -1,19 +1,20 @@
import { useRouter } from "next/router";
-import { motion } from "framer-motion";
import BlurImage from "#/ui/blur-image";
import { Link2 } from "lucide-react";
import { LoadingCircle } from "#/ui/icons";
-import { nFormatter } from "#/lib/utils";
import useSWR from "swr";
import { fetcher } from "#/lib/utils";
import { GOOGLE_FAVICON_URL } from "#/lib/constants";
-import { useContext } from "react";
+import { useContext, useState } from "react";
import { StatsContext } from ".";
+import BarList from "#/ui/stats/bar-list";
+import { Maximize } from "lucide-react";
+import Modal from "#/ui/modal";
export default function Referer() {
const router = useRouter();
- const { endpoint, queryString } = useContext(StatsContext);
+ const { endpoint, queryString, modal } = useContext(StatsContext);
const { data } = useSWR<{ referer: string; clicks: number }[]>(
router.isReady && `${endpoint}/referer${queryString}`,
@@ -25,59 +26,73 @@ export default function Referer() {
fetcher,
);
+ const [showModal, setShowModal] = useState(false);
+
+ const barList = (limit?: number) => (
+ <BarList
+ tab="Referrer"
+ data={
+ data?.map((d) => ({
+ icon:
+ d.referer === "(direct)" ? (
+ <Link2 className="h-4 w-4" />
+ ) : (
+ <BlurImage
+ src={`${GOOGLE_FAVICON_URL}${d.referer}`}
+ alt={d.referer}
+ width={20}
+ height={20}
+ className="h-4 w-4 rounded-full"
+ />
+ ),
+ title: d.referer,
+ clicks: d.clicks,
+ })) || []
+ }
+ totalClicks={totalClicks || 0}
+ barBackground="bg-red-100"
+ {...(limit && { limit })}
+ />
+ );
return (
- <div className="relative z-0 h-[420px] overflow-scroll border border-gray-200 bg-white px-7 py-5 scrollbar-hide sm:rounded-lg sm:border-gray-100 sm:shadow-lg">
- <div className="mb-5 flex">
- <h1 className="text-xl font-semibold">Referrers</h1>
- </div>
- <div
- className={
- data && data.length > 0
- ? "grid gap-4"
- : "flex h-[300px] items-center justify-center"
- }
+ <>
+ <Modal
+ showModal={showModal}
+ setShowModal={setShowModal}
+ className="max-w-lg"
>
+ <div className="border-b border-gray-200 px-6 py-4">
+ <h1 className="text-xl font-semibold">Referrers</h1>
+ </div>
+ {barList()}
+ </Modal>
+ <div className="relative z-0 h-[400px] overflow-scroll border border-gray-200 bg-white px-7 py-5 scrollbar-hide sm:rounded-lg sm:border-gray-100 sm:shadow-lg">
+ <div className="mb-5 flex">
+ <h1 className="text-xl font-semibold">Referrers</h1>
+ </div>
{data ? (
data.length > 0 ? (
- data.map(({ referer, clicks }, idx) => (
- <div key={idx} className="flex items-center justify-between">
- <div className="relative z-10 flex w-full max-w-[calc(100%-3rem)] items-center">
- <span className="z-10 flex items-center space-x-2 px-2">
- {referer === "(direct)" ? (
- <Link2 className="h-4 w-4" />
- ) : (
- <BlurImage
- src={`${GOOGLE_FAVICON_URL}${referer}`}
- alt={referer}
- width={20}
- height={20}
- className="h-4 w-4 rounded-full"
- />
- )}
- <p className="text-sm text-gray-800">{referer}</p>
- </span>
- <motion.div
- style={{
- width: `${(clicks / (totalClicks || 0)) * 100}%`,
- }}
- className="absolute h-8 origin-left rounded bg-red-100"
- transition={{ ease: "easeOut", duration: 0.3 }}
- initial={{ transform: "scaleX(0)" }}
- animate={{ transform: "scaleX(1)" }}
- />
- </div>
- <p className="z-10 text-sm text-gray-600">
- {nFormatter(clicks)}
- </p>
- </div>
- ))
+ barList(9)
) : (
- <p className="text-sm text-gray-600">No data available</p>
+ <div className="flex h-[300px] items-center justify-center">
+ <p className="text-sm text-gray-600">No data available</p>
+ </div>
)
) : (
- <LoadingCircle />
+ <div className="flex h-[300px] items-center justify-center">
+ <LoadingCircle />
+ </div>
+ )}
+ {!modal && data && data.length > 9 && (
+ <button
+ onClick={() => setShowModal(true)}
+ className="absolute inset-x-0 bottom-4 z-10 mx-auto flex max-w-fit items-center space-x-2 rounded-md bg-white px-4 py-1.5 text-gray-500 transition-all hover:text-gray-800 active:scale-95"
+ >
+ <Maximize className="h-4 w-4" />
+ <p className="text-xs font-semibold uppercase">View all</p>
+ </button>
)}
</div>
- </div>
+ </>
);
}
diff --git a/lib/constants/index.ts b/lib/constants/index.ts
index ec9625974b..0e658505e0 100644
--- a/lib/constants/index.ts
+++ b/lib/constants/index.ts
@@ -48,6 +48,7 @@ export const HOME_DOMAIN =
export const APP_HOSTNAMES = new Set([
"app.dub.sh",
"app.localhost:3000",
+ "app.localhost",
"preview.dub.sh",
]);
diff --git a/lib/hooks/use-media-query.ts b/lib/hooks/use-media-query.ts
new file mode 100644
index 0000000000..c91e543e18
--- /dev/null
+++ b/lib/hooks/use-media-query.ts
@@ -0,0 +1,46 @@
+import { useEffect, useState } from "react";
+
+export default function useMediaQuery() {
+ const [device, setDevice] = useState<"mobile" | "tablet" | "desktop" | null>(
+ null,
+ );
+ const [dimensions, setDimensions] = useState<{
+ width: number;
+ height: number;
+ } | null>(null);
+
+ useEffect(() => {
+ const checkDevice = () => {
+ if (window.matchMedia("(max-width: 640px)").matches) {
+ setDevice("mobile");
+ } else if (
+ window.matchMedia("(min-width: 641px) and (max-width: 1024px)").matches
+ ) {
+ setDevice("tablet");
+ } else {
+ setDevice("desktop");
+ }
+ setDimensions({ width: window.innerWidth, height: window.innerHeight });
+ };
+
+ // Initial detection
+ checkDevice();
+
+ // Listener for windows resize
+ window.addEventListener("resize", checkDevice);
+
+ // Cleanup listener
+ return () => {
+ window.removeEventListener("resize", checkDevice);
+ };
+ }, []);
+
+ return {
+ device,
+ width: dimensions?.width,
+ height: dimensions?.height,
+ isMobile: device === "mobile",
+ isTablet: device === "tablet",
+ isDesktop: device === "desktop",
+ };
+}
diff --git a/lib/hooks/use-window-size.ts b/lib/hooks/use-window-size.ts
deleted file mode 100644
index cc75212b78..0000000000
--- a/lib/hooks/use-window-size.ts
+++ /dev/null
@@ -1,47 +0,0 @@
-import { useState, useEffect, useMemo } from "react";
-
-// Hook
-export default function useWindowSize(): {
- width: number;
- height: number;
- isMobile: boolean;
- isDesktop: boolean;
-} {
- // Initialize state with undefined width/height so server and client renders match
- // Learn more here: https://joshwcomeau.com/react/the-perils-of-rehydration/
- const [windowSize, setWindowSize] = useState<{
- width: number;
- height: number;
- }>({
- width: 0,
- height: 0,
- });
- useEffect(() => {
- // Handler to call on window resize
- function handleResize() {
- // Set window width/height to state
- setWindowSize({
- width: window.innerWidth,
- height: window.innerHeight,
- });
- }
- // Add event listener
- window.addEventListener("resize", handleResize);
- // Call handler right away so state gets updated with initial window size
- handleResize();
- // Remove event listener on cleanup
- return () => window.removeEventListener("resize", handleResize);
- }, []); // Empty array ensures that effect is only run on mount
-
- // Memoize the result of the calculations using useMemo
- const memoizedWindowSize = useMemo(() => {
- return {
- ...windowSize,
- isMobile: typeof windowSize?.width === "number" && windowSize.width < 768,
- isDesktop:
- typeof windowSize?.width === "number" && windowSize.width >= 768,
- };
- }, [windowSize]);
-
- return memoizedWindowSize;
-}
diff --git a/tailwind.config.js b/tailwind.config.js
index 7be5af0a27..b20c3481ab 100644
--- a/tailwind.config.js
+++ b/tailwind.config.js
@@ -17,6 +17,7 @@ module.exports = {
animation: {
// Modal
"scale-in": "scale-in 0.2s cubic-bezier(0.16, 1, 0.3, 1)",
+ "fade-in": "fade-in 0.3s ease-out forwards",
// Input Select
"input-select-slide-up":
"input-select-slide-up 0.2s cubic-bezier(0.16, 1, 0.3, 1)",
@@ -47,6 +48,10 @@ module.exports = {
"0%": { transform: "scale(0.95)" },
"100%": { transform: "scale(1)" },
},
+ "fade-in": {
+ "0%": { opacity: 0 },
+ "100%": { opacity: 1 },
+ },
// Input Select
"input-select-slide-up": {
"0%": { transform: "translateY(-342px)" },