diff --git a/components/publication-card.tsx b/components/publication-card.tsx index c3b24042..3de6e7d2 100644 --- a/components/publication-card.tsx +++ b/components/publication-card.tsx @@ -17,8 +17,8 @@ import { } from "lucide-react"; import Image from "next/image"; import { useEffect, useState } from "react"; -import { TrackedLink } from "./util-tracked-link"; import { TrackedButton } from "./util-tracked-button"; +import { TrackedLink } from "./util-tracked-link"; interface Props { bibtexKey: string; @@ -49,24 +49,9 @@ export function PublicationCard({ "idle" ); const [imageError, setImageError] = useState(false); - const [downloadUrl, setDownloadUrl] = useState(null); - const [isClient, setIsClient] = useState(false); - useEffect(() => { - setIsClient(true); - }, []); - - useEffect(() => { - return () => { - if (downloadUrl) { - URL.revokeObjectURL(downloadUrl); - } - }; - }, [downloadUrl]); - - const handleCopy = (e: React.MouseEvent) => { - e.stopPropagation(); - if (isClient && navigator.clipboard?.writeText) { + const handleCopy = () => { + if (navigator.clipboard?.writeText) { navigator.clipboard .writeText(bibtex) .then(() => { @@ -84,17 +69,16 @@ export function PublicationCard({ } }; - const handleDownload = (e: React.MouseEvent) => { - e.stopPropagation(); + const handleDownload = () => { const blob = new Blob([bibtex], { type: "text/plain" }); const url = URL.createObjectURL(blob); - setDownloadUrl(url); const a = document.createElement("a"); a.href = url; a.download = `${bibtexKey}.bib`; document.body.appendChild(a); a.click(); document.body.removeChild(a); + URL.revokeObjectURL(url); // Clean up immediately }; const handleCardClick = () => { @@ -133,94 +117,93 @@ export function PublicationCard({ ); - return ( -
-
- {ImageContent} -
+ return ( +
+
+ {ImageContent} +
-
- - {title} - -

- {formattedAuthors}. {journal}. {year} -

-
+
+ + {title} + +

+ {formattedAuthors}. {journal}. {year} +

+
-
- - - - - - - -

Download BibTeX

-
-
- - - - - {copyStatus === "idle" && } - {copyStatus === "success" && ( - - )} - {copyStatus === "error" && } - - - -

Copy Citation

-
-
- - {pdfUrl && pdfAvailable && ( +
- + + -

Open PDF

+

Download BibTeX

- )} + + + + + {copyStatus === "idle" && } + {copyStatus === "success" && ( + + )} + {copyStatus === "error" && } + + + +

Copy Citation

+
+
+ + {pdfUrl && pdfAvailable && ( + + + + + +

Open PDF

+
+
+ )} +
-
-); + ); }; \ No newline at end of file diff --git a/components/util-tracked-button.tsx b/components/util-tracked-button.tsx index 9bf0b521..df4b4fad 100644 --- a/components/util-tracked-button.tsx +++ b/components/util-tracked-button.tsx @@ -18,6 +18,9 @@ export const TrackedButton = ({ const handleTrackedClick = ( e: React.MouseEvent ) => { + + e.stopPropagation(); + if (window.umami) { window.umami.track(eventName); } diff --git a/types/umami.d.ts b/types/umami.d.ts new file mode 100644 index 00000000..01dfd4ac --- /dev/null +++ b/types/umami.d.ts @@ -0,0 +1,11 @@ +// types/umami.d.ts + +declare global { + interface Window { + umami?: { + track: (event_name: string, data?: object) => void; + }; + } +} + +export {}; \ No newline at end of file