()
| 87 | const NO_PROGRESS: LoadProgress = { receivedBytes: 0, totalBytes: null }; |
| 88 | |
| 89 | export function useGraphData(): UseGraphDataResult { |
| 90 | const [data, setData] = useState<GraphData | null>(null); |
| 91 | const [loading, setLoading] = useState(false); |
| 92 | const [error, setError] = useState<string | null>(null); |
| 93 | const [progress, setProgress] = useState<LoadProgress>(NO_PROGRESS); |
| 94 | |
| 95 | const fetchOverview = useCallback( |
| 96 | async (project: string, maxNodes?: number, graph: GraphVariant = "code") => { |
| 97 | setLoading(true); |
| 98 | setError(null); |
| 99 | setProgress(NO_PROGRESS); |
| 100 | try { |
| 101 | const result = await fetchLayout(project, maxNodes, setProgress, graph); |
| 102 | setData(result); |
| 103 | } catch (e) { |
| 104 | setError(e instanceof Error ? e.message : "Failed to fetch layout"); |
| 105 | } finally { |
| 106 | setLoading(false); |
| 107 | } |
| 108 | }, |
| 109 | [], |
| 110 | ); |
| 111 | |
| 112 | const fetchDetail = useCallback( |
| 113 | async (project: string, _centerNode: string) => { |
| 114 | setLoading(true); |
| 115 | setError(null); |
| 116 | setProgress(NO_PROGRESS); |
| 117 | try { |
| 118 | /* TODO: detail level with center_node filtering */ |
| 119 | const result = await fetchLayout(project, undefined, setProgress); |
| 120 | setData(result); |
| 121 | } catch (e) { |
| 122 | setError(e instanceof Error ? e.message : "Failed to fetch layout"); |
| 123 | } finally { |
| 124 | setLoading(false); |
| 125 | } |
| 126 | }, |
| 127 | [], |
| 128 | ); |
| 129 | |
| 130 | return { data, loading, error, progress, fetchOverview, fetchDetail }; |
| 131 | } |
no test coverage detected