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 the count of links in a folder

Kiran Kbc8c53230508
diff --git a/apps/web/app/api/links/count/route.ts b/apps/web/app/api/links/count/route.ts
index 5a386699dd..09a7c1a69f 100644
--- a/apps/web/app/api/links/count/route.ts
+++ b/apps/web/app/api/links/count/route.ts
@@ -19,6 +19,8 @@ export const GET = withWorkspace(
workspaceId: workspace.id,
});
+ console.log("count", count);
+
return NextResponse.json(count, {
headers,
});
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/folders/[folderId]/members/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/folders/[folderId]/members/page-client.tsx
index b9aab8997a..a19eef5153 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/folders/[folderId]/members/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/folders/[folderId]/members/page-client.tsx
@@ -8,10 +8,11 @@ import {
} from "@/lib/link-folder/constants";
import { getFolderPermissions } from "@/lib/link-folder/permissions";
import { FolderUserProps, FolderWithRole } from "@/lib/link-folder/types";
+import useLinksCount from "@/lib/swr/use-links-count";
import useWorkspace from "@/lib/swr/use-workspace";
import { AskToEditButton } from "@/ui/folders/ask-to-edit-button";
import { Avatar, Globe } from "@dub/ui";
-import { cn, fetcher } from "@dub/utils";
+import { cn, fetcher, nFormatter } from "@dub/utils";
import { FolderUserRole } from "@prisma/client";
import { ChevronLeft, FolderIcon } from "lucide-react";
import { useAction } from "next-safe-action/hooks";
@@ -44,6 +45,11 @@ export const FolderUsersPageClient = ({ folderId }: { folderId: string }) => {
fetcher,
);
+ const { data: numberOfLinks } = useLinksCount({
+ showArchived: true,
+ folderId,
+ });
+
if (!isFolderLoading && !folder) {
notFound();
}
@@ -106,7 +112,8 @@ export const FolderUsersPageClient = ({ folderId }: { folderId: string }) => {
<div className="flex items-center gap-1">
<Globe className="size-3.5 text-gray-500" />
<span className="text-[13px] font-normal leading-[14.30px] text-gray-500">
- 100 links
+ {nFormatter(numberOfLinks)} link
+ {numberOfLinks !== 1 && "s"}
</span>
</div>
</div>
diff --git a/apps/web/lib/api/links/get-links-count.ts b/apps/web/lib/api/links/get-links-count.ts
index 2b3da10c3b..7cb3401ff6 100644
--- a/apps/web/lib/api/links/get-links-count.ts
+++ b/apps/web/lib/api/links/get-links-count.ts
@@ -21,10 +21,9 @@ export async function getLinksCount({
userId,
showArchived,
withTags,
+ folderId,
} = searchParams;
- console.log({ groupBy });
-
const combinedTagIds = combineTagIds({ tagId, tagIds });
const linksWhere = {
@@ -50,6 +49,10 @@ export async function getLinksCount({
groupBy !== "userId" && {
userId,
}),
+ ...(folderId &&
+ groupBy !== "folderId" && {
+ folderId,
+ }),
};
if (groupBy === "tagId") {