Files
CRAPP/src/lib/presenze-mese.ts
T

37 lines
1.3 KiB
TypeScript
Raw Normal View History

2026-08-06 08:36:47 +02:00
import { useMemo } from "react";
import { useEventi } from "./eventi";
import { useRispostePresenze } from "./presenze";
import { useGiocatoriSquadra } from "./giocatori-squadra";
import {
presenzeUltimoMese,
presenzeUltimoMeseTutti,
type StatistichePresenza,
} from "./presenze-mese-core";
2026-08-06 08:36:47 +02:00
/**
* Percentuale di presenze dell'ultimo mese (30 giorni), utile per le convocazioni.
* Usa solo cache già in memoria: nessuna query aggiuntiva. Il calcolo sta in
* `presenze-mese-core.ts`, qui c'è solo il collegamento agli hook.
2026-08-06 08:36:47 +02:00
*/
export function usePresenzeUltimoMese(giocatoreId: string | undefined): StatistichePresenza {
2026-08-06 08:36:47 +02:00
const { eventi } = useEventi();
const { presenze } = useRispostePresenze();
return useMemo(
() => presenzeUltimoMese(giocatoreId, eventi, presenze),
[eventi, presenze, giocatoreId],
);
2026-08-06 08:36:47 +02:00
}
/** Percentuale presenze ultimi 30 giorni per tutti i giocatori (mappa per id). */
export function usePresenzeUltimoMeseTutti(): Record<string, StatistichePresenza> {
2026-08-06 08:36:47 +02:00
const { eventi } = useEventi();
const { presenze } = useRispostePresenze();
const { righe: squadra } = useGiocatoriSquadra();
2026-08-06 08:36:47 +02:00
return useMemo(() => {
const idRosa = squadra.filter((g) => g.attivo).map((g) => g.id);
return presenzeUltimoMeseTutti(eventi, presenze, idRosa);
}, [eventi, presenze, squadra]);
}