diff --git a/src/lib/components/modals/statistics/StatisticsModal.svelte b/src/lib/components/modals/statistics/StatisticsModal.svelte index 80b8604..f677f5c 100644 --- a/src/lib/components/modals/statistics/StatisticsModal.svelte +++ b/src/lib/components/modals/statistics/StatisticsModal.svelte @@ -20,13 +20,16 @@ flights: FlightData[]; } = $props(); - let flightCount = flights.length; - let totalDistance = flights.reduce((acc, curr) => (acc += curr.distance), 0); - let totalDuration = flights.reduce( - (acc, curr) => (acc += curr.duration ?? 0), - 0, + let flightCount = $derived.by(() => flights.length); + let totalDistance = $derived.by(() => + flights.reduce((acc, curr) => (acc += curr.distance ?? 0), 0), + ); + let totalDuration = $derived.by(() => + flights.reduce((acc, curr) => (acc += curr.duration ?? 0), 0), + ); + let airports = $derived.by( + () => new Set(flights.flatMap((f) => [f.from.name, f.to.name])).size, ); - let airports = new Set(flights.flatMap((f) => [f.from.name, f.to.name])).size;