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.

Improve archived links filter

Steven Tey5a737c5dd6c0
diff --git a/apps/web/lib/swr/use-links-count.ts b/apps/web/lib/swr/use-links-count.ts
index e573e03fa6..14c44fc70c 100644
--- a/apps/web/lib/swr/use-links-count.ts
+++ b/apps/web/lib/swr/use-links-count.ts
@@ -3,13 +3,15 @@ import { fetcher } from "@dub/utils";
import { usePathname } from "next/navigation";
import { useEffect, useState } from "react";
import useSWR from "swr";
+import z from "../zod";
+import { getLinksCountQuerySchema } from "../zod/schemas/links";
import useWorkspace from "./use-workspace";
-export default function useLinksCount({
- groupBy,
-}: {
- groupBy?: "domain" | "tagId";
-} = {}) {
+const partialQuerySchema = getLinksCountQuerySchema.partial();
+
+export default function useLinksCount(
+ opts: z.infer<typeof partialQuerySchema> = {},
+) {
const { id, slug } = useWorkspace();
const { getQueryString } = useRouterStuff();
const pathname = usePathname();
@@ -27,7 +29,7 @@ export default function useLinksCount({
? `/api/links/count${getQueryString(
{
workspaceId: id,
- ...(groupBy && { groupBy }),
+ ...opts,
},
{
ignore: [
@@ -40,7 +42,7 @@ export default function useLinksCount({
)}`
: admin
? `/api/admin/links/count${getQueryString({
- ...(groupBy && { groupBy }),
+ ...opts,
})}`
: null,
fetcher,
diff --git a/apps/web/ui/links/archived-links-hint.tsx b/apps/web/ui/links/archived-links-hint.tsx
new file mode 100644
index 0000000000..0c04082400
--- /dev/null
+++ b/apps/web/ui/links/archived-links-hint.tsx
@@ -0,0 +1,39 @@
+"use client";
+
+import useLinksCount from "@/lib/swr/use-links-count";
+import { useRouterStuff } from "@dub/ui";
+import { Archive } from "lucide-react";
+import { useSearchParams } from "next/navigation";
+
+export default function ArchivedLinksHint() {
+ const searchParams = useSearchParams();
+ const showArchived = searchParams.get("showArchived") === "true";
+ const { data: count } = useLinksCount({ showArchived: true });
+ const { queryParams } = useRouterStuff();
+
+ return (
+ count > 0 &&
+ !showArchived && (
+ <li className="flex items-center rounded-lg border border-gray-200 bg-white p-3 text-sm text-gray-500 ring-2 ring-gray-50 transition-all sm:p-4">
+ <Archive className="mr-2 h-4 w-4" />
+ <p>You have {count} archived links that match your filters.</p>
+ <button
+ className="ml-1 font-medium underline underline-offset-2 hover:text-gray-800"
+ onClick={() =>
+ queryParams(
+ showArchived
+ ? { del: "showArchived" }
+ : {
+ set: {
+ showArchived: "true",
+ },
+ },
+ )
+ }
+ >
+ Show archived links?
+ </button>
+ </li>
+ )
+ );
+}
diff --git a/apps/web/ui/links/link-filters.tsx b/apps/web/ui/links/link-filters.tsx
index 5da125b846..e138fbf72e 100644
--- a/apps/web/ui/links/link-filters.tsx
+++ b/apps/web/ui/links/link-filters.tsx
@@ -27,12 +27,7 @@ import {
import { AnimatePresence, motion } from "framer-motion";
import { ChevronRight, Edit3, Search, XCircle } from "lucide-react";
import { useSession } from "next-auth/react";
-import {
- useParams,
- usePathname,
- useRouter,
- useSearchParams,
-} from "next/navigation";
+import { useParams, useRouter, useSearchParams } from "next/navigation";
import { useCallback, useEffect, useMemo, useState } from "react";
import { toast } from "sonner";
import { mutate } from "swr";
@@ -45,17 +40,7 @@ export default function LinkFilters() {
const { tags } = useTags();
const { data: tagsCount } = useLinksCount({ groupBy: "tagId" });
- const pathname = usePathname();
const searchParams = useSearchParams();
- const { queryParams } = useRouterStuff();
-
- useEffect(() => {
- if (searchParams?.has("search")) {
- queryParams({
- set: { showArchived: "true" },
- });
- }
- }, [pathname, searchParams]);
const showClearButton = useMemo(() => {
return [
diff --git a/apps/web/ui/links/links-container.tsx b/apps/web/ui/links/links-container.tsx
index 71cdae2678..093d337163 100644
--- a/apps/web/ui/links/links-container.tsx
+++ b/apps/web/ui/links/links-container.tsx
@@ -3,8 +3,9 @@
import useLinks from "@/lib/swr/use-links";
import useLinksCount from "@/lib/swr/use-links-count";
import { MaxWidthWrapper } from "@dub/ui";
-import { Suspense, useRef } from "react";
+import { Suspense } from "react";
import { useLinkFiltersModal } from "../modals/link-filters-modal";
+import ArchivedLinksHint from "./archived-links-hint";
import LinkCard from "./link-card";
import LinkCardPlaceholder from "./link-card-placeholder";
import LinkFilters, { InputSearchBox } from "./link-filters";
@@ -20,7 +21,6 @@ export default function LinksContainer({
const { links, isValidating } = useLinks();
const { data: count } = useLinksCount();
const { LinkFiltersButton, LinkFiltersModal } = useLinkFiltersModal();
- const searchInputRef = useRef();
return (
<>
@@ -58,6 +58,9 @@ export default function LinksContainer({
<LinkCardPlaceholder key={i} />
))
)}
+ <Suspense>
+ <ArchivedLinksHint />
+ </Suspense>
</ul>
{count && count > 0 ? (
<Suspense>
diff --git a/apps/web/ui/links/no-links-placeholder.tsx b/apps/web/ui/links/no-links-placeholder.tsx
index 1a453829c5..92a86b569c 100644
--- a/apps/web/ui/links/no-links-placeholder.tsx
+++ b/apps/web/ui/links/no-links-placeholder.tsx
@@ -4,7 +4,7 @@ export default function NoLinksPlaceholder({
AddEditLinkButton: () => JSX.Element;
}) {
return (
- <div className="mb-12 flex flex-col items-center justify-center rounded-md border border-gray-200 bg-white py-12">
+ <div className="flex flex-col items-center justify-center rounded-md border border-gray-200 bg-white py-12">
<h2 className="z-10 text-xl font-semibold text-gray-700">
No links found.
</h2>
diff --git a/apps/web/ui/shared/icons/archive.tsx b/apps/web/ui/shared/icons/archive.tsx
deleted file mode 100644
index 92c9fad450..0000000000
--- a/apps/web/ui/shared/icons/archive.tsx
+++ /dev/null
@@ -1,20 +0,0 @@
-export default function Archive({ className }: { className: string }) {
- return (
- <svg
- fill="none"
- height="24"
- shapeRendering="geometricPrecision"
- stroke="currentColor"
- strokeLinecap="round"
- strokeLinejoin="round"
- strokeWidth="1.5"
- viewBox="0 0 24 24"
- width="24"
- className={className}
- >
- <path d="M21 8v13H3V8" />
- <path d="M1 3h22v5H1z" />
- <path d="M10 12h4" />
- </svg>
- );
-}
diff --git a/apps/web/ui/shared/icons/index.tsx b/apps/web/ui/shared/icons/index.tsx
index 9a1be7447c..9a09b05be3 100644
--- a/apps/web/ui/shared/icons/index.tsx
+++ b/apps/web/ui/shared/icons/index.tsx
@@ -2,7 +2,6 @@
export { default as Airplay } from "./airplay";
export { default as AlertCircleFill } from "./alert-circle-fill";
-export { default as Archive } from "./archive";
export { default as Chart } from "./chart";
export { default as CheckCircleFill } from "./check-circle-fill";
export { default as Clipboard } from "./clipboard";
diff --git a/packages/ui/src/hooks/use-router-stuff.ts b/packages/ui/src/hooks/use-router-stuff.ts
index 47c576e44f..e7f168890c 100644
--- a/packages/ui/src/hooks/use-router-stuff.ts
+++ b/packages/ui/src/hooks/use-router-stuff.ts
@@ -7,7 +7,7 @@ export function useRouterStuff() {
const searchParamsObj = Object.fromEntries(searchParams);
const getQueryString = (
- kv?: Record<string, string>,
+ kv?: Record<string, any>,
opts?: {
ignore?: string[];
},