From af2c13f809355acbdb8b0b622926a6c280b3a134 Mon Sep 17 00:00:00 2001 From: Pavlo Tsimura Date: Wed, 6 Sep 2023 18:04:15 +0200 Subject: [PATCH] Some refactoring --- src/components/ConfirmedRoute.js | 4 ++-- src/components/DistanceRequest.js | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/components/ConfirmedRoute.js b/src/components/ConfirmedRoute.js index 31b05d03378c..c9b418849423 100644 --- a/src/components/ConfirmedRoute.js +++ b/src/components/ConfirmedRoute.js @@ -4,7 +4,7 @@ import {View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; import lodashGet from 'lodash/get'; -import lodashIsNil from "lodash/isNil"; +import lodashIsNil from 'lodash/isNil'; import _ from 'underscore'; import ONYXKEYS from '../ONYXKEYS'; import CONST from '../CONST'; @@ -44,7 +44,7 @@ const getWaypointMarkers = (waypoints) => { const lastWaypointIndex = numberOfWaypoints - 1; return _.filter( _.map(waypoints, (waypoint, key) => { - if (!waypoint || lodashIsNil(waypoint.lng) || lodashIsNil(waypoint.lat)) { + if (!waypoint || lodashIsNil(lodashGet(waypoint, 'lng')) || lodashIsNil(lodashGet(waypoint, 'lat'))) { return; } diff --git a/src/components/DistanceRequest.js b/src/components/DistanceRequest.js index 8b54327aea04..5b2116b784f7 100644 --- a/src/components/DistanceRequest.js +++ b/src/components/DistanceRequest.js @@ -2,8 +2,7 @@ import React, {useEffect, useMemo, useState, useRef} from 'react'; import {ScrollView, View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; import lodashGet from 'lodash/get'; -import lodashHas from 'lodash/has'; -import lodashIsNull from 'lodash/isNull'; +import lodashIsNil from 'lodash/isNil'; import PropTypes from 'prop-types'; import _ from 'underscore'; @@ -90,18 +89,17 @@ function DistanceRequest({iou, iouType, report, transaction, mapboxAccessToken}) const lastWaypointIndex = numberOfWaypoints - 1; const isLoadingRoute = lodashGet(transaction, 'comment.isLoading', false); - const hasRouteError = !lodashIsNull(lodashGet(transaction, 'errorFields.route')); + const hasRouteError = !lodashIsNil(lodashGet(transaction, 'errorFields.route')); const haveWaypointsChanged = !_.isEqual(previousWaypoints, waypoints); const doesRouteExist = TransactionUtils.doesRouteExist(transaction) const validatedWaypoints = TransactionUtils.getValidWaypoints(waypoints); - const hasMultipleValidWaypoints = _.size(validatedWaypoints) > 1; const isRouteAbsentWithNoErrors = !hasRouteError && !doesRouteExist; - const shouldFetchRoute = (haveWaypointsChanged || isRouteAbsentWithNoErrors) && !isLoadingRoute && hasMultipleValidWaypoints; + const shouldFetchRoute = (haveWaypointsChanged || isRouteAbsentWithNoErrors) && !isLoadingRoute && _.size(validatedWaypoints) > 1; const waypointMarkers = useMemo( () => _.filter( _.map(waypoints, (waypoint, key) => { - if (!waypoint || !lodashHas(waypoint, 'lat') || !lodashHas(waypoint, 'lng') || lodashIsNull(waypoint.lat) || lodashIsNull(waypoint.lng)) { + if (!waypoint || lodashIsNil(lodashGet(waypoint, 'lng')) || lodashIsNil(lodashGet(waypoint, 'lat'))) { return; }