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
{resource.summary}
{formatTimestampToHowLongAgo(resource.published_at)}