import React, { useEffect, useState, useMemo } from "react"; import Image from "next/image"; import { useRouter } from "next/router"; import { formatTimestampToHowLongAgo } from "@/utils/time"; import { useImageProxy } from "@/hooks/useImageProxy"; import { useZapsQuery } from "@/hooks/nostrQueries/useZapsQuery"; import { getSatAmountFromInvoice } from "@/utils/lightning"; import ZapDisplay from "@/components/zaps/ZapDisplay"; const ResourceTemplate = ({ resource }) => { const [zapAmount, setZapAmount] = useState(0); const router = useRouter(); const { returnImageProxy } = useImageProxy(); useEffect(() => { if (!resource?.zaps || !resource?.zaps.length > 0) return; let total = 0; resource.zaps.forEach((zap) => { // If the zap matches the event or the parameterized event, then add the zap to the total const bolt11Tag = zap.tags.find(tag => tag[0] === "bolt11"); const invoice = bolt11Tag ? bolt11Tag[1] : null; if (invoice) { const amount = getSatAmountFromInvoice(invoice); total += amount; } }); setZapAmount(total); }, [resource]); 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.push(`/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}

{formatTimestampToHowLongAgo(resource.published_at)}

); }; export default ResourceTemplate;