(initialStats: FreebuffLiveStats)
| 14 | import type { LucideIcon } from 'lucide-react' |
| 15 | |
| 16 | function useHomepageLiveStats(initialStats: FreebuffLiveStats) { |
| 17 | const [isVisible, setIsVisible] = useState(false) |
| 18 | const sectionRef = useRef<HTMLElement>(null) |
| 19 | const stats = useLiveStats(initialStats, { |
| 20 | enabled: isVisible, |
| 21 | pauseWhenHidden: true, |
| 22 | refreshOnMount: true, |
| 23 | }) |
| 24 | |
| 25 | useEffect(() => { |
| 26 | const section = sectionRef.current |
| 27 | if (!section || !('IntersectionObserver' in window)) { |
| 28 | setIsVisible(true) |
| 29 | return |
| 30 | } |
| 31 | |
| 32 | const observer = new IntersectionObserver( |
| 33 | ([entry]) => setIsVisible(entry.isIntersecting), |
| 34 | { rootMargin: '240px 0px', threshold: 0.01 }, |
| 35 | ) |
| 36 | |
| 37 | observer.observe(section) |
| 38 | return () => observer.disconnect() |
| 39 | }, []) |
| 40 | |
| 41 | return { sectionRef, stats } |
| 42 | } |
| 43 | |
| 44 | function LiveRows({ |
| 45 | title, |
no test coverage detected