Skip to content

Commit

Permalink
Some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
paultsimura committed Sep 6, 2023
1 parent 0b9596d commit af2c13f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/components/ConfirmedRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}

Expand Down
10 changes: 4 additions & 6 deletions src/components/DistanceRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit af2c13f

Please sign in to comment.