|
@@ -4,7 +4,7 @@ import MapView, { Geojson, Marker, UrlTile } from 'react-native-maps';
|
|
|
import * as turf from '@turf/turf';
|
|
|
import * as FileSystem from 'expo-file-system';
|
|
|
import * as Location from 'expo-location';
|
|
|
-import { getOnlineStatus, storage, StoreType } from '../../../storage';
|
|
|
+import { storage, StoreType } from '../../../storage';
|
|
|
|
|
|
import MenuIcon from '../../../../assets/icons/menu.svg';
|
|
|
import SearchIcon from '../../../../assets/icons/search.svg';
|
|
@@ -15,7 +15,6 @@ import CloseSvg from '../../../../assets/icons/close.svg';
|
|
|
import regions from '../../../../assets/geojson/nm2022.json';
|
|
|
import dareRegions from '../../../../assets/geojson/mqp.json';
|
|
|
|
|
|
-import NetInfo from '@react-native-community/netinfo';
|
|
|
import { getFirstDatabase, getSecondDatabase, refreshDatabases } from '../../../db';
|
|
|
import { LocationPopup, RegionPopup, WarningModal } from '../../../components';
|
|
|
|
|
@@ -43,6 +42,7 @@ import {
|
|
|
Series
|
|
|
} from '../../../types/map';
|
|
|
import { MAP_HOST } from 'src/constants';
|
|
|
+import { useConnection } from 'src/contexts/ConnectionContext';
|
|
|
|
|
|
const tilesBaseURL = `${MAP_HOST}/tiles_osm`;
|
|
|
const localTileDir = `${FileSystem.cacheDirectory}tiles/background`;
|
|
@@ -60,7 +60,7 @@ const AnimatedMarker = Animated.createAnimatedComponent(Marker);
|
|
|
const MapScreen: React.FC<MapScreenProps> = ({ navigation }) => {
|
|
|
const userId = storage.get('uid', StoreType.STRING);
|
|
|
const token = storage.get('token', StoreType.STRING);
|
|
|
- const isOnline = getOnlineStatus();
|
|
|
+ const netInfo = useConnection();
|
|
|
|
|
|
const { mutateAsync } = fetchSeriesData();
|
|
|
|
|
@@ -87,6 +87,14 @@ const MapScreen: React.FC<MapScreenProps> = ({ navigation }) => {
|
|
|
const currentTokenRef = useRef(0);
|
|
|
const strokeWidthAnim = useRef(new Animated.Value(2)).current;
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
+ if (netInfo?.isInternetReachable) {
|
|
|
+ setIsConnected(true);
|
|
|
+ } else {
|
|
|
+ setIsConnected(false);
|
|
|
+ }
|
|
|
+ }, [netInfo?.isInternetReachable]);
|
|
|
+
|
|
|
useEffect(() => {
|
|
|
Animated.loop(
|
|
|
Animated.sequence([
|
|
@@ -118,14 +126,6 @@ const MapScreen: React.FC<MapScreenProps> = ({ navigation }) => {
|
|
|
});
|
|
|
}, [regionPopupVisible, navigation]);
|
|
|
|
|
|
- useEffect(() => {
|
|
|
- const unsubscribe = NetInfo.addEventListener((state) => {
|
|
|
- setIsConnected(isOnline as boolean);
|
|
|
- });
|
|
|
-
|
|
|
- return () => unsubscribe();
|
|
|
- }, [isOnline]);
|
|
|
-
|
|
|
useEffect(() => {
|
|
|
(async () => {
|
|
|
let { status } = await Location.getForegroundPermissionsAsync();
|
|
@@ -154,7 +154,7 @@ const MapScreen: React.FC<MapScreenProps> = ({ navigation }) => {
|
|
|
latitudeDelta: any;
|
|
|
longitudeDelta?: any;
|
|
|
}) => {
|
|
|
- if (!isOnline) return;
|
|
|
+ if (!isConnected) return;
|
|
|
const currentZoom = Math.log2(360 / visibleMapArea.latitudeDelta);
|
|
|
|
|
|
if (cancelTokenRef.current) {
|
|
@@ -188,7 +188,7 @@ const MapScreen: React.FC<MapScreenProps> = ({ navigation }) => {
|
|
|
(region: { properties: { id: any } }) => region.properties.id
|
|
|
);
|
|
|
|
|
|
- isOnline && await mutateAsync(
|
|
|
+ isConnected && await mutateAsync(
|
|
|
{ regions: JSON.stringify(regionIds), token: String(token) },
|
|
|
{
|
|
|
onSuccess: (data) => {
|