import { useState, useEffect, useCallback } from 'react'; import { apiClient } from '../api/client'; import type { ProgressData } from '../types/progress'; interface UseProgressReturn { progress: ProgressData | null; loading: boolean; error: string | null; refetch: () => void; } export function useProgress(): UseProgressReturn { const [progress, setProgress] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const fetchProgress = useCallback(() => { setLoading(true); setError(null); apiClient .get('/api/progress') .then((data) => { setProgress(data); }) .catch((err: Error) => { setError(err.message); }) .finally(() => { setLoading(false); }); }, []); useEffect(() => { fetchProgress(); }, [fetchProgress]); return { progress, loading, error, refetch: fetchProgress }; }