Spaces:
Sleeping
Sleeping
File size: 1,260 Bytes
8e0dd55 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | import { useState, useEffect } from 'react';
interface ProcessedProject {
id: string;
owner: string;
repo: string;
name: string;
repo_type: string;
submittedAt: number;
language: string;
}
export function useProcessedProjects() {
const [projects, setProjects] = useState<ProcessedProject[]>([]);
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
const fetchProjects = async () => {
setIsLoading(true);
setError(null);
try {
const response = await fetch('/api/wiki/projects');
if (!response.ok) {
throw new Error(`Failed to fetch projects: ${response.statusText}`);
}
const data = await response.json();
if (data.error) {
throw new Error(data.error);
}
setProjects(data as ProcessedProject[]);
} catch (e: unknown) {
console.error("Failed to load projects from API:", e);
const message = e instanceof Error ? e.message : "An unknown error occurred.";
setError(message);
setProjects([]);
} finally {
setIsLoading(false);
}
};
fetchProjects();
}, []);
return { projects, isLoading, error };
}
|