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 display options

Tim Wilsonbb8b08590420
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 664860106e..371763110e 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
@@ -3,7 +3,7 @@
import useWorkspace from "@/lib/swr/use-workspace";
import LinkDisplay from "@/ui/links/link-display";
import { InputSearchBox } from "@/ui/links/link-filters";
-import LinksContainer from "@/ui/links/links-container";
+import LinksContainer, { linkViewModes } from "@/ui/links/links-container";
import { useLinkFilters } from "@/ui/links/use-link-filters";
import { useAddEditLinkModal } from "@/ui/modals/add-edit-link-modal";
import { useExportLinksModal } from "@/ui/modals/export-links-modal";
@@ -17,6 +17,7 @@ import {
Popover,
Tooltip,
TooltipContent,
+ useLocalStorage,
useRouterStuff,
} from "@dub/ui";
import { CloudUpload, Download } from "@dub/ui/src/icons";
@@ -33,6 +34,15 @@ import {
export default function WorkspaceLinksClient() {
const { AddEditLinkModal, AddEditLinkButton } = useAddEditLinkModal();
+ const [viewMode, setViewMode] = useLocalStorage(
+ "links-view-mode",
+ linkViewModes[0],
+ );
+
+ useEffect(() => {
+ if (!linkViewModes.includes(viewMode)) setViewMode("cards");
+ }, [viewMode]);
+
const { filters, activeFilters, onSelect, onRemove, onRemoveAll } =
useLinkFilters();
@@ -58,7 +68,10 @@ export default function WorkspaceLinksClient() {
/>
</div>
<div className="grow basis-0 md:grow-0">
- <LinkDisplay />
+ <LinkDisplay
+ viewMode={viewMode}
+ onViewModeChange={setViewMode}
+ />
</div>
</div>
<div className="order-3 flex gap-x-2">
@@ -77,7 +90,10 @@ export default function WorkspaceLinksClient() {
</MaxWidthWrapper>
</div>
<div className="mt-3">
- <LinksContainer AddEditLinkButton={AddEditLinkButton} />
+ <LinksContainer
+ AddEditLinkButton={AddEditLinkButton}
+ viewMode={viewMode}
+ />
</div>
</>
);
diff --git a/apps/web/ui/links/link-controls.tsx b/apps/web/ui/links/link-controls.tsx
index 8131985078..e0885fd701 100644
--- a/apps/web/ui/links/link-controls.tsx
+++ b/apps/web/ui/links/link-controls.tsx
@@ -9,9 +9,9 @@ import {
Popover,
SimpleTooltipContent,
} from "@dub/ui";
-import { CircleCheck, Copy, QRCode } from "@dub/ui/src/icons";
+import { BoxArchive, CircleCheck, Copy, QRCode } from "@dub/ui/src/icons";
import { cn, isDubDomain, nanoid, punycode } from "@dub/utils";
-import { Archive, CopyPlus, Delete, FolderInput } from "lucide-react";
+import { CopyPlus, Delete, FolderInput } from "lucide-react";
import { useParams } from "next/navigation";
import { useState } from "react";
import { toast } from "sonner";
@@ -157,7 +157,7 @@ export function LinkControls({ link }: { link: ResponseLink }) {
setOpenPopover(false);
setShowArchiveLinkModal(true);
}}
- icon={<Archive className="h-4 w-4" />}
+ icon={<BoxArchive className="h-4 w-4" />}
shortcut="A"
className="h-9 px-2 font-medium"
/>
diff --git a/apps/web/ui/links/link-display.tsx b/apps/web/ui/links/link-display.tsx
index af33fc0d08..553b9e670f 100644
--- a/apps/web/ui/links/link-display.tsx
+++ b/apps/web/ui/links/link-display.tsx
@@ -1,11 +1,25 @@
-import { Button, Popover, useRouterStuff } from "@dub/ui";
-import { Sliders } from "@dub/ui/src/icons";
+import { Button, Popover, Switch, useRouterStuff } from "@dub/ui";
+import {
+ ArrowsOppositeDirectionY,
+ BoxArchive,
+ GridLayoutRows,
+ Sliders,
+ TableRows2,
+} from "@dub/ui/src/icons";
import { cn } from "@dub/utils";
import { ChevronDown } from "lucide-react";
import { useSearchParams } from "next/navigation";
import { useState } from "react";
+import LinkSort from "./link-sort";
+import { LinksViewMode } from "./links-container";
-export default function LinkDisplay() {
+export default function LinkDisplay({
+ viewMode,
+ onViewModeChange,
+}: {
+ viewMode: LinksViewMode;
+ onViewModeChange: (viewMode: LinksViewMode) => void;
+}) {
const [openPopover, setOpenPopover] = useState(false);
const searchParams = useSearchParams();
const sort = searchParams?.get("sort");
@@ -13,7 +27,69 @@ export default function LinkDisplay() {
return (
<Popover
- content={<div className="w-full p-2 md:w-48">options</div>}
+ content={
+ <div className="w-full divide-y divide-gray-200 text-sm md:w-80">
+ <div className="grid grid-cols-2 gap-2 p-3">
+ {[
+ { id: "cards", label: "Cards", icon: GridLayoutRows },
+ { id: "rows", label: "Rows", icon: TableRows2 },
+ ].map(({ id, label, icon: Icon }) => {
+ const selected = viewMode === id;
+ return (
+ <button
+ key={id}
+ className={cn(
+ "flex h-20 flex-col items-center justify-center gap-2 rounded-md transition-colors",
+ selected
+ ? "bg-gray-200 text-gray-950"
+ : "text-gray-800 hover:bg-gray-100 hover:text-gray-950",
+ )}
+ onClick={() => onViewModeChange(id as LinksViewMode)}
+ >
+ <Icon
+ className={cn(
+ "h-5 w-5 text-gray-600",
+ selected && "text-gray-800",
+ )}
+ />
+ {label}
+ </button>
+ );
+ })}
+ </div>
+ <div className="flex h-20 items-center justify-between gap-2 px-4">
+ <span className="flex items-center gap-2">
+ <ArrowsOppositeDirectionY className="h-4 w-4 text-gray-800" />
+ Ordering
+ </span>
+ <div>
+ <LinkSort />
+ </div>
+ </div>
+ <div className="flex h-20 items-center justify-between gap-2 px-4">
+ <span className="flex items-center gap-2">
+ <BoxArchive className="h-4 w-4 text-gray-800" />
+ Show archived links
+ </span>
+ <div>
+ <Switch
+ checked={searchParams.get("showArchived") === "true"}
+ fn={(checked) =>
+ queryParams(
+ checked
+ ? {
+ set: {
+ showArchived: "true",
+ },
+ }
+ : { del: "showArchived" },
+ )
+ }
+ />
+ </div>
+ </div>
+ </div>
+ }
openPopover={openPopover}
setOpenPopover={setOpenPopover}
>
diff --git a/apps/web/ui/links/link-sort.tsx b/apps/web/ui/links/link-sort.tsx
index b55a4ee284..ea6995e17c 100644
--- a/apps/web/ui/links/link-sort.tsx
+++ b/apps/web/ui/links/link-sort.tsx
@@ -64,7 +64,7 @@ export default function LinkSort() {
<button
onClick={() => setOpenPopover(!openPopover)}
className={cn(
- "group flex h-10 w-full cursor-pointer appearance-none items-center gap-x-2 truncate rounded-md border px-3 text-sm outline-none transition-all lg:w-48",
+ "group flex h-10 cursor-pointer appearance-none items-center gap-x-2 truncate rounded-md border px-3 text-sm outline-none transition-all",
"border-gray-200 bg-white text-gray-900 placeholder-gray-400",
"focus-visible:border-gray-500 data-[state=open]:border-gray-500 data-[state=open]:ring-4 data-[state=open]:ring-gray-200",
)}
diff --git a/apps/web/ui/links/links-container.tsx b/apps/web/ui/links/links-container.tsx
index 1955ef0969..a9d9ac4892 100644
--- a/apps/web/ui/links/links-container.tsx
+++ b/apps/web/ui/links/links-container.tsx
@@ -17,34 +17,31 @@ import { useEffect, useMemo, useState } from "react";
import { LinkDetailsColumn } from "./link-details-column";
import { LinkTitleColumn } from "./link-title-column";
+export const linkViewModes = ["cards", "rows"] as const;
+export type LinksViewMode = (typeof linkViewModes)[number];
+
export type ResponseLink = LinkWithTagsProps & {
user: UserProps;
};
export default function LinksContainer({
AddEditLinkButton,
+ viewMode,
}: {
AddEditLinkButton: () => JSX.Element;
+ viewMode: LinksViewMode;
}) {
const { links, isValidating } = useLinks();
const { data: count } = useLinksCount();
- const [compact, setCompact] = useState(false);
-
return (
<MaxWidthWrapper className="grid gap-y-2">
- <button
- className="w-24 border border-gray-200 text-xs"
- onClick={() => setCompact((c) => !c)}
- >
- toggle view
- </button>
<LinksList
AddEditLinkButton={AddEditLinkButton}
links={links}
count={count}
loading={isValidating}
- compact={compact}
+ compact={viewMode === "rows"}
/>
</MaxWidthWrapper>
);
diff --git a/apps/web/ui/links/use-link-filters.tsx b/apps/web/ui/links/use-link-filters.tsx
index 68ab7a3547..5d7b39ddb3 100644
--- a/apps/web/ui/links/use-link-filters.tsx
+++ b/apps/web/ui/links/use-link-filters.tsx
@@ -3,7 +3,7 @@ import useLinksCount from "@/lib/swr/use-links-count";
import useTags from "@/lib/swr/use-tags";
import useUser from "@/lib/swr/use-user";
import useWorkspace from "@/lib/swr/use-workspace";
-import { BlurImage, Globe, Tag, Trash, User, useRouterStuff } from "@dub/ui";
+import { BlurImage, Globe, Tag, User, useRouterStuff } from "@dub/ui";
import { DUB_WORKSPACE_ID, GOOGLE_FAVICON_URL, cn } from "@dub/utils";
import { useMemo } from "react";
import { COLORS_LIST } from "./tag-badge";
@@ -88,29 +88,15 @@ export function useLinkFilters() {
},
]
: []),
- {
- key: "showArchived",
- icon: Trash,
- label: "Archived",
- options: [
- {
- value: true,
- label: "Include archived links",
- },
- ],
- },
];
}, [domains, tags]);
const activeFilters = useMemo(() => {
- const { domain, tagId, userId, showArchived } = searchParamsObj;
+ const { domain, tagId, userId } = searchParamsObj;
return [
...(domain ? [{ key: "domain", value: domain }] : []),
...(tagId ? [{ key: "tagId", value: tagId }] : []),
...(userId ? [{ key: "userId", value: userId }] : []),
- ...(showArchived
- ? [{ key: "showArchived", value: showArchived === "true" }]
- : []),
];
}, [searchParamsObj]);
@@ -130,7 +116,7 @@ export function useLinkFilters() {
const onRemoveAll = () => {
queryParams({
- del: ["domain", "tagId", "userId", "showArchived", "search"],
+ del: ["domain", "tagId", "userId", "search"],
});
};
diff --git a/packages/ui/src/hooks/use-local-storage.ts b/packages/ui/src/hooks/use-local-storage.ts
index e794abd1b9..6fa774a7e0 100644
--- a/packages/ui/src/hooks/use-local-storage.ts
+++ b/packages/ui/src/hooks/use-local-storage.ts
@@ -1,17 +1,26 @@
import { useEffect, useState } from "react";
+function getItemFromLocalStorage(key: string) {
+ if (typeof window === "undefined") return null;
+
+ const item = window.localStorage.getItem(key);
+ if (item) return JSON.parse(item);
+
+ return null;
+}
+
export function useLocalStorage<T>(
key: string,
initialValue: T,
): [T, (value: T) => void] {
- const [storedValue, setStoredValue] = useState(initialValue);
+ const [storedValue, setStoredValue] = useState(
+ getItemFromLocalStorage(key) ?? initialValue,
+ );
useEffect(() => {
// Retrieve from localStorage
- const item = window.localStorage.getItem(key);
- if (item) {
- setStoredValue(JSON.parse(item));
- }
+ const item = getItemFromLocalStorage(key);
+ if (item) setStoredValue(item);
}, [key]);
const setValue = (value: T) => {
@@ -20,5 +29,6 @@ export function useLocalStorage<T>(
// Save to localStorage
window.localStorage.setItem(key, JSON.stringify(value));
};
+
return [storedValue, setValue];
}
diff --git a/packages/ui/src/icons/nucleo/arrows-opposite-direction-y.tsx b/packages/ui/src/icons/nucleo/arrows-opposite-direction-y.tsx
new file mode 100644
index 0000000000..10ae5e1d66
--- /dev/null
+++ b/packages/ui/src/icons/nucleo/arrows-opposite-direction-y.tsx
@@ -0,0 +1,54 @@
+import { SVGProps } from "react";
+
+export function ArrowsOppositeDirectionY(props: SVGProps<SVGSVGElement>) {
+ return (
+ <svg
+ height="18"
+ width="18"
+ viewBox="0 0 18 18"
+ xmlns="http://www.w3.org/2000/svg"
+ {...props}
+ >
+ <g fill="currentColor">
+ <polyline
+ fill="none"
+ points="8.5 12.5 11.75 15.75 15 12.5"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ <polyline
+ fill="none"
+ points="3 5.5 6.25 2.25 9.5 5.5"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ <line
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="11.75"
+ x2="11.75"
+ y1="15.75"
+ y2="7.75"
+ />
+ <line
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="6.25"
+ x2="6.25"
+ y1="2.25"
+ y2="10.25"
+ />
+ </g>
+ </svg>
+ );
+}
diff --git a/packages/ui/src/icons/nucleo/box-archive.tsx b/packages/ui/src/icons/nucleo/box-archive.tsx
new file mode 100644
index 0000000000..3ae60ce168
--- /dev/null
+++ b/packages/ui/src/icons/nucleo/box-archive.tsx
@@ -0,0 +1,48 @@
+import { SVGProps } from "react";
+
+export function BoxArchive(props: SVGProps<SVGSVGElement>) {
+ return (
+ <svg
+ height="18"
+ width="18"
+ viewBox="0 0 18 18"
+ xmlns="http://www.w3.org/2000/svg"
+ {...props}
+ >
+ <g fill="currentColor">
+ <path
+ d="M14.75,6.25v7c0,1.105-.895,2-2,2H5.25c-1.105,0-2-.895-2-2V6.25"
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ <rect
+ height="3.5"
+ width="14.5"
+ fill="none"
+ rx="1"
+ ry="1"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x="1.75"
+ y="2.75"
+ />
+ <line
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="7"
+ x2="11"
+ y1="9.25"
+ y2="9.25"
+ />
+ </g>
+ </svg>
+ );
+}
diff --git a/packages/ui/src/icons/nucleo/grid-layout-rows.tsx b/packages/ui/src/icons/nucleo/grid-layout-rows.tsx
new file mode 100644
index 0000000000..50f3d7c101
--- /dev/null
+++ b/packages/ui/src/icons/nucleo/grid-layout-rows.tsx
@@ -0,0 +1,44 @@
+import { SVGProps } from "react";
+
+export function GridLayoutRows(props: SVGProps<SVGSVGElement>) {
+ return (
+ <svg
+ height="18"
+ width="18"
+ viewBox="0 0 18 18"
+ xmlns="http://www.w3.org/2000/svg"
+ {...props}
+ >
+ <g fill="currentColor">
+ <rect
+ height="4.5"
+ width="12.5"
+ fill="none"
+ rx="1"
+ ry="1"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ transform="translate(18 10) rotate(-180)"
+ x="2.75"
+ y="2.75"
+ />
+ <rect
+ height="4.5"
+ width="12.5"
+ fill="none"
+ rx="1"
+ ry="1"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ transform="translate(18 26) rotate(-180)"
+ x="2.75"
+ y="10.75"
+ />
+ </g>
+ </svg>
+ );
+}
diff --git a/packages/ui/src/icons/nucleo/index.ts b/packages/ui/src/icons/nucleo/index.ts
index 3d0f89d88f..3fee1fc428 100644
--- a/packages/ui/src/icons/nucleo/index.ts
+++ b/packages/ui/src/icons/nucleo/index.ts
@@ -1,7 +1,9 @@
export * from "./arrow-right";
export * from "./arrow-turn-right2";
+export * from "./arrows-opposite-direction-y";
export * from "./blog";
export * from "./book2";
+export * from "./box-archive";
export * from "./bullet-list";
export * from "./chart-line";
export * from "./circle-check";
@@ -24,6 +26,7 @@ export * from "./gear";
export * from "./gear2";
export * from "./globe";
export * from "./globe2";
+export * from "./grid-layout-rows";
export * from "./headset";
export * from "./hexadecagon-star";
export * from "./hyperlink";
@@ -42,6 +45,7 @@ export * from "./refresh2";
export * from "./shield-check";
export * from "./sliders";
export * from "./stars2";
+export * from "./table-rows2";
export * from "./tablet";
export * from "./tag";
export * from "./trash";
diff --git a/packages/ui/src/icons/nucleo/table-rows2.tsx b/packages/ui/src/icons/nucleo/table-rows2.tsx
new file mode 100644
index 0000000000..fde0b39a55
--- /dev/null
+++ b/packages/ui/src/icons/nucleo/table-rows2.tsx
@@ -0,0 +1,51 @@
+import { SVGProps } from "react";
+
+export function TableRows2(props: SVGProps<SVGSVGElement>) {
+ return (
+ <svg
+ height="18"
+ width="18"
+ viewBox="0 0 18 18"
+ xmlns="http://www.w3.org/2000/svg"
+ {...props}
+ >
+ <g fill="currentColor">
+ <line
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="1.75"
+ x2="16.25"
+ y1="6.75"
+ y2="6.75"
+ />
+ <line
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="1.75"
+ x2="16.25"
+ y1="11.25"
+ y2="11.25"
+ />
+ <rect
+ height="12.5"
+ width="14.5"
+ fill="none"
+ rx="2"
+ ry="2"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x="1.75"
+ y="2.75"
+ />
+ </g>
+ </svg>
+ );
+}