'use client'; import createGlobe from 'cobe'; import { useEffect, useRef, useState } from 'react'; import { Globe } from 'lucide-react'; export function GlobeCard() { const canvasRef = useRef(null); const [visitorStats, setVisitorStats] = useState({ total: 0, active24h: 0, active7d: 0, locations: [], }); useEffect(() => { async function fetchVisitors() { try { const res = await fetch('/api/visitors'); const data = await res.json(); setVisitorStats({ total: data.totalVisitors || 0, active24h: data.active24h || 0, active7d: data.active7d || 0, locations: data.locations || [], }); } catch (e) { console.error('Failed to load visitors', e); } } fetchVisitors(); const interval = setInterval(fetchVisitors, 30000); return () => clearInterval(interval); }, []); useEffect(() => { let phi = 0; if (!canvasRef.current) return; const globe = createGlobe(canvasRef.current, { devicePixelRatio: 2, width: 600 * 2, height: 600 * 2, phi: 0, theta: 0, dark: 1, diffuse: 1.2, mapSamples: 16000, mapBrightness: 6, baseColor: [0.3, 0.3, 0.3], markerColor: [0.1, 0.8, 1], glowColor: [0.1, 0.1, 0.2], markers: visitorStats.locations, onRender: (state) => { state.phi = phi; phi += 0.01; }, }); return () => { globe.destroy(); }; }, [visitorStats.locations]); return (
Visitor Map
{visitorStats.active24h} LAST 24H
{visitorStats.active7d} LAST 7D
{visitorStats.total} ALL TIME
); }