Skip to content

Commit

Permalink
fix: statistics not updating when new flights are added
Browse files Browse the repository at this point in the history
  • Loading branch information
johanohly committed Sep 13, 2024
1 parent cab76b5 commit 8894ffd
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/lib/components/modals/statistics/StatisticsModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
</script>

<Modal bind:open classes="h-full overflow-y-auto !rounded-none" dialogOnly>
Expand Down

0 comments on commit 8894ffd

Please sign in to comment.