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.

filter the links by folderId

Kiran K746e0a5136c0
diff --git a/apps/web/app/api/links/route.ts b/apps/web/app/api/links/route.ts
index 93a71a3184..4408a8ad9a 100644
--- a/apps/web/app/api/links/route.ts
+++ b/apps/web/app/api/links/route.ts
@@ -24,7 +24,7 @@ export const GET = withWorkspace(
domain,
tagId,
tagIds,
- folderIds,
+ folderId,
search,
sort,
page,
@@ -44,7 +44,7 @@ export const GET = withWorkspace(
domain,
tagId,
tagIds,
- folderIds,
+ folderId,
search,
sort,
page,
diff --git a/apps/web/lib/api/links/get-links-for-workspace.ts b/apps/web/lib/api/links/get-links-for-workspace.ts
index 1a725b82c5..3f931e5c14 100644
--- a/apps/web/lib/api/links/get-links-for-workspace.ts
+++ b/apps/web/lib/api/links/get-links-for-workspace.ts
@@ -9,7 +9,7 @@ export async function getLinksForWorkspace({
tagId,
tagIds,
tagNames,
- folderIds,
+ folderId,
search,
sort = "createdAt",
page,
@@ -63,9 +63,9 @@ export async function getLinksForWorkspace({
...(userId && { userId }),
// Filter by folderId
- ...(folderIds && folderIds.length > 0
+ ...(folderId
? {
- folderId: { in: folderIds },
+ folderId,
}
: {}),
},
diff --git a/apps/web/lib/zod/schemas/links.ts b/apps/web/lib/zod/schemas/links.ts
index 3716688067..66680c2902 100644
--- a/apps/web/lib/zod/schemas/links.ts
+++ b/apps/web/lib/zod/schemas/links.ts
@@ -50,11 +50,10 @@ const LinksQuerySchema = z.object({
.describe(
"The unique name of the tags assigned to the short link (case insensitive).",
),
- folderIds: z
- .union([z.string(), z.array(z.string())])
- .transform((v) => (Array.isArray(v) ? v : v.split(",")))
+ folderId: z
+ .string()
.optional()
- .describe("The folder IDs to filter the links by."),
+ .describe("The folder ID to filter the links by."),
search: z
.string()
.optional()
diff --git a/apps/web/ui/folders/folder-switcher.tsx b/apps/web/ui/folders/folder-switcher.tsx
index 085855d928..382d145c54 100644
--- a/apps/web/ui/folders/folder-switcher.tsx
+++ b/apps/web/ui/folders/folder-switcher.tsx
@@ -1,38 +1,51 @@
import useFolders from "@/lib/swr/use-folders";
import { FolderProps } from "@/lib/types";
-import { Popover, Tick } from "@dub/ui";
+import { Popover, Tick, useRouterStuff } from "@dub/ui";
import { ChevronsUpDown, FolderCheck, FolderPlusIcon } from "lucide-react";
import Link from "next/link";
import { useCallback, useState } from "react";
type Folder = Pick<FolderProps, "id" | "name">;
+const allLinksFolder: Folder = {
+ id: "all-links",
+ name: "All links",
+};
+
export const FolderSwitcher = () => {
- const [openPopover, setOpenPopover] = useState(true);
- const { folders, isLoading, isValidating } = useFolders();
- const [selectedFolder, setSelectedFolder] = useState<Folder | null>(null);
+ const { folders, isLoading } = useFolders();
+ const [openPopover, setOpenPopover] = useState(false);
+ const { queryParams, searchParamsObj } = useRouterStuff();
+
+ const [selectedFolder, setSelectedFolder] = useState<Folder | null>(
+ allLinksFolder,
+ );
const handleFolderSelect = useCallback((folder: Folder) => {
setSelectedFolder(folder);
+
+ if (folder.id === "all-links") {
+ return queryParams({
+ del: "folderId",
+ });
+ }
+
+ queryParams({
+ set: {
+ folderId: folder.id,
+ },
+ });
}, []);
if (isLoading || !folders) {
return <FolderSwitcherPlaceholder />;
}
- const folderList = [
- {
- id: "all-links",
- name: "All links",
- },
- ...(folders || []),
- ];
-
return (
<Popover
content={
<FolderList
- folders={folderList}
+ folders={[allLinksFolder, ...folders]}
setOpenPopover={setOpenPopover}
onFolderSelect={handleFolderSelect}
selectedFolder={selectedFolder}
@@ -44,7 +57,7 @@ export const FolderSwitcher = () => {
>
<button className="flex items-center justify-between space-x-2 rounded-md px-3 py-1 text-sm font-medium text-gray-700 hover:bg-gray-100">
<h1 className="text-2xl font-semibold tracking-tight text-black">
- {selectedFolder?.name || "All links"}
+ {selectedFolder?.name}
</h1>
<ChevronsUpDown className="h-5 w-5 text-gray-400" aria-hidden="true" />
</button>