import React, { useEffect, useState } from "react"; import Image from "next/image"; import { useRouter } from "next/router"; import { formatTimestampToHowLongAgo } from "@/utils/time"; import { useImageProxy } from "@/hooks/useImageProxy"; import { getTotalFromZaps } from "@/utils/lightning"; import { Tag } from "primereact/tag"; import ZapDisplay from "@/components/zaps/ZapDisplay"; import { useZapsSubscription } from "@/hooks/nostrQueries/zaps/useZapsSubscription"; const ResourceTemplate = ({ resource }) => { const { zaps, zapsLoading, zapsError } = useZapsSubscription({ event: resource }); const [zapAmount, setZapAmount] = useState(0); const router = useRouter(); const { returnImageProxy } = useImageProxy(); useEffect(() => { if (zaps.length > 0) { const total = getTotalFromZaps(zaps, resource); setZapAmount(total); } }, [zaps, resource]); if (zapsError) return
Error: {zapsError}
; return (
{/* Wrap the image in a div with a relative class with a padding-bottom of 56.25% representing the aspect ratio of 16:9 */}
router.replace(`/details/${resource.id}`)} className="relative w-full h-0 hover:opacity-80 transition-opacity duration-300 cursor-pointer" style={{ paddingBottom: "56.25%" }} > resource thumbnail

{resource.title}

{resource.summary}

{resource.price && resource.price > 0 ? (

Price: {resource.price} sats

) : (

Free

)}

{formatTimestampToHowLongAgo(resource.published_at)}

{resource?.topics && resource?.topics.length > 0 && (
{resource.topics.map((topic, index) => ( ))}
)}
); }; export default ResourceTemplate;