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 useLinksCount, hide link display, etc.

Steven Tey79f307725f03
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/library/folders/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/library/folders/page-client.tsx
index 26fa486771..8d2c17160c 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/library/folders/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/library/folders/page-client.tsx
@@ -15,6 +15,7 @@ import { useRouter, useSearchParams } from "next/navigation";
const allLinkFolder: Folder = {
id: "unsorted",
name: "Links",
+ type: "default",
accessLevel: null,
linkCount: 0,
createdAt: new Date(),
diff --git a/apps/web/lib/swr/use-links-count.ts b/apps/web/lib/swr/use-links-count.ts
index 65deb82e3b..78f5898323 100644
--- a/apps/web/lib/swr/use-links-count.ts
+++ b/apps/web/lib/swr/use-links-count.ts
@@ -4,6 +4,7 @@ import { useEffect, useState } from "react";
import useSWR from "swr";
import z from "../zod";
import { getLinksCountQuerySchema } from "../zod/schemas/links";
+import useFolder from "./use-folder";
import useWorkspace from "./use-workspace";
const partialQuerySchema = getLinksCountQuerySchema.partial();
@@ -11,14 +12,14 @@ const partialQuerySchema = getLinksCountQuerySchema.partial();
export default function useLinksCount<T = any>({
query,
ignoreParams,
- enabled = true,
+ enabled,
}: {
query?: z.infer<typeof partialQuerySchema>;
ignoreParams?: boolean;
enabled?: boolean;
} = {}) {
const { id: workspaceId } = useWorkspace();
- const { getQueryString } = useRouterStuff();
+ const { searchParamsObj, getQueryString } = useRouterStuff();
const [admin, setAdmin] = useState(false);
useEffect(() => {
@@ -26,27 +27,28 @@ export default function useLinksCount<T = any>({
setAdmin(true);
}
}, []);
+ const { folder: currentFolder } = useFolder({
+ folderId: searchParamsObj.folderId,
+ });
const { data, error } = useSWR<any>(
- !enabled
- ? null
- : workspaceId
- ? `/api/links/count${getQueryString(
- {
- workspaceId,
- ...query,
- },
- ignoreParams
- ? { include: [] }
- : {
- exclude: ["import", "upgrade", "newLink"],
- },
- )}`
- : admin
- ? `/api/admin/links/count${getQueryString({
- ...query,
- })}`
- : null,
+ workspaceId && currentFolder?.type !== "mega" && enabled
+ ? `/api/links/count${getQueryString(
+ {
+ workspaceId,
+ ...query,
+ },
+ ignoreParams
+ ? { include: [] }
+ : {
+ exclude: ["import", "upgrade", "newLink"],
+ },
+ )}`
+ : admin
+ ? `/api/admin/links/count${getQueryString({
+ ...query,
+ })}`
+ : null,
fetcher,
{
dedupingInterval: 60000,
diff --git a/apps/web/ui/links/link-display.tsx b/apps/web/ui/links/link-display.tsx
index 39ad7f1adc..098d29180f 100644
--- a/apps/web/ui/links/link-display.tsx
+++ b/apps/web/ui/links/link-display.tsx
@@ -1,3 +1,4 @@
+import useFolder from "@/lib/swr/use-folder";
import {
Button,
Popover,
@@ -15,6 +16,7 @@ import {
import { cn } from "@dub/utils";
import { AnimatePresence, motion } from "framer-motion";
import { ChevronDown } from "lucide-react";
+import { useSearchParams } from "next/navigation";
import { useContext, useState } from "react";
import LinkSort from "./link-sort";
import {
@@ -36,6 +38,12 @@ export default function LinkDisplay() {
reset,
} = useContext(LinksDisplayContext);
+ const searchParams = useSearchParams();
+ const folderId = searchParams.get("folderId");
+ const { folder: currentFolder } = useFolder({
+ folderId,
+ });
+
const [openPopover, setOpenPopover] = useState(false);
const { queryParams } = useRouterStuff();
@@ -74,15 +82,17 @@ export default function LinkDisplay() {
);
})}
</div>
- <div className="flex h-16 items-center justify-between gap-2 px-4">
- <span className="flex items-center gap-2">
- <ArrowsOppositeDirectionY className="h-4 w-4 text-neutral-800" />
- Ordering
- </span>
- <div>
- <LinkSort />
+ {currentFolder?.type !== "mega" && (
+ <div className="flex h-16 items-center justify-between gap-2 px-4">
+ <span className="flex items-center gap-2">
+ <ArrowsOppositeDirectionY className="h-4 w-4 text-neutral-800" />
+ Ordering
+ </span>
+ <div>
+ <LinkSort />
+ </div>
</div>
- </div>
+ )}
<div className="group flex h-16 items-center justify-between gap-2 px-4">
<div className="flex items-center gap-2">
<div className="flex w-6 items-center justify-center">
diff --git a/apps/web/ui/links/links-container.tsx b/apps/web/ui/links/links-container.tsx
index 16efb3a69e..8799ccdcbc 100644
--- a/apps/web/ui/links/links-container.tsx
+++ b/apps/web/ui/links/links-container.tsx
@@ -39,7 +39,6 @@ export default function LinksContainer({
const { links, isValidating } = useLinks({ sortBy, showArchived });
const { data: count } = useLinksCount<number>({
- enabled: currentFolder && currentFolder?.type !== "mega",
query: { showArchived },
});