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.

Update folder-dropdown.tsx

Steven Tey484f30a5deaa
diff --git a/apps/web/ui/folders/folder-dropdown.tsx b/apps/web/ui/folders/folder-dropdown.tsx
index c5ffc637b7..8a53fe24f1 100644
--- a/apps/web/ui/folders/folder-dropdown.tsx
+++ b/apps/web/ui/folders/folder-dropdown.tsx
@@ -2,11 +2,12 @@ import { unsortedLinks } from "@/lib/folder/constants";
import { getPlanCapabilities } from "@/lib/plan-capabilities";
import useFolder from "@/lib/swr/use-folder";
import useFolders from "@/lib/swr/use-folders";
+import useLinksCount from "@/lib/swr/use-links-count";
import useWorkspace from "@/lib/swr/use-workspace";
import { FolderSummary } from "@/lib/types";
import { FOLDERS_MAX_PAGE_SIZE } from "@/lib/zod/schemas/folders";
import { Button, Combobox, TooltipContent, useRouterStuff } from "@dub/ui";
-import { cn } from "@dub/utils";
+import { cn, nFormatter } from "@dub/utils";
import { ChevronsUpDown } from "lucide-react";
import Link from "next/link";
import { useRouter } from "next/navigation";
@@ -63,6 +64,13 @@ export const FolderDropdown = ({
setUseAsync(true);
}, [folders, useAsync]);
+ const { data: folderLinksCount } = useLinksCount<
+ {
+ folderId: string;
+ _count: number;
+ }[]
+ >({ query: { groupBy: "folderId" }, ignoreParams: true });
+
const [openPopover, setOpenPopover] = useState(false);
const [selectedFolder, setSelectedFolder] = useState<FolderSummary | null>(
@@ -122,7 +130,15 @@ export const FolderDropdown = ({
value: folder.id,
label: folder.name,
icon: <FolderIcon className="mr-1" folder={folder} shape="square" />,
- meta: folder,
+ meta: {
+ ...folder,
+ linksCount:
+ folderLinksCount?.find(
+ ({ folderId }) =>
+ folderId === folder.id ||
+ (folder.id === "unsorted" && folderId === null),
+ )?._count || 0,
+ },
first: folder.id === "unsorted",
})),
{
@@ -210,10 +226,10 @@ export const FolderDropdown = ({
) : undefined
}
optionRight={(option) =>
- option.value === "unsorted" ? (
- <div className="rounded bg-neutral-100 p-1">
- <div className="text-xs font-normal text-black">Unsorted</div>
- </div>
+ option.meta && "linksCount" in option.meta ? (
+ <span className="text-xs text-neutral-500">
+ {nFormatter(option.meta.linksCount, { full: true })}
+ </span>
) : undefined
}
caret={