From aa60c23611af225bf3cbf0de78b0541e3b89f3cd Mon Sep 17 00:00:00 2001 From: austinkelsay Date: Mon, 5 Aug 2024 19:45:26 -0500 Subject: [PATCH] Improvements to zaps zap loading and spinner styles --- src/components/zaps/ZapDisplay.js | 27 ++++++--- src/components/zaps/ZapForm.js | 56 +------------------ src/hooks/nostrQueries/zaps/useZapsQuery.js | 5 +- .../nostrQueries/zaps/useZapsSubscription.js | 18 +++--- src/pages/details/[slug].js | 5 +- 5 files changed, 40 insertions(+), 71 deletions(-) diff --git a/src/components/zaps/ZapDisplay.js b/src/components/zaps/ZapDisplay.js index 32e8531..90290c2 100644 --- a/src/components/zaps/ZapDisplay.js +++ b/src/components/zaps/ZapDisplay.js @@ -1,19 +1,32 @@ -import React, { useRef } from 'react'; +import React, { useRef, useEffect, useState, useMemo } from 'react'; import { OverlayPanel } from 'primereact/overlaypanel'; import ZapForm from './ZapForm'; import { ProgressSpinner } from 'primereact/progressspinner'; const ZapDisplay = ({ zapAmount, event, zapsLoading }) => { const op = useRef(null); + const [extraLoading, setExtraLoading] = useState(false); + + useMemo(() => { + let timeout; + if (!zapsLoading && zapAmount === 0) { + setExtraLoading(true); + timeout = setTimeout(() => setExtraLoading(false), 5000); + } + return () => clearTimeout(timeout); + }, [zapsLoading, zapAmount]); + return ( <> - op.current.toggle(e)}> + op.current.toggle(e)}> - {zapsLoading ? ( - - ) : ( - zapAmount !== null ? zapAmount : - )} + + {zapsLoading || zapAmount === null || extraLoading ? ( + + ) : ( + zapAmount + )} + diff --git a/src/components/zaps/ZapForm.js b/src/components/zaps/ZapForm.js index 4d92add..ec45961 100644 --- a/src/components/zaps/ZapForm.js +++ b/src/components/zaps/ZapForm.js @@ -1,13 +1,12 @@ -import React from "react"; +import React, { useEffect } from "react"; import { nip19 } from "nostr-tools"; const ZapForm = ({ event }) => { - console.log('event', event); const nAddress = nip19.naddrEncode({ kind: event?.kind, pubkey: event?.pubkey, identifier: event.d, - }) + }); return (