| 1 | /** biome-ignore-all lint/suspicious/noExplicitAny: This use requires any */ |
| 2 | import { useCallback, useState } from "react"; |
| 3 | |
| 4 | // Hook for dynamic font info loading |
| 5 | export function useFontInfo() { |
| 6 | const [fontInfos, setFontInfos] = useState<any[] | null>(null); |
| 7 | const [isLoading, setIsLoading] = useState(false); |
| 8 | const [error, setError] = useState<string | null>(null); |
| 9 | |
| 10 | const loadFontInfo = useCallback(async () => { |
| 11 | if (fontInfos || isLoading) return; // Already loaded or loading |
| 12 | |
| 13 | setIsLoading(true); |
| 14 | setError(null); |
| 15 | |
| 16 | try { |
| 17 | // Dynamic import of the large JSON file |
| 18 | const fontInfoModule = await import("../font-preview/fontInfo.json"); |
| 19 | setFontInfos(fontInfoModule.default); |
| 20 | } catch (err) { |
| 21 | console.error("Failed to load font info:", err); |
| 22 | setError("Failed to load fonts"); |
| 23 | } finally { |
| 24 | setIsLoading(false); |
| 25 | } |
| 26 | }, [fontInfos, isLoading]); |
| 27 | |
| 28 | return { fontInfos, isLoading, error, loadFontInfo }; |
| 29 | } |
| 30 |