first commit

This commit is contained in:
nBiqoz
2025-10-05 16:10:35 +02:00
parent 201fca4e68
commit 13cd637391
70 changed files with 7287 additions and 130 deletions

54
hooks/useStats.ts Normal file
View File

@@ -0,0 +1,54 @@
"use client";
import { useState, useEffect } from "react";
interface DailyToken {
name: string;
value: number;
}
interface ModelDistribution {
name: string;
value: number;
}
interface StatsData {
dailyTokens: DailyToken[];
modelDistribution: ModelDistribution[];
}
export function useStats() {
const [stats, setStats] = useState<StatsData | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const fetchStats = async () => {
try {
setLoading(true);
setError(null);
const response = await fetch("/api/stats");
if (!response.ok) {
throw new Error("Erreur lors du chargement des statistiques");
}
const data = await response.json();
setStats(data);
} catch (err) {
setError(err instanceof Error ? err.message : "Erreur inconnue");
} finally {
setLoading(false);
}
};
useEffect(() => {
fetchStats();
}, []);
return {
stats,
loading,
error,
refetch: fetchStats
};
}