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 { useNostr } from "@/hooks/useNostr"; import { getSatAmountFromInvoice } from "@/utils/lightning"; const ResourceTemplate = (resource) => { const [zaps, setZaps] = useState([]); const [zapAmount, setZapAmount] = useState(null); const router = useRouter(); const { returnImageProxy } = useImageProxy(); const { fetchZapsForEvent } = useNostr(); useEffect(() => { const fetchZaps = async () => { try { const zaps = await fetchZapsForEvent(resource.id); setZaps(zaps); } catch (error) { console.error("Error fetching zaps:", error); } }; fetchZaps(); }, [fetchZapsForEvent, resource]); useEffect(() => { if (zaps.length > 0) { zaps.map((zap) => { const bolt11Tag = zap.tags.find((tag) => tag[0] === "bolt11"); const invoice = bolt11Tag ? bolt11Tag[1] : null; if (invoice) { const amount = getSatAmountFromInvoice(invoice); setZapAmount(zapAmount + amount); } }); } }, [zaps]); 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" style={{ paddingBottom: "56.25%"}} > resource thumbnail

{resource.title}

{resource.summary}

{formatTimestampToHowLongAgo(resource.published_at)}

{zapAmount}

); }; export default ResourceTemplate;