this repo has no description
1import { useState, useEffect, useCallback } from 'react';
2import { apiClient } from '../api/client';
3import type { ProgressData } from '../types/progress';
4
5interface UseProgressReturn {
6 progress: ProgressData | null;
7 loading: boolean;
8 error: string | null;
9 refetch: () => void;
10}
11
12export function useProgress(): UseProgressReturn {
13 const [progress, setProgress] = useState<ProgressData | null>(null);
14 const [loading, setLoading] = useState(true);
15 const [error, setError] = useState<string | null>(null);
16
17 const fetchProgress = useCallback(() => {
18 setLoading(true);
19 setError(null);
20 apiClient
21 .get<ProgressData>('/api/progress')
22 .then((data) => {
23 setProgress(data);
24 })
25 .catch((err: Error) => {
26 setError(err.message);
27 })
28 .finally(() => {
29 setLoading(false);
30 });
31 }, []);
32
33 useEffect(() => {
34 fetchProgress();
35 }, [fetchProgress]);
36
37 return { progress, loading, error, refetch: fetchProgress };
38}