From ecb746cf287dd0fdc20154011957f73bd997e3d2 Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Fri, 8 Sep 2023 06:37:22 +0530 Subject: [PATCH 1/8] map loding when online --- src/components/DistanceRequest.js | 5 ++++- src/setup/platformSetup/index.website.js | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/components/DistanceRequest.js b/src/components/DistanceRequest.js index 966f700e25d4..43c6ea3a294e 100644 --- a/src/components/DistanceRequest.js +++ b/src/components/DistanceRequest.js @@ -154,9 +154,12 @@ function DistanceRequest({iou, iouType, report, transaction, mapboxAccessToken, const scrollContainerMaxHeight = variables.optionRowHeight * MAX_WAYPOINTS_TO_DISPLAY + halfMenuItemHeight; useEffect(() => { + if (isOffline || mapboxAccessToken.token) { + return; + } MapboxToken.init(); return MapboxToken.stop; - }, []); + }, [mapboxAccessToken.token, isOffline]); useEffect(() => { if (!iou.transactionID || !_.isEmpty(waypoints)) { diff --git a/src/setup/platformSetup/index.website.js b/src/setup/platformSetup/index.website.js index e859005c9abe..0b3a45b0b3ba 100644 --- a/src/setup/platformSetup/index.website.js +++ b/src/setup/platformSetup/index.website.js @@ -3,6 +3,10 @@ import {AppRegistry} from 'react-native'; // This is a polyfill for InternetExplorer to support the modern KeyboardEvent.key and KeyboardEvent.code instead of KeyboardEvent.keyCode import 'shim-keyboard-event-key'; +// load all chunk file map when online +import 'react-map-gl'; +import 'mapbox-gl/dist/mapbox-gl.css'; + import checkForUpdates from '../../libs/checkForUpdates'; import Config from '../../CONFIG'; import DateUtils from '../../libs/DateUtils'; From a2fe761450e346bd7f33d0dfdeafe03d7bc554bc Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Fri, 8 Sep 2023 07:39:15 +0530 Subject: [PATCH 2/8] load chunk on desktop --- src/setup/platformSetup/index.desktop.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/setup/platformSetup/index.desktop.js b/src/setup/platformSetup/index.desktop.js index a1585065e142..cf9e591935ce 100644 --- a/src/setup/platformSetup/index.desktop.js +++ b/src/setup/platformSetup/index.desktop.js @@ -4,6 +4,9 @@ import LocalNotification from '../../libs/Notification/LocalNotification'; import * as KeyboardShortcuts from '../../libs/actions/KeyboardShortcuts'; import DateUtils from '../../libs/DateUtils'; import ELECTRON_EVENTS from '../../../desktop/ELECTRON_EVENTS'; +// load all chunk file map when online +import 'react-map-gl'; +import 'mapbox-gl/dist/mapbox-gl.css'; export default function () { AppRegistry.runApplication(Config.APP_NAME, { From bd340bbaa81accd87eb88ad44f04f631389a7ae4 Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Tue, 12 Sep 2023 09:24:54 +0530 Subject: [PATCH 3/8] map view updated --- src/components/MapView/MapView.web.tsx | 1 + src/setup/platformSetup/index.desktop.js | 3 --- src/setup/platformSetup/index.website.js | 4 ---- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/components/MapView/MapView.web.tsx b/src/components/MapView/MapView.web.tsx index d1b26df8b00e..a95ed6aa9e47 100644 --- a/src/components/MapView/MapView.web.tsx +++ b/src/components/MapView/MapView.web.tsx @@ -66,6 +66,7 @@ const MapView = forwardRef( > Date: Mon, 18 Sep 2023 07:32:52 +0530 Subject: [PATCH 4/8] update module import --- src/components/MapView/MapView.web.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/MapView/MapView.web.tsx b/src/components/MapView/MapView.web.tsx index a95ed6aa9e47..fc2c97bd8e80 100644 --- a/src/components/MapView/MapView.web.tsx +++ b/src/components/MapView/MapView.web.tsx @@ -6,6 +6,7 @@ import React, {forwardRef, useCallback, useEffect, useImperativeHandle, useState} from 'react'; import {View} from 'react-native'; import Map, {MapRef, Marker} from 'react-map-gl'; +import mapboxgl from 'mapbox-gl'; import responder from './responder'; import utils from './utils'; @@ -66,7 +67,7 @@ const MapView = forwardRef( > Date: Mon, 18 Sep 2023 22:31:34 +0530 Subject: [PATCH 5/8] move logic to maptoken --- src/components/DistanceRequest.js | 5 +---- src/libs/actions/MapboxToken.js | 15 +++++++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/components/DistanceRequest.js b/src/components/DistanceRequest.js index 43c6ea3a294e..966f700e25d4 100644 --- a/src/components/DistanceRequest.js +++ b/src/components/DistanceRequest.js @@ -154,12 +154,9 @@ function DistanceRequest({iou, iouType, report, transaction, mapboxAccessToken, const scrollContainerMaxHeight = variables.optionRowHeight * MAX_WAYPOINTS_TO_DISPLAY + halfMenuItemHeight; useEffect(() => { - if (isOffline || mapboxAccessToken.token) { - return; - } MapboxToken.init(); return MapboxToken.stop; - }, [mapboxAccessToken.token, isOffline]); + }, []); useEffect(() => { if (!iou.transactionID || !_.isEmpty(waypoints)) { diff --git a/src/libs/actions/MapboxToken.js b/src/libs/actions/MapboxToken.js index 2ce56eb1a11e..fc6f351996e4 100644 --- a/src/libs/actions/MapboxToken.js +++ b/src/libs/actions/MapboxToken.js @@ -46,7 +46,7 @@ const hasTokenExpired = () => moment().isAfter(currentToken.expiration); const clearToken = () => { console.debug('[MapboxToken] Deleting the token stored in Onyx'); - + currentToken = null; // Use Onyx.set() to delete the key from Onyx, which will trigger a new token to be retrieved from the API. Onyx.set(ONYXKEYS.MAPBOX_ACCESS_TOKEN, null); }; @@ -126,9 +126,16 @@ const init = () => { callback: (val) => { // When the network reconnects, check if the token has expired. If it has, then clearing the token will // trigger the fetch of a new one - if (network && network.isOffline && val && !val.isOffline && !isCurrentlyFetchingToken && hasTokenExpired()) { - console.debug('[MapboxToken] Token is expired after network came online'); - clearToken(); + if (network && network.isOffline && val && !val.isOffline) { + if (_.isEmpty(currentToken)) { + console.debug('[MapboxToken] Token does not exist so fetching one'); + // eslint-disable-next-line rulesdir/no-multiple-api-calls + API.read('GetMapboxAccessToken'); + isCurrentlyFetchingToken = true; + } else if (!isCurrentlyFetchingToken && hasTokenExpired()) { + console.debug('[MapboxToken] Token is expired after network came online'); + clearToken(); + } } network = val; }, From 5b7f27e0f993e742b707107ea5fa47df29c6b8fc Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Tue, 19 Sep 2023 08:41:56 +0530 Subject: [PATCH 6/8] remove unwanted code --- src/libs/actions/MapboxToken.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/actions/MapboxToken.js b/src/libs/actions/MapboxToken.js index fc6f351996e4..c0d7010b383c 100644 --- a/src/libs/actions/MapboxToken.js +++ b/src/libs/actions/MapboxToken.js @@ -46,7 +46,6 @@ const hasTokenExpired = () => moment().isAfter(currentToken.expiration); const clearToken = () => { console.debug('[MapboxToken] Deleting the token stored in Onyx'); - currentToken = null; // Use Onyx.set() to delete the key from Onyx, which will trigger a new token to be retrieved from the API. Onyx.set(ONYXKEYS.MAPBOX_ACCESS_TOKEN, null); }; From 6fb66ea8d871b92c93d7f5e23a6ebc2fc7889185 Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Tue, 19 Sep 2023 15:46:28 +0530 Subject: [PATCH 7/8] update function --- src/libs/actions/MapboxToken.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/libs/actions/MapboxToken.js b/src/libs/actions/MapboxToken.js index c0d7010b383c..0202488ed199 100644 --- a/src/libs/actions/MapboxToken.js +++ b/src/libs/actions/MapboxToken.js @@ -50,6 +50,12 @@ const clearToken = () => { Onyx.set(ONYXKEYS.MAPBOX_ACCESS_TOKEN, null); }; +const fetchToken = () => { + console.debug('[MapboxToken] Token does not exist so fetching one'); + API.read('GetMapboxAccessToken'); + isCurrentlyFetchingToken = true; +}; + const init = () => { if (connectionIDForToken) { console.debug('[MapboxToken] init() is already listening to Onyx so returning early'); @@ -82,9 +88,7 @@ const init = () => { // If the token is falsy or an empty object, the token needs to be retrieved from the API. // The API sets a token in Onyx with a 30 minute expiration. if (_.isEmpty(token)) { - console.debug('[MapboxToken] Token does not exist so fetching one'); - API.read('GetMapboxAccessToken'); - isCurrentlyFetchingToken = true; + fetchToken(); return; } @@ -127,10 +131,7 @@ const init = () => { // trigger the fetch of a new one if (network && network.isOffline && val && !val.isOffline) { if (_.isEmpty(currentToken)) { - console.debug('[MapboxToken] Token does not exist so fetching one'); - // eslint-disable-next-line rulesdir/no-multiple-api-calls - API.read('GetMapboxAccessToken'); - isCurrentlyFetchingToken = true; + fetchToken(); } else if (!isCurrentlyFetchingToken && hasTokenExpired()) { console.debug('[MapboxToken] Token is expired after network came online'); clearToken(); From 3ebb638f17e4b6ff0d7e25231eee1281f0d3b673 Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Tue, 26 Sep 2023 07:55:37 +0530 Subject: [PATCH 8/8] remvoe console --- src/libs/actions/MapboxToken.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/actions/MapboxToken.js b/src/libs/actions/MapboxToken.js index 0202488ed199..e5824ef0302d 100644 --- a/src/libs/actions/MapboxToken.js +++ b/src/libs/actions/MapboxToken.js @@ -51,7 +51,6 @@ const clearToken = () => { }; const fetchToken = () => { - console.debug('[MapboxToken] Token does not exist so fetching one'); API.read('GetMapboxAccessToken'); isCurrentlyFetchingToken = true; };