Card evento filtrata sui convocati + copertura test per numero di convocati
- La card (Calendario e Home) conta «presenti/convocati» e mostra i pulsanti di presenza solo ai convocati; «Da confermare» in Home esclude gli eventi a cui non si è convocati. - Nuove eConvocato() e rosaConvocata(): il filtro, prima ripetuto in tre punti, è una funzione pura usata da card, «Rosa e presenze» e convocatiEvento. - Test per 0, 1, 2, 3, tutti e id sconosciuti su visibilità, convocazione e solleciti. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8def97731c
commit
5ee148b88b
7 files changed
+103
-12
No files matched your search
+15
-4
@@ -90,6 +90,11 @@ export function useEventi() {
|
||||
return { ...query, eventi: query.data ?? [] };
|
||||
}
|
||||
|
||||
/** Il giocatore è tra i convocati (elenco vuoto = tutta la rosa). */
|
||||
export function eConvocato(evento: Pick<Evento, "convocati">, giocatoreId: string): boolean {
|
||||
return evento.convocati.length === 0 || evento.convocati.includes(giocatoreId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Chi vede un evento: i convocati; se `convocati` è vuoto, tutta la rosa. Chi gestisce gli
|
||||
* eventi (admin e allenatori) li vede sempre, convocato o no.
|
||||
@@ -99,8 +104,9 @@ export function eventoVisibile(
|
||||
giocatoreId: string | null,
|
||||
vedeTutto: boolean,
|
||||
): boolean {
|
||||
if (vedeTutto || evento.convocati.length === 0) return true;
|
||||
return giocatoreId !== null && evento.convocati.includes(giocatoreId);
|
||||
if (vedeTutto) return true;
|
||||
if (evento.convocati.length === 0) return true;
|
||||
return giocatoreId !== null && eConvocato(evento, giocatoreId);
|
||||
}
|
||||
|
||||
export function useEvento(id: string) {
|
||||
@@ -211,6 +217,11 @@ export function compleanniEventi(
|
||||
|
||||
/** Rosa convocata per un evento: se non specificata vale tutta la rosa. */
|
||||
export function convocatiEvento(evento: Evento | null, rosa: Giocatore[]) {
|
||||
if (!evento || evento.convocati.length === 0) return rosa;
|
||||
return rosa.filter((g) => evento.convocati.includes(g.id));
|
||||
return rosaConvocata(rosa, evento?.convocati ?? []);
|
||||
}
|
||||
|
||||
/** Restringe una rosa ai convocati indicati: elenco vuoto = tutta la rosa. */
|
||||
export function rosaConvocata<T extends { id: string }>(rosa: T[], convocati: string[]): T[] {
|
||||
if (convocati.length === 0) return rosa;
|
||||
return rosa.filter((g) => convocati.includes(g.id));
|
||||
}
|
||||
Reference in new issue
Block a user