/** * Custom hook for fetching space data */ import { useState, useEffect } from 'react'; import { fetchCelestialPositions } from '../utils/api'; import type { CelestialBody } from '../types'; export function useSpaceData() { const [bodies, setBodies] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { async function loadData() { try { setLoading(true); setError(null); // Fetch current position - single point in time at current hour // Round to current hour (00 minutes, 00 seconds) const now = new Date(); now.setMinutes(0, 0, 0); const data = await fetchCelestialPositions( now.toISOString(), now.toISOString(), // Same as start - single point in time '1h' // 1 hour step (though doesn't matter for single point) ); setBodies(data.bodies); } catch (err) { console.error('Failed to fetch celestial data:', err); setError(err instanceof Error ? err.message : 'Unknown error'); } finally { setLoading(false); } } loadData(); }, []); return { bodies, loading, error }; }