/** * @file app/(app)/dashboard/header/TrashLink.tsx * @description Client component rendering a navigation link button to the trash view with a dynamic item counter badge fetched via SWR. */ "use client"; import Link from "next/link"; import { Trash2 } from "lucide-react"; import useSWR from "swr"; /** * Fetches data from a given URL and returns the parsed JSON response. * * @async * @param {string} url - The target endpoint URL to fetch. * @returns {Promise} The JSON response data. */ const fetcher = (url: string) => fetch(url).then((res) => res.json()); /** * Renders an interactive trash icon link featuring hover animations and a self-fetched item count badge. * * @returns {JSX.Element} The rendered trash link component. */ export default function TrashLink() { const { data } = useSWR("/api/trash/count", fetcher, { revalidateOnFocus: false, revalidateIfStale: false, }); const count = data?.count || 0; return ( {count > 0 && ( {count} )} ); }