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 { useNostr } from "@/hooks/useNostr"; import { getSatAmountFromInvoice } from "@/utils/lightning"; const ResourceTemplate = ({resource}) => { const [zapAmount, setZapAmount] = useState(null); const router = useRouter(); const { returnImageProxy } = useImageProxy(); useEffect(() => { if (!resource || !resource.zaps) return; let total = 0; resource.zaps.forEach((zap) => { 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)}

{zapAmount}

); }; export default ResourceTemplate;