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.

small fixes

Steven Tey6460ee50fb08
diff --git a/app/(marketing)/@modal/(...)stats/[key]/page.tsx b/app/(marketing)/@modal/(...)stats/[key]/page.tsx
index 58a54d3f3d..919b78b972 100644
--- a/app/(marketing)/@modal/(...)stats/[key]/page.tsx
+++ b/app/(marketing)/@modal/(...)stats/[key]/page.tsx
@@ -8,7 +8,7 @@ export default function StatsModal({ params }: { params: { key: string } }) {
className="inline-block max-h-[calc(100vh-150px)] w-full max-w-screen-xl transform overflow-scroll bg-gray-50
align-middle shadow-xl scrollbar-hide md:rounded-2xl md:border md:border-gray-200"
>
- <Stats staticDomain="dub.sh" staticKey={params.key} />
+ <Stats staticDomain="dub.sh" staticKey={params.key} modal />
</div>
</Modal>
);
diff --git a/app/lib/hooks/use-scroll.ts b/app/lib/hooks/use-scroll.ts
index 6be621b58a..3c8014e31d 100644
--- a/app/lib/hooks/use-scroll.ts
+++ b/app/lib/hooks/use-scroll.ts
@@ -1,28 +1,16 @@
-import { useCallback, useEffect, useState, RefObject } from "react";
+import { useCallback, useEffect, useState } from "react";
-export default function useScroll(
- threshold: number,
- ref?: RefObject<HTMLDivElement>,
-) {
+export default function useScroll(threshold: number) {
const [scrolled, setScrolled] = useState(false);
const onScroll = useCallback(() => {
- if (ref && ref.current) {
- setScrolled(ref.current.scrollTop > threshold);
- } else {
- setScrolled(window.pageYOffset > threshold);
- }
- }, [threshold, ref]);
+ setScrolled(window.pageYOffset > threshold);
+ }, [threshold]);
useEffect(() => {
- if (ref && ref.current) {
- ref.current.addEventListener("scroll", onScroll);
- return () => ref.current?.removeEventListener("scroll", onScroll);
- } else {
- window.addEventListener("scroll", onScroll);
- return () => window.removeEventListener("scroll", onScroll);
- }
- }, [onScroll, ref]);
+ window.addEventListener("scroll", onScroll);
+ return () => window.removeEventListener("scroll", onScroll);
+ }, [onScroll]);
return scrolled;
}
diff --git a/app/ui/stats/index.tsx b/app/ui/stats/index.tsx
index a66eacc0ba..88aab9072a 100644
--- a/app/ui/stats/index.tsx
+++ b/app/ui/stats/index.tsx
@@ -8,7 +8,7 @@
We use the `useEndpoint()` hook to get the correct layout
*/
-import { createContext, useMemo, useRef } from "react";
+import { createContext, useCallback, useMemo, useRef, useState } from "react";
import { useParams, usePathname, useSearchParams } from "next/navigation";
import Clicks from "./clicks";
import Devices from "./devices";
@@ -16,6 +16,7 @@ import Feedback from "./feedback";
import Locations from "./locations";
import Referer from "./referer";
import Toggle from "./toggle";
+import useScroll from "#/lib/hooks/use-scroll";
export const StatsContext = createContext<{
basePath: string;
@@ -24,6 +25,7 @@ export const StatsContext = createContext<{
interval: string;
domain: string;
key: string;
+ modal?: boolean;
}>({
basePath: "",
endpoint: "",
@@ -31,14 +33,17 @@ export const StatsContext = createContext<{
interval: "",
domain: "",
key: "",
+ modal: false,
});
export default function Stats({
staticDomain,
staticKey,
+ modal,
}: {
staticDomain?: string;
staticKey?: string;
+ modal?: boolean;
}) {
const params = useParams();
const searchParams = useSearchParams() || new URLSearchParams();
@@ -100,6 +105,7 @@ export default function Stats({
queryString, // query string for the API (e.g. ?interval=24h&domain=dub.sh, ?interval=24h, etc.)
interval, // time interval (e.g. 24h, 7d, 30d, etc.)
key, // link key (e.g. github, weathergpt, etc.)
+ modal, // whether or not this is a modal
}}
>
<div className="bg-gray-50 py-10">
diff --git a/app/ui/stats/toggle.tsx b/app/ui/stats/toggle.tsx
index 7ed3acd4f5..86910ade4d 100644
--- a/app/ui/stats/toggle.tsx
+++ b/app/ui/stats/toggle.tsx
@@ -20,7 +20,7 @@ import { StatsContext } from ".";
import useScroll from "#/lib/hooks/use-scroll";
export default function Toggle() {
- const { basePath, domain, interval, key } = useContext(StatsContext);
+ const { basePath, domain, interval, key, modal } = useContext(StatsContext);
const [openDatePopover, setOpenDatePopover] = useState(false);
@@ -33,8 +33,12 @@ export default function Toggle() {
return (
<div
className={`z-20 mb-5 ${
- basePath.startsWith("/stats") ? "top-0 md:top-16" : "top-[6.95rem]"
- } sticky bg-gray-50 py-3 md:py-5 ${scrolled ? "shadow-md" : ""}`}
+ basePath.startsWith("/stats")
+ ? `top-0 ${!modal ? "md:top-16" : ""}`
+ : "top-[6.95rem]"
+ } sticky bg-gray-50 py-3 md:py-5 ${
+ scrolled && !modal ? "shadow-md" : ""
+ }`}
>
<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">
<a