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.

Fix tags

Tim Wilson467ea268ba41
diff --git a/apps/web/ui/links/link-details-column.tsx b/apps/web/ui/links/link-details-column.tsx
index 9bc78703e4..6acaa1021e 100644
--- a/apps/web/ui/links/link-details-column.tsx
+++ b/apps/web/ui/links/link-details-column.tsx
@@ -1,5 +1,6 @@
import { CompositeAnalyticsResponseOptions } from "@/lib/analytics/types";
import useWorkspace from "@/lib/swr/use-workspace";
+import { TagProps } from "@/lib/types";
import {
AnimatedSizeContainer,
CardList,
@@ -7,12 +8,19 @@ import {
Tooltip,
useIntersectionObserver,
useMediaQuery,
+ useRouterStuff,
} from "@dub/ui";
import { CursorRays, InvoiceDollar, LinesY } from "@dub/ui/src/icons";
import { cn, fetcher, nFormatter, timeAgo } from "@dub/utils";
import Link from "next/link";
import { useSearchParams } from "next/navigation";
-import { useContext, useMemo, useRef, useState } from "react";
+import {
+ PropsWithChildren,
+ useContext,
+ useMemo,
+ useRef,
+ useState,
+} from "react";
import useSWR from "swr";
import { LinkControls } from "./link-controls";
import { ResponseLink } from "./links-container";
@@ -46,6 +54,8 @@ function useOrganizedTags(tags: ResponseLink["tags"]) {
export function LinkDetailsColumn({ link }: { link: ResponseLink }) {
const { tags } = link;
+ const { queryParams } = useRouterStuff();
+
const ref = useRef<HTMLDivElement>(null);
const entry = useIntersectionObserver(ref, {});
const isVisible = !!entry?.isIntersecting;
@@ -57,24 +67,9 @@ export function LinkDetailsColumn({ link }: { link: ResponseLink }) {
{isVisible && (
<>
{primaryTag && (
- <Tooltip
- content={
- <div className="flex flex-wrap gap-1.5 p-3">
- {tags.map((tag) => (
- <TagBadge key={tag.id} {...tag} />
- ))}
- </div>
- }
- side="bottom"
- >
- <div className="cursor-default transition-transform hover:scale-105">
- <TagBadge
- withIcon
- {...primaryTag}
- plus={additionalTags.length}
- />
- </div>
- </Tooltip>
+ <TagsTooltip additionalTags={additionalTags}>
+ <TagButton tag={primaryTag} plus={additionalTags.length} />
+ </TagsTooltip>
)}
<AnalyticsBadge link={link} />
<LinkControls link={link} />
@@ -84,6 +79,56 @@ export function LinkDetailsColumn({ link }: { link: ResponseLink }) {
);
}
+function TagsTooltip({
+ additionalTags,
+ children,
+}: PropsWithChildren<{ additionalTags: TagProps[] }>) {
+ return !!additionalTags.length ? (
+ <Tooltip
+ content={
+ <div className="flex flex-wrap gap-1.5 p-3">
+ {additionalTags.map((tag) => (
+ <TagButton key={tag.id} tag={tag} />
+ ))}
+ </div>
+ }
+ side="bottom"
+ >
+ <div>{children}</div>
+ </Tooltip>
+ ) : (
+ children
+ );
+}
+
+function TagButton({ tag, plus }: { tag: TagProps; plus?: number }) {
+ const { queryParams } = useRouterStuff();
+ const searchParams = useSearchParams();
+
+ const selectedTagIds =
+ searchParams?.get("tagIds")?.split(",")?.filter(Boolean) ?? [];
+
+ return (
+ <button
+ onClick={() => {
+ let newTagIds = selectedTagIds.includes(tag.id)
+ ? selectedTagIds.filter((id) => id !== tag.id)
+ : [...selectedTagIds, tag.id];
+
+ queryParams({
+ set: {
+ tagIds: newTagIds.join(","),
+ },
+ del: [...(newTagIds.length ? [] : ["tagIds"])],
+ });
+ }}
+ className="transition-all duration-75 hover:scale-105 active:scale-100"
+ >
+ <TagBadge {...tag} withIcon plus={plus} />
+ </button>
+ );
+}
+
function AnalyticsBadge({ link }: { link: ResponseLink }) {
const { id, domain, key, trackConversion } = link;
diff --git a/apps/web/ui/links/links-container.tsx b/apps/web/ui/links/links-container.tsx
index 284d57ec09..32e6d4037b 100644
--- a/apps/web/ui/links/links-container.tsx
+++ b/apps/web/ui/links/links-container.tsx
@@ -100,7 +100,11 @@ function LinksList({
links.map((link) => <LinkCard link={link} />)
: // Loading placeholder cards
Array.from({ length: 6 }).map((_, idx) => (
- <CardList.Card key={idx} innerClassName="flex items-center gap-4">
+ <CardList.Card
+ key={idx}
+ outerClassName="pointer-events-none"
+ innerClassName="flex items-center gap-4"
+ >
<LinkCardPlaceholder />
</CardList.Card>
))}