Skip to content

Commit

Permalink
Fix lint errors, replace MapView import
Browse files Browse the repository at this point in the history
  • Loading branch information
gegham-khachatryan committed Sep 1, 2023
1 parent c2e3291 commit 299d030
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
30 changes: 19 additions & 11 deletions src/components/ConfirmedRoute.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {useEffect} from 'react';
import PropTypes from 'prop-types';
import {View} from 'react-native';
import MapView from 'react-native-x-maps';

import {withOnyx} from 'react-native-onyx';
import lodashGet from 'lodash/get';
import _ from 'underscore';
Expand All @@ -15,18 +15,27 @@ import transactionPropTypes from './transactionPropTypes';
import BlockingView from './BlockingViews/BlockingView';
import useNetwork from '../hooks/useNetwork';
import useLocalize from '../hooks/useLocalize';
import MapView from './MapView';

const propTypes = {
/** Transaction that stores the distance request data */
transaction: transactionPropTypes,

/** Token needed to render the map */
mapboxToken: PropTypes.string,
/** Data about Mapbox token for calling Mapbox API */
mapboxAccessToken: PropTypes.shape({
/** Temporary token for Mapbox API */
token: PropTypes.string,

/** Time when the token will expire in ISO 8601 */
expiration: PropTypes.string,
}),
};

const defaultProps = {
transaction: {},
mapboxToken: '',
mapboxAccessToken: {
token: '',
},
};

const getWaypointMarkers = (waypoints) => {
Expand All @@ -49,6 +58,7 @@ const getWaypointMarkers = (waypoints) => {
}

return {
id: `${waypoint.lng},${waypoint.lat},${index}`,
coordinate: [waypoint.lng, waypoint.lat],
markerComponent: () => (
<MarkerComponent
Expand All @@ -63,7 +73,7 @@ const getWaypointMarkers = (waypoints) => {
);
};

function ConfirmedRoute({mapboxToken, transaction}) {
function ConfirmedRoute({mapboxAccessToken, transaction}) {
const {isOffline} = useNetwork();
const {translate} = useLocalize();
const {route0: route} = transaction.routes || {};
Expand All @@ -78,16 +88,15 @@ function ConfirmedRoute({mapboxToken, transaction}) {

return (
<>
{!isOffline && mapboxToken ? (
{!isOffline && Boolean(mapboxAccessToken.token) ? (
<MapView
accessToken={mapboxToken}
accessToken={mapboxAccessToken.token}
mapPadding={CONST.MAP_PADDING}
pitchEnabled={false}
directionCoordinates={coordinates}
directionStyle={styles.mapDirection}
style={styles.mapView}
waypoints={waypointMarkers}
styleURL={CONST.MAPBOX_STYLE_URL}
styleURL={CONST.MAPBOX.STYLE_URL}
/>
) : (
<View style={[styles.mapPendingView]}>
Expand All @@ -107,9 +116,8 @@ export default withOnyx({
transaction: {
key: ({transactionID}) => `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`,
},
mapboxToken: {
mapboxAccessToken: {
key: ONYXKEYS.MAPBOX_ACCESS_TOKEN,
selector: (mapboxAccessToken) => mapboxAccessToken && mapboxAccessToken.token,
},
})(ConfirmedRoute);

Expand Down
7 changes: 6 additions & 1 deletion src/components/DistanceRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ import * as Expensicons from './Icon/Expensicons';
import BlockingView from './BlockingViews/BlockingView';
import DotIndicatorMessage from './DotIndicatorMessage';
import MenuItemWithTopDescription from './MenuItemWithTopDescription';
import {iouPropTypes} from '../pages/iou/propTypes';
import reportPropTypes from '../pages/reportPropTypes';
import * as IOU from '../libs/actions/IOU';

const MAX_WAYPOINTS = 25;
const MAX_WAYPOINTS_TO_DISPLAY = 4;
Expand Down Expand Up @@ -65,7 +68,9 @@ const defaultProps = {
iouType: '',
report: {},
transaction: {},
mapboxAccessToken: {},
mapboxAccessToken: {
token: '',
},
};

function DistanceRequest({iou, iouType, report, transaction, mapboxAccessToken}) {
Expand Down

0 comments on commit 299d030

Please sign in to comment.