Refactor GroupTable component to use $props for event, group, and rows; simplify teamPoints calculation with derived state
All checks were successful
SteamWarCI Build successful

This commit is contained in:
2025-06-29 19:41:43 +02:00
parent 3c6d0f8528
commit 353a415990

View File

@ -24,35 +24,22 @@
import type { ExtendedEvent } from "@type/event.ts"; import type { ExtendedEvent } from "@type/event.ts";
import "@styles/table.css"; import "@styles/table.css";
export let event: ExtendedEvent; let {
export let group: number; event,
export let rows: number = 1; group,
rows = 1,
}: {
event: ExtendedEvent;
group: number;
rows?: number;
} = $props();
$: teamPoints = event.teams let teamPoints = $derived(
.map((team) => { Object.entries(event.groups[group]?.points ?? {}).map(([teamId, points]) => ({
let fights = event.fights.filter((fight) => fight.blueTeam.id === team.id || fight.redTeam.id === team.id); team: event.teams.find((t) => t.id === Number(teamId))!!,
points: points,
if (group !== undefined) { }))
fights = fights.filter((fight) => fight.group?.id === group); );
}
const points = fights.reduce((acc, fight) => {
if (fight.ergebnis === 1 && fight.blueTeam.id === team.id) {
return acc + (fight.group?.pointsPerWin ?? 3);
} else if (fight.ergebnis === 2 && fight.redTeam.id === team.id) {
return acc + (fight.group?.pointsPerWin ?? 3);
} else if (fight.ergebnis === 3) {
return acc + (fight.group?.pointsPerDraw ?? 1);
} else {
return acc + (fight.group?.pointsPerLoss ?? 0);
}
}, 0);
return {
team,
points,
};
})
.sort((a, b) => b.points - a.points);
</script> </script>
<div class="p-3 bg-gray-200 dark:bg-neutral-800 rounded-2xl w-3/4 mx-auto"> <div class="p-3 bg-gray-200 dark:bg-neutral-800 rounded-2xl w-3/4 mx-auto">