2024-08-05 19:45:26 -05:00
|
|
|
import React, { useRef, useEffect, useState, useMemo } from 'react';
|
2024-04-22 19:09:46 -05:00
|
|
|
import { OverlayPanel } from 'primereact/overlaypanel';
|
|
|
|
import ZapForm from './ZapForm';
|
2024-04-23 21:30:54 -05:00
|
|
|
import { ProgressSpinner } from 'primereact/progressspinner';
|
2024-04-22 19:09:46 -05:00
|
|
|
|
2024-08-05 15:25:04 -05:00
|
|
|
const ZapDisplay = ({ zapAmount, event, zapsLoading }) => {
|
2024-04-22 19:09:46 -05:00
|
|
|
const op = useRef(null);
|
2024-08-05 19:45:26 -05:00
|
|
|
const [extraLoading, setExtraLoading] = useState(false);
|
|
|
|
|
|
|
|
useMemo(() => {
|
|
|
|
let timeout;
|
|
|
|
if (!zapsLoading && zapAmount === 0) {
|
|
|
|
setExtraLoading(true);
|
2024-08-09 19:00:31 -05:00
|
|
|
timeout = setTimeout(() => setExtraLoading(false), 3000);
|
2024-08-05 19:45:26 -05:00
|
|
|
}
|
|
|
|
return () => clearTimeout(timeout);
|
|
|
|
}, [zapsLoading, zapAmount]);
|
|
|
|
|
2024-04-22 19:09:46 -05:00
|
|
|
return (
|
|
|
|
<>
|
2024-08-07 16:02:13 -05:00
|
|
|
<span className="text-xs cursor-pointer flex items-center relative hover:opacity-80" onClick={(e) => op.current.toggle(e)}>
|
2024-08-13 16:28:25 -05:00
|
|
|
<i className="pi pi-bolt text-yellow-300 text-lg"></i>
|
|
|
|
<span className="relative flex items-center min-w-[20px] min-h-[20px] text-sm">
|
2024-08-05 19:45:26 -05:00
|
|
|
{zapsLoading || zapAmount === null || extraLoading ? (
|
|
|
|
<ProgressSpinner className="absolute top-0 left-0 w-[20px] h-[20px]" strokeWidth="8" animationDuration=".5s" />
|
|
|
|
) : (
|
|
|
|
zapAmount
|
|
|
|
)}
|
|
|
|
</span>
|
2024-07-31 16:41:18 -05:00
|
|
|
</span>
|
2024-04-23 18:52:55 -05:00
|
|
|
<OverlayPanel className='w-[40%] h-[40%]' ref={op}>
|
2024-04-22 19:09:46 -05:00
|
|
|
<ZapForm event={event} />
|
|
|
|
</OverlayPanel>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-07-31 16:41:18 -05:00
|
|
|
export default ZapDisplay;
|