"use client"; import { useState, useEffect } from "react"; import dynamic from "next/dynamic"; import Link from "next/link"; const MapView = dynamic(() => import("@/components/map/MapView"), { ssr: false, loading: () => (
Loading map...
), }); const TIME_FILTERS = [ { label: "1 Hour", value: 1 }, { label: "3 Hours", value: 3 }, { label: "6 Hours", value: 6 }, { label: "12 Hours", value: 12 }, { label: "24 Hours", value: 24 }, { label: "All", value: 0 }, ]; interface DeviceInfo { id: string; name: string; color: string; } export default function MapPage() { const [selectedDevice, setSelectedDevice] = useState("all"); const [timeFilter, setTimeFilter] = useState(1); // Default 1 hour const [isPaused, setIsPaused] = useState(false); const [devices, setDevices] = useState([]); // Custom range state const [filterMode, setFilterMode] = useState<"quick" | "custom">("quick"); const [startTime, setStartTime] = useState(""); const [endTime, setEndTime] = useState(""); // Fetch user's devices from API useEffect(() => { const fetchDevices = async () => { try { const response = await fetch("/api/devices/public"); if (response.ok) { const data = await response.json(); setDevices(data.devices || []); } else { console.error("Failed to fetch devices:", response.status); } } catch (err) { console.error("Failed to fetch devices:", err); } }; fetchDevices(); // Refresh devices every 30 seconds const interval = setInterval(fetchDevices, 30000); return () => clearInterval(interval); }, []); return (
{/* Modern SaaS Header - Compact */}
{/* Single row with title and controls */}
{/* Title - left aligned */}

Location Tracker

{/* Device Filter */}
{/* Time Filter */}
{/* Pause/Resume Button */} {/* Spacer to push buttons to the right */}
{/* Export and Admin Buttons */}
{/* Custom Range - Modern Card Style */} {filterMode === "custom" && (
setStartTime(e.target.value)} className="flex-1 px-3 py-2 text-sm bg-white border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all" />
setEndTime(e.target.value)} className="flex-1 px-3 py-2 text-sm bg-white border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all" />
)}
{/* Map */}
); }