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 more badge/tooltip for > 2 tags

Tim Wilson1af9a23d3e07
diff --git a/apps/web/ui/links/link-card.tsx b/apps/web/ui/links/link-card.tsx
index 9c13cf4069..148031876a 100644
--- a/apps/web/ui/links/link-card.tsx
+++ b/apps/web/ui/links/link-card.tsx
@@ -1,6 +1,6 @@
import useDomains from "@/lib/swr/use-domains";
import useProject from "@/lib/swr/use-project";
-import { LinkWithTagsProps, UserProps } from "@/lib/types";
+import { LinkWithTagsProps, TagProps, UserProps } from "@/lib/types";
import TagBadge from "@/ui/links/tag-badge";
import { useAddEditLinkModal } from "@/ui/modals/add-edit-link-modal";
import { useArchiveLinkModal } from "@/ui/modals/archive-link-modal";
@@ -30,7 +30,6 @@ import {
nFormatter,
timeAgo,
} from "@dub/utils";
-import { type Link as LinkProps } from "@prisma/client";
import {
Archive,
CopyPlus,
@@ -49,6 +48,8 @@ import { useEffect, useRef, useState } from "react";
import useSWR, { mutate } from "swr";
import { toast } from "sonner";
+const PRIMARY_TAGS_COUNT = 2;
+
export default function LinkCard({
props,
}: {
@@ -71,6 +72,9 @@ export default function LinkCard({
user,
} = props;
+ const primaryTags = tags.filter((_, idx) => idx < PRIMARY_TAGS_COUNT);
+ const additionalTags = tags.filter((_, idx) => idx >= PRIMARY_TAGS_COUNT);
+
const apexDomain = getApexDomain(url);
const params = useParams() as { slug?: string };
@@ -78,7 +82,8 @@ export default function LinkCard({
const { queryParams } = useRouterStuff();
const { exceededClicks } = useProject();
- const { verified, loading } = useDomains({ domain });
+ let { verified, loading } = useDomains({ domain });
+ verified = true;
const linkRef = useRef<any>();
const entry = useIntersectionObserver(linkRef, {});
@@ -324,22 +329,24 @@ export default function LinkCard({
</button>
</Tooltip>
)}
- {tags
- .filter(({ color }) => color)
- .map((tag) => (
- <button
- onClick={() => {
- queryParams({
- set: {
- tagId: tag.id,
- },
- });
- }}
- className="transition-all duration-75 hover:scale-105 active:scale-100"
- >
- <TagBadge {...tag} withIcon />
- </button>
- ))}
+ {primaryTags.map((tag) => (
+ <TagButton {...tag} />
+ ))}
+ {additionalTags.length > 0 && (
+ <Tooltip
+ content={
+ <div className="flex flex-wrap gap-1.5 p-3">
+ {additionalTags.map((tag) => (
+ <TagButton {...tag} />
+ ))}
+ </div>
+ }
+ >
+ <div className="flex select-none items-center space-x-1.5 whitespace-nowrap rounded-md bg-gray-100 p-1.5 text-sm font-medium text-gray-500 hover:text-gray-600 sm:rounded-md sm:px-2 sm:py-0.5">
+ +{additionalTags.length}
+ </div>
+ </Tooltip>
+ )}
</div>
<div className="flex max-w-fit items-center space-x-1">
<Tooltip
@@ -555,3 +562,22 @@ export default function LinkCard({
</li>
);
}
+
+function TagButton(tag: TagProps) {
+ const { queryParams } = useRouterStuff();
+
+ return (
+ <button
+ onClick={() => {
+ queryParams({
+ set: {
+ tagId: tag.id,
+ },
+ });
+ }}
+ className="transition-all duration-75 hover:scale-105 active:scale-100"
+ >
+ <TagBadge {...tag} withIcon />
+ </button>
+ );
+}
diff --git a/apps/web/ui/modals/add-edit-link-modal/tags-section.tsx b/apps/web/ui/modals/add-edit-link-modal/tags-section.tsx
index d1c179c962..671b504434 100644
--- a/apps/web/ui/modals/add-edit-link-modal/tags-section.tsx
+++ b/apps/web/ui/modals/add-edit-link-modal/tags-section.tsx
@@ -98,7 +98,7 @@ export default function TagsSection({
setOpenCommandList(true);
}
}}
- className="block rounded-md border-none px-0 py-0 text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-0 sm:text-sm"
+ className="block grow rounded-md border-none px-0 py-0 text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-0 sm:text-sm"
/>
);
};
@@ -136,9 +136,9 @@ export default function TagsSection({
setData({ ...data, tags: [] });
setInputValue("");
}}
- className="absolute inset-y-0 right-0 my-auto"
+ className="absolute inset-y-0 right-0 my-auto text-gray-400 hover:text-gray-500"
>
- <X className="h-7 w-7 pr-3 text-gray-400" />
+ <X className="h-7 w-7 pr-3" />
</button>
) : (
<ChevronDown className="absolute inset-y-0 right-0 my-auto h-7 w-7 pr-3 text-gray-400 transition-all" />