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 archived links count

Tim Wilsonc404a2d244b8
diff --git a/apps/web/ui/links/links-container.tsx b/apps/web/ui/links/links-container.tsx
index 3818c11ec8..284d57ec09 100644
--- a/apps/web/ui/links/links-container.tsx
+++ b/apps/web/ui/links/links-container.tsx
@@ -3,7 +3,15 @@
import useLinks from "@/lib/swr/use-links";
import useLinksCount from "@/lib/swr/use-links-count";
import { LinkWithTagsProps, UserProps } from "@/lib/types";
-import { CardList, MaxWidthWrapper, useRouterStuff } from "@dub/ui";
+import {
+ Button,
+ CardList,
+ MaxWidthWrapper,
+ Tooltip,
+ useMediaQuery,
+ useRouterStuff,
+} from "@dub/ui";
+import { BoxArchive } from "@dub/ui/src/icons";
import { useSearchParams } from "next/navigation";
import { Dispatch, SetStateAction, createContext, useState } from "react";
import { LinkCard } from "./link-card";
@@ -27,6 +35,8 @@ export default function LinksContainer({
}) {
const { links, isValidating } = useLinks();
const { data: count } = useLinksCount();
+ const { data: totalCount } = useLinksCount({ showArchived: true });
+ const archivedCount = totalCount - count;
return (
<MaxWidthWrapper className="grid gap-y-2">
@@ -34,6 +44,7 @@ export default function LinksContainer({
AddEditLinkButton={AddEditLinkButton}
links={links}
count={count}
+ archivedCount={archivedCount}
loading={isValidating}
compact={viewMode === "rows"}
/>
@@ -53,15 +64,19 @@ function LinksList({
AddEditLinkButton,
links,
count,
+ archivedCount,
loading,
compact,
}: {
AddEditLinkButton: () => JSX.Element;
links?: ResponseLink[];
count?: number;
+ archivedCount: number;
loading?: boolean;
compact: boolean;
}) {
+ const { isMobile } = useMediaQuery();
+
const { queryParams } = useRouterStuff();
const searchParams = useSearchParams();
const page = (parseInt(searchParams?.get("page") || "1") || 1) - 1;
@@ -110,7 +125,43 @@ function LinksList({
totalCount={count ?? links.length}
resourceName={(plural) => `${plural ? "links" : "link"}`}
>
- {!!archivedCount && `${archivedCount} archived`}
+ {!!archivedCount && !isMobile && (
+ <Tooltip
+ side="top"
+ content={
+ <div className="px-3 py-2 text-sm text-gray-500">
+ <div className="flex items-center gap-4">
+ <span>
+ <span className="font-medium text-gray-950">
+ {archivedCount}
+ </span>{" "}
+ archived link{archivedCount !== 1 && "s"} that match
+ {archivedCount === 1 && "es"} the applied filters
+ </span>
+ <div>
+ <Button
+ className="h-6 px-2"
+ variant="secondary"
+ text="Show archived links"
+ onClick={() =>
+ queryParams({
+ set: {
+ showArchived: "true",
+ },
+ })
+ }
+ />
+ </div>
+ </div>
+ </div>
+ }
+ >
+ <div className="flex cursor-default items-center gap-1.5 rounded-md bg-gray-100 px-2 py-0.5 text-sm font-medium text-gray-950 hover:bg-gray-200">
+ <BoxArchive className="h-3 w-3" />
+ {archivedCount}
+ </div>
+ </Tooltip>
+ )}
</CardList.Pagination>
)}
</LinksListContext.Provider>
diff --git a/packages/ui/src/card-list/card-list-pagination.tsx b/packages/ui/src/card-list/card-list-pagination.tsx
index dc240dede6..83253fcda6 100644
--- a/packages/ui/src/card-list/card-list-pagination.tsx
+++ b/packages/ui/src/card-list/card-list-pagination.tsx
@@ -1,4 +1,5 @@
import { PAGINATION_LIMIT } from "@dub/utils";
+import { PropsWithChildren } from "react";
import { Button } from "../button";
export function CardListPagination({
@@ -7,44 +8,51 @@ export function CardListPagination({
pageSize = PAGINATION_LIMIT,
totalCount,
resourceName = (plural) => `item${plural ? "s" : ""}`,
-}: {
+ children,
+}: PropsWithChildren<{
page: number;
onPageChange: (fn: (prev: number) => number) => void;
pageSize?: number;
totalCount: number;
resourceName?: (plural: boolean) => string;
-}) {
+}>) {
return (
<>
{/* Placeholder to make room for the floating pagination at the bottom of the list */}
<div className="h-[90px]" />
- <nav className="fixed bottom-4 left-1/2 flex w-full max-w-[768px] -translate-x-1/2 items-center justify-between rounded-xl border border-gray-200 bg-white px-4 py-3.5 text-sm leading-6 text-gray-600 [filter:drop-shadow(0_5px_8px_#222A351d)]">
- <div>
- <span className="hidden sm:inline-block">Viewing</span>{" "}
- <span className="font-medium">
- {page * pageSize + 1}-
- {Math.min(page * pageSize + pageSize, totalCount)}
- </span>{" "}
- of <span className="font-medium">{totalCount.toLocaleString()}</span>{" "}
- {resourceName?.(totalCount !== 1) || "items"}
- </div>
- <div className="flex items-center gap-2">
- <Button
- variant="secondary"
- text="Previous"
- className="h-7 px-2"
- onClick={() => onPageChange((prev) => prev - 1)}
- disabled={page < 1}
- />
- <Button
- variant="secondary"
- text="Next"
- className="h-7 px-2"
- onClick={() => onPageChange((prev) => prev + 1)}
- disabled={(page + 1) * pageSize >= totalCount}
- />
- </div>
- </nav>
+ <div className="fixed bottom-4 left-1/2 w-full max-w-[768px] -translate-x-1/2 px-2.5">
+ <nav className="flex w-full items-center justify-between rounded-xl border border-gray-200 bg-white px-4 py-3.5 text-sm leading-6 text-gray-600 [filter:drop-shadow(0_5px_8px_#222A351d)]">
+ <div className="flex items-center gap-4">
+ <div>
+ <span className="hidden sm:inline-block">Viewing</span>{" "}
+ <span className="font-medium">
+ {page * pageSize + 1}-
+ {Math.min(page * pageSize + pageSize, totalCount)}
+ </span>{" "}
+ of{" "}
+ <span className="font-medium">{totalCount.toLocaleString()}</span>{" "}
+ {resourceName?.(totalCount !== 1) || "items"}
+ </div>
+ {children && <div>{children}</div>}
+ </div>
+ <div className="flex items-center gap-2">
+ <Button
+ variant="secondary"
+ text="Previous"
+ className="h-7 px-2"
+ onClick={() => onPageChange((prev) => prev - 1)}
+ disabled={page < 1}
+ />
+ <Button
+ variant="secondary"
+ text="Next"
+ className="h-7 px-2"
+ onClick={() => onPageChange((prev) => prev + 1)}
+ disabled={(page + 1) * pageSize >= totalCount}
+ />
+ </div>
+ </nav>
+ </div>
</>
);
}