"use client"; import { useState } from "react"; import { Popover } from "../Popover"; import { Tag } from "../Tags"; import { TagTiny } from "../Icons/TagTiny"; import { prefetchTagPosts, type TagPostsSource } from "./tagPosts"; export function TagButton(props: { tags: string[]; publicationUri?: string; showOtherPublications: boolean; onTagClick: (tag: string) => void; className?: string; }) { let [open, setOpen] = useState(false); if (props.tags.length === 0) return null; let source = (tag: string): TagPostsSource => ({ tag, publicationUri: props.publicationUri, showOtherPublications: props.showOtherPublications, }); // Server actions run one at a time per client, so warming every tag from the // icon would queue the clicked tag's fetch behind the others. The icon only // prefetches when there's a single tag to guess; otherwise the chips do it. let prefetchOnlyTag = props.tags.length === 1 ? () => prefetchTagPosts(source(props.tags[0])) : undefined; return ( {props.tags.length} } >
{props.tags.map((tag) => ( prefetchTagPosts(source(t))} onClick={(t) => { setOpen(false); props.onTagClick(t); }} /> ))}
); }