From a8ffc38ca8b7c05bbe363c50cd368b1d836a8e0e Mon Sep 17 00:00:00 2001 From: spark Date: Fri, 6 Nov 2026 22:00:30 +0000 Subject: [PATCH] feat(squads): show each athlete face in the squad panel The list did not say who already has a face, or what that face looks like. --- apps/api/src/sports/service.ts | 23 ++++++++++++++-- apps/app/src/i18n.ts | 4 +++ apps/app/src/library/Squads.test.tsx | 15 +++++++++-- apps/app/src/library/Squads.tsx | 40 +++++++++++++++++++++++++++- packages/sdk/src/types.ts | 4 +++ 5 files changed, 81 insertions(+), 5 deletions(-) diff --git a/apps/api/src/sports/service.ts b/apps/api/src/sports/service.ts index 9317f17..8de08bc 100644 --- a/apps/api/src/sports/service.ts +++ b/apps/api/src/sports/service.ts @@ -1388,11 +1388,15 @@ export class SportsService { const season = event.fixture?.season ?? seasonOf(event.startsAt); const players = await this.squad(team.id, season); const personOf = await this.peopleOf(event.organizationId, players); + const faceOf = await this.facesOf([...personOf.values()]); sides.push({ side, team: { id: team.id, name: team.name, abbreviation: team.abbreviation, logoUrl: team.logoUrl }, players: players.map((p) => { - const tally = counts(personOf.get(p.id) ?? null); + const personId = personOf.get(p.id) ?? null; + const tally = counts(personId); + const enrolled = personId ? faceOf.get(personId) ?? null : null; + const official = p.photoUrl && /^https?:\/\//i.test(p.photoUrl) ? p.photoUrl : null; return { id: p.id, number: p.number, @@ -1400,7 +1404,9 @@ export class SportsService { fullName: p.fullName, position: p.position, hasPhoto: !!p.photoUrl, - personId: personOf.get(p.id) ?? null, + faceUrl: enrolled ?? official, + hasFace: !!enrolled, + personId, photos: { confirmed: tally.confirmed, likely: tally.likely }, photoIds: tally.photoIds, }; @@ -1765,6 +1771,19 @@ export class SportsService { return linked?.season ?? null; } + /** Signed URL of each person's enrolled face. People without a reference photo are absent. */ + private async facesOf(personIds: string[]): Promise> { + const ids = [...new Set(personIds)]; + const out = new Map(); + if (!ids.length) return out; + const people = await this.deps.db.person.findMany({ + where: { id: { in: ids }, referenceKey: { not: null } }, + select: { id: true }, + }); + for (const person of people) out.set(person.id, this.deps.storage.personUrl(person.id)); + return out; + } + /** Which person is each squad row: the row itself, or the same human at the club they play for now. */ private async peopleOf(orgId: string, players: SportsPlayer[]): Promise> { const out = new Map(); diff --git a/apps/app/src/i18n.ts b/apps/app/src/i18n.ts index 5d1dc60..3058c52 100644 --- a/apps/app/src/i18n.ts +++ b/apps/app/src/i18n.ts @@ -846,6 +846,10 @@ export const t = { never: "ainda não lido", addFpf: "Seguir competição FPF (link do resultados.fpf.pt)", add: "Adicionar", + showFaces: "Caras", + faceKnown: "Cara registada", + faceSquadOnly: "Foto do plantel, ainda sem cara registada", + faceNone: "Sem cara", squadsSync: "Atualizar pessoas a partir dos plantéis", squadsSynced: "Pessoas atualizadas", }, diff --git a/apps/app/src/library/Squads.test.tsx b/apps/app/src/library/Squads.test.tsx index 6f0c684..623bec9 100644 --- a/apps/app/src/library/Squads.test.tsx +++ b/apps/app/src/library/Squads.test.tsx @@ -12,7 +12,7 @@ const squads: EventSquads = { side: "home", team: { id: "t1", name: "ÁGUAS SANTAS MILANEZA", abbreviation: "ASM", logoUrl: null }, players: [ - { id: "pl1", number: "5", name: "Miguel Baptista", fullName: null, position: null, hasPhoto: false, personId: "pe1", photos: { confirmed: 0, likely: 2 }, photoIds: ["a", "b"] }, + { id: "pl1", number: "5", name: "Miguel Baptista", fullName: null, position: null, hasPhoto: true, faceUrl: "/v1/files/persons/pe1/reference", hasFace: true, personId: "pe1", photos: { confirmed: 0, likely: 2 }, photoIds: ["a", "b"] }, { id: "pl2", number: "7", name: "Gabriel", fullName: null, position: null, hasPhoto: false, personId: null, photos: { confirmed: 0, likely: 0 }, photoIds: [] }, ], }, @@ -32,7 +32,7 @@ function Harness() { return ( <> path } as unknown as ApiClient} event={{ id: "e1", homeTeamId: "t1", awayTeamId: "t2" } as EventSummary} canEdit={false} onSaved={() => {}} @@ -59,4 +59,15 @@ describe("squad panel", () => { await waitFor(() => expect(screen.getByTestId("picked").textContent).toBe("b+c")); expect(miguel.getAttribute("aria-pressed")).toBe("false"); }); + + it("shows each athlete's face only when asked", async () => { + window.localStorage.clear(); + render(); + fireEvent.click(screen.getByRole("button", { name: "Plantéis" })); + await screen.findByRole("button", { name: /Miguel Baptista/ }); + expect(document.querySelector("img")).toBeNull(); + fireEvent.click(screen.getByRole("button", { name: "Caras" })); + expect(document.querySelector("img")?.getAttribute("src")).toContain("/v1/files/persons/pe1/reference"); + expect(document.querySelectorAll("span[title$='Sem cara']").length).toBe(2); + }); }); diff --git a/apps/app/src/library/Squads.tsx b/apps/app/src/library/Squads.tsx index a7c91f2..c2e1791 100644 --- a/apps/app/src/library/Squads.tsx +++ b/apps/app/src/library/Squads.tsx @@ -1,9 +1,12 @@ import { ApiError, type ApiClient, type EventSquads, type EventSummary } from "@photoreport/sdk"; import { useEffect, useState } from "react"; import { t } from "../i18n.js"; +import { prefs } from "../platform.js"; import { FixturePicker } from "./EventForm.js"; import { type PlayerPick, picksFrom } from "./squadFilter.js"; +const FACES_PREF = "squad-faces"; + /** * The open event's squads (from the federations): who is who by number, and whether each player is already a person * of the organisation (faces and jersey numbers name people). An older event can be linked to its match here. @@ -11,6 +14,7 @@ import { type PlayerPick, picksFrom } from "./squadFilter.js"; */ export function SquadsButton({ api, event, canEdit, onSaved, facesTick = 0, selectedIds = [], onPlayers }: { api: ApiClient; event: EventSummary; canEdit: boolean; onSaved: (e: EventSummary) => void; facesTick?: number; selectedIds?: readonly string[]; onPlayers?: (picks: PlayerPick[]) => void }) { const [open, setOpen] = useState(false); + const [showFaces, setShowFaces] = useState(() => prefs.get(FACES_PREF) === "1"); const [squads, setSquads] = useState(null); const [status, setStatus] = useState(null); const [busy, setBusy] = useState(false); @@ -86,6 +90,20 @@ export function SquadsButton({ api, event, canEdit, onSaved, facesTick = 0, sele ) ) : (
+
+ +
{squads?.sides.map((s) => (

{s.team.name}

@@ -100,8 +118,9 @@ export function SquadsButton({ api, event, canEdit, onSaved, facesTick = 0, sele aria-pressed={on} title={p.personId ? t.sports.photosHelp(p.photos?.confirmed ?? 0, p.photos?.likely ?? 0) : t.sports.notPerson} onClick={() => toggle(p.id)} - className={`flex w-full gap-2 px-1 py-0.5 text-left ${on ? "bg-cell-on" : "hover:bg-cell"} disabled:cursor-default disabled:hover:bg-transparent`} + className={`flex w-full items-center gap-2 px-1 py-0.5 text-left ${on ? "bg-cell-on" : "hover:bg-cell"} disabled:cursor-default disabled:hover:bg-transparent`} > + {showFaces && api.absolute(path)} />} {p.number ?? "–"} {p.name} @@ -140,3 +159,22 @@ export function SquadsButton({ api, event, canEdit, onSaved, facesTick = 0, sele
); } + +/** The enrolled face, the squad photo, or an empty slot when this athlete has neither. */ +function FaceThumb(props: { name: string; url?: string | null; hasFace: boolean; absolute: (path: string) => string }) { + const [failed, setFailed] = useState(false); + if (!props.url || failed) { + return ; + } + const title = props.hasFace ? t.sports.faceKnown : t.sports.faceSquadOnly; + return ( + setFailed(true)} + className={`h-8 w-8 shrink-0 object-cover ${props.hasFace ? "outline outline-1 outline-offset-[-1px] outline-white" : "opacity-70"}`} + /> + ); +} diff --git a/packages/sdk/src/types.ts b/packages/sdk/src/types.ts index 6c19a5e..7050927 100644 --- a/packages/sdk/src/types.ts +++ b/packages/sdk/src/types.ts @@ -219,6 +219,10 @@ export interface EventSquads { fullName: string | null; position: string | null; hasPhoto: boolean; + /** The enrolled face, or the squad photo when there is no face yet. */ + faceUrl?: string | null; + /** An enrolled reference face, the one recognition uses. */ + hasFace?: boolean; personId: string | null; /** Photos of them in this event: confirmed, and taken for them by the faces (70% or more) not confirmed yet. */ photos?: { confirmed: number; likely: number }; -- 2.47.3