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.

fix links & domains

Steven Tey3cbca9cac4c4
diff --git a/apps/web/ui/analytics/top-links.tsx b/apps/web/ui/analytics/top-links.tsx
index 98ca9205c7..7bedf8c5d2 100644
--- a/apps/web/ui/analytics/top-links.tsx
+++ b/apps/web/ui/analytics/top-links.tsx
@@ -1,7 +1,6 @@
import { useRouterStuff } from "@dub/ui";
import { getApexDomain } from "@dub/utils";
-import { useSearchParams } from "next/navigation";
-import { useContext } from "react";
+import { useContext, useState } from "react";
import { AnalyticsContext } from ".";
import LinkLogo from "../links/link-logo";
import { AnalyticsCard } from "./analytics-card";
@@ -11,13 +10,16 @@ import { useAnalyticsFilterOption } from "./utils";
export default function TopLinks() {
const { queryParams } = useRouterStuff();
- const searchParams = useSearchParams();
- const root = searchParams.get("root");
+ const [selectedTabId, setSelectedTabId] = useState<"links" | "domains">(
+ "links",
+ );
const { domain, key } = useContext(AnalyticsContext);
const showUrls = domain && key;
- const data = useAnalyticsFilterOption(`top_${showUrls ? "urls" : "links"}`);
+ const data = useAnalyticsFilterOption(`top_${showUrls ? "urls" : "links"}`, {
+ root: selectedTabId === "domains" ? "true" : "false",
+ });
return (
<AnalyticsCard
@@ -31,27 +33,9 @@ export default function TopLinks() {
}
expandLimit={8}
hasMore={(data?.length ?? 0) > 8}
- selectedTabId={
- showUrls
- ? "urls"
- : root === "false"
- ? "links"
- : root === "true"
- ? "domains"
- : "links"
- }
- onSelectTab={(tabId) =>
- queryParams({
- ...((root === "false" && tabId === "links") ||
- (root === "true" && tabId === "domains")
- ? { del: ["root"] }
- : {
- set: {
- root: tabId === "links" ? "false" : "true",
- },
- }),
- replace: true,
- })
+ selectedTabId={showUrls ? "urls" : selectedTabId}
+ onSelectTab={(tabId: "links" | "domains") =>
+ showUrls ? null : setSelectedTabId(tabId)
}
>
{({ limit, event, setShowModal }) =>
diff --git a/apps/web/ui/analytics/utils.ts b/apps/web/ui/analytics/utils.ts
index db4b4b904d..19c4f85bf5 100644
--- a/apps/web/ui/analytics/utils.ts
+++ b/apps/web/ui/analytics/utils.ts
@@ -7,6 +7,7 @@ import { AnalyticsContext } from ".";
export function useAnalyticsFilterOption(
groupBy: AnalyticsGroupByOptions,
+ additionalParams?: Record<string, any>,
): ({ count?: number } & Record<string, any>)[] | null {
const { baseApiPath, queryString, selectedTab, requiresUpgrade } =
useContext(AnalyticsContext);
@@ -14,6 +15,7 @@ export function useAnalyticsFilterOption(
const { data } = useSWR<Record<string, any>[]>(
`${baseApiPath}?${editQueryString(queryString, {
groupBy,
+ ...additionalParams,
})}`,
fetcher,
{