'use client'; import { useEffect, useState } from 'react'; import dynamic from 'next/dynamic'; import { SensorWithLatestReading } from '@/lib/types'; // Dynamically import map to avoid SSR issues const MapView = dynamic(() => import('./MapView'), { ssr: false }); export default function SensorMap() { const [sensors, setSensors] = useState([]); const [selectedSensor, setSelectedSensor] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { fetchSensors(); // Refresh data every 30 seconds const interval = setInterval(fetchSensors, 30000); return () => clearInterval(interval); }, []); const fetchSensors = async () => { try { const response = await fetch('/api/sensors'); const data = await response.json(); setSensors(data); } catch (error) { console.error('Error fetching sensors:', error); } finally { setLoading(false); } }; if (loading) { return (

Loading sensors...

); } return (
{/* Header */}

Water Quality Monitoring

{sensors.length} active sensor{sensors.length !== 1 ? 's' : ''} worldwide

{/* Map Container */}
); }