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.

add folder switcher

Kiran Ke0946d5bde76
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/page-client.tsx
index 6a59169f82..5a2534b748 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/page-client.tsx
@@ -2,6 +2,7 @@
import useLinks from "@/lib/swr/use-links";
import useWorkspace from "@/lib/swr/use-workspace";
+import { FolderSwitcher } from "@/ui/folders/folder-switcher";
import LinkDisplay from "@/ui/links/link-display";
import LinksContainer from "@/ui/links/links-container";
import { LinksDisplayProvider } from "@/ui/links/links-display-provider";
@@ -19,7 +20,6 @@ import {
Popover,
Tooltip,
TooltipContent,
- useMediaQuery,
} from "@dub/ui";
import { Download, TableIcon, Tag } from "@dub/ui/src/icons";
import { useSession } from "next-auth/react";
@@ -72,9 +72,7 @@ function WorkspaceLinks() {
<div className="mt-10 flex w-full items-center pt-3">
<MaxWidthWrapper className="flex flex-col gap-y-3">
<div className="flex flex-wrap items-center justify-between gap-2 md:flex-nowrap">
- <h1 className="order-1 text-2xl font-semibold tracking-tight text-black">
- Links
- </h1>
+ <FolderSwitcher />
<div className="order-4 flex w-full grow flex-wrap justify-end gap-2 md:order-2 md:w-auto">
<div className="w-full md:w-56 lg:w-64">
<SearchBoxPersisted
@@ -164,7 +162,6 @@ function WorkspaceLinks() {
const MoreLinkOptions = () => {
const router = useRouter();
const { slug } = useWorkspace();
- const { isMobile } = useMediaQuery();
const [openPopover, setOpenPopover] = useState(false);
const [state, setState] = useState<"default" | "import">("default");
const { ExportLinksModal, setShowExportLinksModal } = useExportLinksModal();
diff --git a/apps/web/ui/folders/folder-switcher.tsx b/apps/web/ui/folders/folder-switcher.tsx
new file mode 100644
index 0000000000..085855d928
--- /dev/null
+++ b/apps/web/ui/folders/folder-switcher.tsx
@@ -0,0 +1,137 @@
+import useFolders from "@/lib/swr/use-folders";
+import { FolderProps } from "@/lib/types";
+import { Popover, Tick } 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">;
+
+export const FolderSwitcher = () => {
+ const [openPopover, setOpenPopover] = useState(true);
+ const { folders, isLoading, isValidating } = useFolders();
+ const [selectedFolder, setSelectedFolder] = useState<Folder | null>(null);
+
+ const handleFolderSelect = useCallback((folder: Folder) => {
+ setSelectedFolder(folder);
+ }, []);
+
+ if (isLoading || !folders) {
+ return <FolderSwitcherPlaceholder />;
+ }
+
+ const folderList = [
+ {
+ id: "all-links",
+ name: "All links",
+ },
+ ...(folders || []),
+ ];
+
+ return (
+ <Popover
+ content={
+ <FolderList
+ folders={folderList}
+ setOpenPopover={setOpenPopover}
+ onFolderSelect={handleFolderSelect}
+ selectedFolder={selectedFolder}
+ />
+ }
+ openPopover={openPopover}
+ setOpenPopover={setOpenPopover}
+ align="start"
+ >
+ <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"}
+ </h1>
+ <ChevronsUpDown className="h-5 w-5 text-gray-400" aria-hidden="true" />
+ </button>
+ </Popover>
+ );
+};
+
+const FolderList = ({
+ folders,
+ setOpenPopover,
+ onFolderSelect,
+ selectedFolder,
+}: {
+ folders: Folder[];
+ setOpenPopover: (open: boolean) => void;
+ onFolderSelect: (folder: Folder) => void;
+ selectedFolder: Folder | null;
+}) => {
+ return (
+ <div className="relative mt-1 max-h-72 w-full space-y-0.5 overflow-auto rounded-md bg-white p-2 text-base sm:w-60 sm:text-sm sm:shadow-lg">
+ <div className="flex items-center justify-between px-2 pb-1">
+ <p className="text-xs text-gray-500">Folders</p>
+ {folders.length > 0 && (
+ <Link
+ href="/settings/folders"
+ onClick={() => setOpenPopover(false)}
+ className="rounded-md border border-gray-200 px-2 py-1 text-xs transition-colors hover:bg-gray-100"
+ >
+ View All
+ </Link>
+ )}
+ </div>
+
+ {folders.map(({ id, name }) => {
+ return (
+ <button
+ key={id}
+ className={`relative flex w-full items-center gap-x-2 rounded-md px-2 py-1.5 hover:bg-gray-100 active:bg-gray-200 ${
+ selectedFolder?.id === id ? "font-medium" : ""
+ } transition-all duration-75`}
+ onClick={() => {
+ setOpenPopover(false);
+ onFolderSelect({ id, name });
+ }}
+ >
+ <div className="flex size-7 items-center justify-center rounded-full border border-gray-200 bg-gradient-to-t from-gray-100 group-hover:bg-white">
+ <FolderCheck className="size-3" aria-hidden="true" />
+ </div>
+
+ <span
+ className={`block truncate text-sm sm:max-w-[140px] ${
+ selectedFolder?.id === id ? "font-medium" : "font-normal"
+ }`}
+ >
+ {name}
+ </span>
+
+ {selectedFolder?.id === id && (
+ <span className="absolute inset-y-0 right-0 flex items-center pr-3 text-black">
+ <Tick className="size-5" aria-hidden="true" />
+ </span>
+ )}
+ </button>
+ );
+ })}
+
+ <button
+ key="add-folder"
+ onClick={() => {
+ setOpenPopover(false);
+ }}
+ className="relative flex w-full items-center gap-x-2 rounded-md px-2 py-1.5 transition-all duration-75 hover:bg-gray-100 active:bg-gray-200"
+ >
+ <div className="flex size-7 items-center justify-center rounded-full border border-gray-200 bg-gradient-to-t from-gray-100 group-hover:bg-white">
+ <FolderPlusIcon className="size-4 text-gray-700" />
+ </div>
+ <span className="block truncate">Create new folder</span>
+ </button>
+ </div>
+ );
+};
+
+const FolderSwitcherPlaceholder = () => {
+ return (
+ <div className="flex animate-pulse items-center space-x-1.5 rounded-lg px-1.5 py-2 sm:w-60">
+ <div className="hidden h-8 w-28 animate-pulse rounded-md bg-gray-200 sm:block sm:w-40" />
+ <ChevronsUpDown className="h-5 w-5 text-gray-400" aria-hidden="true" />
+ </div>
+ );
+};
diff --git a/apps/web/ui/folders/icons/all-folders.tsx b/apps/web/ui/folders/icons/all-folders.tsx
new file mode 100644
index 0000000000..29d1cad044
--- /dev/null
+++ b/apps/web/ui/folders/icons/all-folders.tsx
@@ -0,0 +1,42 @@
+import { SVGProps } from "react";
+
+export function AllFolders(props: SVGProps<SVGSVGElement>) {
+ return (
+ <svg
+ width="16"
+ height="16"
+ viewBox="0 0 16 16"
+ fill="none"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <g clip-path="url(#clip0_298_25371)">
+ <path
+ d="M2 7.77767V4.22211C2 3.23989 2.79556 2.44434 3.77778 2.44434H5.512C6.05156 2.44434 6.56089 2.68878 6.89867 3.10922L7.43467 3.77767H12.2222C13.2044 3.77767 14 4.57322 14 5.55545V7.33322"
+ stroke="#166534"
+ stroke-width="1.5"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ />
+ <path
+ d="M13.9369 7.33333C13.7387 6.568 13.0498 6 12.2222 6H3.77778C2.79556 6 2 6.79644 2 7.77778V11.7778C2 12.7591 2.79556 13.5556 3.77778 13.5556H9.11111"
+ stroke="#166534"
+ stroke-width="1.5"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ />
+ <path
+ d="M15.3335 15.3334L13.3335 13.3334L11.3335 15.3334V10.4446C11.3335 9.95389 11.7317 9.55566 12.2224 9.55566H14.4446C14.9353 9.55566 15.3335 9.95389 15.3335 10.4446V15.3334Z"
+ stroke="#166534"
+ stroke-width="1.5"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ />
+ </g>
+ <defs>
+ <clipPath id="clip0_298_25371">
+ <rect width="16" height="16" fill="white" />
+ </clipPath>
+ </defs>
+ </svg>
+ );
+}