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 { useResourceZapsQuery } from "@/hooks/nostrQueries/useResourceZapsQuery"; import { getSatAmountFromInvoice } from "@/utils/lightning"; import ZapDisplay from "@/components/zaps/ZapDisplay"; const ResourceTemplate = ({ resource }) => { const [zapAmount, setZapAmount] = useState(0); const { zaps, zapsLoading, zapsError, refetchZaps } = useResourceZapsQuery({ event: resource }) const router = useRouter(); const { returnImageProxy } = useImageProxy(); useEffect(() => { if (!zaps || zapsLoading || zapsError) return; let total = 0; zaps.forEach((zap) => { // If the zap matches the event or the parameterized event, then add the zap to the total if (zap.tags.find(tag => tag[0] === "e" && tag[1] === resource.id) || zap.tags.find(tag => tag[0] === "a" && tag[1] === `${resource.kind}:${resource.id}:${resource.d}`)) { 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, zaps, zapsLoading, zapsError]); if (zapsLoading) return
Loading...
; 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.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;