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.

Move `LinksToolbar` into separate file

Tim Wilsonfab04418b19a
diff --git a/apps/web/ui/links/links-container.tsx b/apps/web/ui/links/links-container.tsx
index 499508122b..0ccd99f324 100644
--- a/apps/web/ui/links/links-container.tsx
+++ b/apps/web/ui/links/links-container.tsx
@@ -3,14 +3,8 @@
import useLinks from "@/lib/swr/use-links";
import useLinksCount from "@/lib/swr/use-links-count";
import { ExpandedLinkProps, UserProps } from "@/lib/types";
-import {
- CardList,
- MaxWidthWrapper,
- PaginationControls,
- usePagination,
-} from "@dub/ui";
-import { CursorRays, Hyperlink, LoadingSpinner } from "@dub/ui/icons";
-import { cn } from "@dub/utils";
+import { CardList, MaxWidthWrapper } from "@dub/ui";
+import { CursorRays, Hyperlink } from "@dub/ui/icons";
import { useSearchParams } from "next/navigation";
import {
createContext,
@@ -20,15 +14,11 @@ import {
useState,
} from "react";
import { AnimatedEmptyState } from "../shared/animated-empty-state";
-import { X } from "../shared/icons";
-import ArchivedLinksHint from "./archived-links-hint";
import { LinkCard } from "./link-card";
import LinkCardPlaceholder from "./link-card-placeholder";
-import {
- LinkSelectionProvider,
- useLinkSelection,
-} from "./link-selection-provider";
+import { LinkSelectionProvider } from "./link-selection-provider";
import { LinksDisplayContext } from "./links-display-provider";
+import { LinksToolbar } from "./links-toolbar";
export type ResponseLink = ExpandedLinkProps & {
user: UserProps;
@@ -145,7 +135,7 @@ function LinksList({
{/* Pagination */}
{links && (
- <FloatingToolbar
+ <LinksToolbar
loading={!!loading}
linksCount={count ?? links?.length ?? 0}
/>
@@ -153,84 +143,3 @@ function LinksList({
</LinkSelectionProvider>
);
}
-
-const FloatingToolbar = ({
- loading,
- linksCount,
-}: {
- loading: boolean;
- linksCount: number;
-}) => {
- const { selectedLinkIds, setSelectedLinkIds } = useLinkSelection();
- const { pagination, setPagination } = usePagination();
-
- return (
- <>
- {/* Leave room at bottom of list */}
- <div className="h-[90px]" />
-
- <div className="fixed bottom-4 left-0 w-full sm:max-[1330px]:w-[calc(100%-150px)] md:left-[240px] md:w-[calc(100%-240px)] md:max-[1330px]:w-[calc(100%-240px-150px)]">
- <div
- className={cn(
- "relative left-1/2 w-full max-w-[768px] -translate-x-1/2 px-5",
- "max-[1330px]:left-0 max-[1330px]:translate-x-0",
- )}
- >
- <div className="overflow-hidden rounded-xl border border-neutral-200 bg-white [filter:drop-shadow(0_5px_8px_#222A351d)]">
- <div
- className={cn(
- "relative px-4 py-3.5 transition-[opacity,transform] duration-100",
- selectedLinkIds.length > 0 &&
- "absolute inset-0 translate-y-1/2 opacity-0",
- )}
- >
- <PaginationControls
- pagination={pagination}
- setPagination={setPagination}
- totalCount={linksCount}
- unit={(plural) => `${plural ? "links" : "link"}`}
- >
- {loading ? (
- <LoadingSpinner className="size-3.5" />
- ) : (
- <div className="hidden sm:block">
- <ArchivedLinksHint />
- </div>
- )}
- </PaginationControls>
- </div>
-
- <div
- className={cn(
- "relative px-4 py-3.5 transition-[opacity,transform] duration-100",
- !selectedLinkIds.length &&
- "absolute inset-0 translate-y-1/2 opacity-0",
- )}
- >
- <div className="flex items-center justify-between">
- <div className="flex items-center gap-2">
- <button
- type="button"
- onClick={() => setSelectedLinkIds([])}
- className="rounded-md p-1.5 transition-colors duration-75 hover:bg-neutral-50 active:bg-neutral-100"
- >
- <X className="size-4 text-neutral-900" />
- </button>
- <span className="text-sm font-medium text-neutral-600">
- <strong className="font-semibold">
- {selectedLinkIds.length}
- </strong>{" "}
- selected
- </span>
- </div>
-
- {/* Controls */}
- <div className="flex items-center gap-2"></div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </>
- );
-};
diff --git a/apps/web/ui/links/links-toolbar.tsx b/apps/web/ui/links/links-toolbar.tsx
new file mode 100644
index 0000000000..126b961208
--- /dev/null
+++ b/apps/web/ui/links/links-toolbar.tsx
@@ -0,0 +1,86 @@
+import { LoadingSpinner, PaginationControls, usePagination } from "@dub/ui";
+import { cn } from "@dub/utils";
+import { X } from "../shared/icons";
+import ArchivedLinksHint from "./archived-links-hint";
+import { useLinkSelection } from "./link-selection-provider";
+
+export const LinksToolbar = ({
+ loading,
+ linksCount,
+}: {
+ loading: boolean;
+ linksCount: number;
+}) => {
+ const { selectedLinkIds, setSelectedLinkIds } = useLinkSelection();
+ const { pagination, setPagination } = usePagination();
+
+ return (
+ <>
+ {/* Leave room at bottom of list */}
+ <div className="h-[90px]" />
+
+ <div className="fixed bottom-4 left-0 w-full sm:max-[1330px]:w-[calc(100%-150px)] md:left-[240px] md:w-[calc(100%-240px)] md:max-[1330px]:w-[calc(100%-240px-150px)]">
+ <div
+ className={cn(
+ "relative left-1/2 w-full max-w-[768px] -translate-x-1/2 px-5",
+ "max-[1330px]:left-0 max-[1330px]:translate-x-0",
+ )}
+ >
+ <div className="overflow-hidden rounded-xl border border-neutral-200 bg-white [filter:drop-shadow(0_5px_8px_#222A351d)]">
+ <div
+ className={cn(
+ "relative px-4 py-3.5 transition-[opacity,transform] duration-100",
+ selectedLinkIds.length > 0 &&
+ "absolute inset-0 translate-y-1/2 opacity-0",
+ )}
+ >
+ <PaginationControls
+ pagination={pagination}
+ setPagination={setPagination}
+ totalCount={linksCount}
+ unit={(plural) => `${plural ? "links" : "link"}`}
+ >
+ {loading ? (
+ <LoadingSpinner className="size-3.5" />
+ ) : (
+ <div className="hidden sm:block">
+ <ArchivedLinksHint />
+ </div>
+ )}
+ </PaginationControls>
+ </div>
+
+ <div
+ className={cn(
+ "relative px-4 py-3.5 transition-[opacity,transform] duration-100",
+ !selectedLinkIds.length &&
+ "absolute inset-0 translate-y-1/2 opacity-0",
+ )}
+ >
+ <div className="flex items-center justify-between">
+ <div className="flex items-center gap-2">
+ <button
+ type="button"
+ onClick={() => setSelectedLinkIds([])}
+ className="rounded-md p-1.5 transition-colors duration-75 hover:bg-neutral-50 active:bg-neutral-100"
+ >
+ <X className="size-4 text-neutral-900" />
+ </button>
+ <span className="text-sm font-medium text-neutral-600">
+ <strong className="font-semibold">
+ {selectedLinkIds.length}
+ </strong>{" "}
+ selected
+ </span>
+ </div>
+
+ {/* Controls */}
+ <div className="flex items-center gap-2"></div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </>
+ );
+};