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.

Merge fixes

Tim Wilsond86755319a9c
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 c02325ed3e..b257c978fa 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
@@ -1,7 +1,7 @@
"use client";
import useWorkspace from "@/lib/swr/use-workspace";
-import { SearchBox } from "@/ui/links/link-filters";
+import { InputSearchBox } from "@/ui/links/link-filters";
import LinkSort from "@/ui/links/link-sort";
import LinksContainer from "@/ui/links/links-container";
import { useLinkFilters } from "@/ui/links/use-link-filters";
@@ -48,7 +48,7 @@ export default function WorkspaceLinksClient() {
</h1>
<div className="flex space-x-2">
<div className="w-72 max-w-full">
- <SearchBox />
+ <InputSearchBox />
</div>
<Filter.Select
filters={filters}
diff --git a/apps/web/ui/analytics/events/use-pagination.ts b/apps/web/ui/analytics/events/use-pagination.ts
index 6092fd53d8..f47540d914 100644
--- a/apps/web/ui/analytics/events/use-pagination.ts
+++ b/apps/web/ui/analytics/events/use-pagination.ts
@@ -1,7 +1,8 @@
import { useRouterStuff, useTablePagination } from "@dub/ui";
+import { PAGINATION_LIMIT } from "@dub/utils";
import { useEffect, useMemo } from "react";
-export default function usePagination(pageSize: number) {
+export default function usePagination(pageSize = PAGINATION_LIMIT) {
const { searchParams, queryParams } = useRouterStuff();
const page = useMemo(
diff --git a/apps/web/ui/links/link-sort.tsx b/apps/web/ui/links/link-sort.tsx
index 6e1adae7bb..b55a4ee284 100644
--- a/apps/web/ui/links/link-sort.tsx
+++ b/apps/web/ui/links/link-sort.tsx
@@ -1,9 +1,9 @@
-import { Button, IconMenu, Popover, Tick, useRouterStuff } from "@dub/ui";
+import { Sort } from "@/ui/shared/icons";
+import { IconMenu, Popover, Tick, useRouterStuff } from "@dub/ui";
import { cn } from "@dub/utils";
import { ChevronDown, SortDesc } from "lucide-react";
import { useSearchParams } from "next/navigation";
import { useMemo, useState } from "react";
-import { Sort } from "../shared/icons";
const sortOptions = [
{
@@ -61,8 +61,7 @@ export default function LinkSort() {
openPopover={openPopover}
setOpenPopover={setOpenPopover}
>
- <Button
- variant="secondary"
+ <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",
@@ -79,7 +78,7 @@ export default function LinkSort() {
{sort ? selectedSort.display : "Sort by"}
</span>
<ChevronDown className="h-4 w-4 flex-shrink-0 text-gray-400 transition-transform duration-75 group-data-[state=open]:rotate-180" />
- </Button>
+ </button>
</Popover>
);
}
diff --git a/apps/web/ui/links/links-container.tsx b/apps/web/ui/links/links-container.tsx
index 093d337163..a584e15b42 100644
--- a/apps/web/ui/links/links-container.tsx
+++ b/apps/web/ui/links/links-container.tsx
@@ -2,17 +2,40 @@
import useLinks from "@/lib/swr/use-links";
import useLinksCount from "@/lib/swr/use-links-count";
-import { MaxWidthWrapper } from "@dub/ui";
-import { Suspense } from "react";
-import { useLinkFiltersModal } from "../modals/link-filters-modal";
-import ArchivedLinksHint from "./archived-links-hint";
+import { LinkWithTagsProps, UserProps } from "@/lib/types";
+import {
+ Avatar,
+ LinkLogo,
+ MaxWidthWrapper,
+ Table,
+ useRouterStuff,
+ useTable,
+} from "@dub/ui";
+import {
+ PAGINATION_LIMIT,
+ formatDate,
+ formatDateTime,
+ getApexDomain,
+} from "@dub/utils";
+import { ColumnDef } from "@tanstack/react-table";
+import { useSearchParams } from "next/navigation";
+import { Suspense, useEffect, useMemo, useState } from "react";
import LinkCard from "./link-card";
import LinkCardPlaceholder from "./link-card-placeholder";
-import LinkFilters, { InputSearchBox } from "./link-filters";
import LinkPagination from "./link-pagination";
-import LinkSort from "./link-sort";
import NoLinksPlaceholder from "./no-links-placeholder";
+type ResponseLink = LinkWithTagsProps & {
+ user: UserProps;
+};
+
+type ListProps = {
+ AddEditLinkButton: () => JSX.Element;
+ links?: ResponseLink[];
+ count?: number;
+ loading?: boolean;
+};
+
export default function LinksContainer({
AddEditLinkButton,
}: {
@@ -20,56 +43,167 @@ export default function LinksContainer({
}) {
const { links, isValidating } = useLinks();
const { data: count } = useLinksCount();
- const { LinkFiltersButton, LinkFiltersModal } = useLinkFiltersModal();
+ 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 compact
+ </button>
+ {compact ? (
+ <CompactList
+ AddEditLinkButton={AddEditLinkButton}
+ links={links}
+ count={count}
+ loading={isValidating}
+ />
+ ) : (
+ <DefaultList
+ AddEditLinkButton={AddEditLinkButton}
+ links={links}
+ count={count}
+ loading={isValidating}
+ />
+ )}
+ </MaxWidthWrapper>
+ );
+}
+
+function DefaultList({ AddEditLinkButton, links, count, loading }: ListProps) {
return (
<>
- <LinkFiltersModal />
- <MaxWidthWrapper className="flex flex-col space-y-3 py-3">
- <div className="flex h-10 w-full justify-center lg:justify-end">
- <LinkFiltersButton />
- <Suspense>
- <LinkSort />
- </Suspense>
- </div>
- <div className="block lg:hidden">
- <InputSearchBox />
- </div>
- <div className="grid grid-cols-1 gap-5 lg:grid-cols-7">
- <div className="scrollbar-hide sticky top-14 col-span-2 hidden max-h-[calc(100vh-80px)] self-start overflow-auto rounded-lg border border-gray-200 bg-white lg:block">
- <Suspense>
- <LinkFilters />
- </Suspense>
- </div>
- <div className="col-span-1 auto-rows-min grid-cols-1 lg:col-span-5">
- <ul className="grid min-h-[66.5vh] auto-rows-min gap-3">
- {links && !isValidating ? (
- links.length > 0 ? (
- links.map((props) => (
- <Suspense key={props.id} fallback={<LinkCardPlaceholder />}>
- <LinkCard props={props} />
- </Suspense>
- ))
- ) : (
- <NoLinksPlaceholder AddEditLinkButton={AddEditLinkButton} />
- )
- ) : (
- Array.from({ length: 10 }).map((_, i) => (
- <LinkCardPlaceholder key={i} />
- ))
- )}
- <Suspense>
- <ArchivedLinksHint />
+ <ul className="grid min-h-[66.5vh] auto-rows-min gap-3">
+ {links && !loading ? (
+ links.length > 0 ? (
+ links.map((props) => (
+ <Suspense key={props.id} fallback={<LinkCardPlaceholder />}>
+ <LinkCard props={props} />
</Suspense>
- </ul>
- {count && count > 0 ? (
- <Suspense>
- <LinkPagination />
- </Suspense>
- ) : null}
- </div>
- </div>
- </MaxWidthWrapper>
+ ))
+ ) : (
+ <NoLinksPlaceholder AddEditLinkButton={AddEditLinkButton} />
+ )
+ ) : (
+ Array.from({ length: 10 }).map((_, i) => (
+ <LinkCardPlaceholder key={i} />
+ ))
+ )}
+ </ul>
+ {count && count > 0 ? (
+ <Suspense>
+ <LinkPagination />
+ </Suspense>
+ ) : null}
</>
);
}
+
+function CompactList({ AddEditLinkButton, links, count, loading }: ListProps) {
+ const { queryParams } = useRouterStuff();
+ const searchParams = useSearchParams();
+ const currentPage = parseInt(searchParams?.get("page") || "1") || 1;
+
+ const columns: ColumnDef<ResponseLink, any>[] = useMemo(
+ () => [
+ {
+ id: "link",
+ header: "Link",
+ accessorFn: (d) => d,
+ cell: ({ getValue }) => {
+ const path = getValue().key === "_root" ? "" : `/${getValue().key}`;
+
+ return (
+ <div className="flex items-center gap-3">
+ <LinkLogo
+ apexDomain={getApexDomain(getValue().url)}
+ className="h-4 w-4 sm:h-4 sm:w-4"
+ />
+ <span className="truncate" title={`${getValue().domain}${path}`}>
+ <span className="font-medium text-gray-950">
+ {getValue().domain}
+ </span>
+ {path}
+ </span>
+ </div>
+ );
+ },
+ enableHiding: false,
+ size: 130,
+ },
+ {
+ id: "url",
+ header: "URL",
+ accessorKey: "url",
+ size: 130,
+ },
+ {
+ id: "creator",
+ header: "Creator",
+ accessorFn: (d) => d.user,
+ cell: ({ getValue }) => {
+ const user = getValue() as ResponseLink["user"];
+ return (
+ <div className="flex items-center gap-3">
+ <Avatar user={user} className="h-4 w-4" />
+ <span className="truncate" title={user.name}>
+ {user.name}
+ </span>
+ </div>
+ );
+ },
+ size: 50,
+ },
+ {
+ id: "created",
+ header: "Created",
+ accessorKey: "createdAt",
+ cell: ({ getValue }) => {
+ const createdAt = getValue() as Date;
+
+ return (
+ <span title={formatDateTime(createdAt)}>
+ {formatDate(createdAt)}
+ </span>
+ );
+ },
+ size: 50,
+ },
+ {
+ id: "clicks",
+ header: "Clicks",
+ accessorKey: "clicks",
+ size: 50,
+ },
+ ],
+ [],
+ );
+
+ const [pagination, setPagination] = useState({
+ pageIndex: currentPage - 1,
+ pageSize: PAGINATION_LIMIT,
+ });
+
+ useEffect(() => {
+ queryParams({
+ set: {
+ page: (pagination.pageIndex + 1).toString(),
+ },
+ });
+ }, [pagination]);
+
+ const { table, ...tableProps } = useTable({
+ data: links ?? [],
+ loading,
+ columns,
+ pagination: pagination,
+ rowCount: count ?? 0,
+ onPaginationChange: setPagination,
+ resourceName: (plural) => `link${plural ? "s" : ""}`,
+ });
+
+ return <Table table={table} {...tableProps} />;
+}
diff --git a/packages/ui/src/table/use-table-pagination.tsx b/packages/ui/src/table/use-table-pagination.tsx
index f7dde5b07f..e7a3402891 100644
--- a/packages/ui/src/table/use-table-pagination.tsx
+++ b/packages/ui/src/table/use-table-pagination.tsx
@@ -3,27 +3,27 @@ import { useEffect, useState } from "react";
export function useTablePagination({
pageSize,
- offset,
- onOffsetChange,
+ page,
+ onPageChange,
}: {
pageSize: number;
- offset: number;
- onOffsetChange?: (offset: number) => void;
+ page: number;
+ onPageChange?: (page: number) => void;
}) {
const [pagination, setPagination] = useState<PaginationState>({
- pageIndex: 0,
+ pageIndex: page,
pageSize,
});
useEffect(() => {
setPagination((p) => ({
...p,
- pageIndex: Math.floor(offset / p.pageSize),
+ pageIndex: page,
}));
- }, [offset]);
+ }, [page]);
useEffect(() => {
- onOffsetChange?.(pagination.pageIndex * pagination.pageSize);
+ onPageChange?.(pagination.pageIndex);
}, [pagination]);
return { pagination, setPagination };