From bc98fda9d116b9e75edd37b575c9dc05b99f2382 Mon Sep 17 00:00:00 2001 From: Inga Date: Mon, 20 Nov 2023 13:00:53 +0000 Subject: [PATCH] minor simplification --- src/routePlanner/total.tsx | 5 +---- src/shared/routes.ts | 9 ++++++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/routePlanner/total.tsx b/src/routePlanner/total.tsx index 880c145..2ab4bb3 100644 --- a/src/routePlanner/total.tsx +++ b/src/routePlanner/total.tsx @@ -7,10 +7,7 @@ type TotalProps = { }; export const TotalComponent = ({ markers }: TotalProps) => { - const routeLength = useMemo( - () => getRouteLength(markers.map(({ coordinates }) => coordinates)), - [markers], - ); + const routeLength = useMemo(() => getRouteLength(markers), [markers]); return <>{`Total route length: ${routeLength.toFixed(0)}m`}; }; diff --git a/src/shared/routes.ts b/src/shared/routes.ts index 3b7a6f2..359ffc8 100644 --- a/src/shared/routes.ts +++ b/src/shared/routes.ts @@ -1,7 +1,7 @@ import haversineDistance from 'haversine-distance'; -import { Coordinates } from './types'; +import { Waypoint } from './types'; -export const getRouteLength = (points: Coordinates[]) => { +export const getRouteLength = (points: Waypoint[]) => { let result = 0; for (let i = 0; i < points.length; i++) { const currentPoint = points[i]; @@ -9,7 +9,10 @@ export const getRouteLength = (points: Coordinates[]) => { if (!currentPoint || !previousPoint) { continue; } - result += haversineDistance(previousPoint, currentPoint); + result += haversineDistance( + previousPoint.coordinates, + currentPoint.coordinates, + ); } return result;