|
@@ -1,10 +1,10 @@
|
|
|
-import { View, Platform, TouchableOpacity, Text, Linking, Animated } from 'react-native';
|
|
|
-import React, { useEffect, useState, useRef, useMemo } from 'react';
|
|
|
-import MapView, { UrlTile, Geojson, Marker } from 'react-native-maps';
|
|
|
+import { Animated, Linking, Platform, Text, TouchableOpacity, View } from 'react-native';
|
|
|
+import React, { useEffect, useMemo, useRef, useState } from 'react';
|
|
|
+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 { storageGet } from '../../../storage';
|
|
|
+import { storage, StoreType } from '../../../storage';
|
|
|
|
|
|
import MenuIcon from '../../../../assets/icons/menu.svg';
|
|
|
import SearchIcon from '../../../../assets/icons/search.svg';
|
|
@@ -17,31 +17,32 @@ import dareRegions from '../../../../assets/geojson/mqp.json';
|
|
|
|
|
|
import NetInfo from '@react-native-community/netinfo';
|
|
|
import { getFirstDatabase, getSecondDatabase } from '../../../db';
|
|
|
-import { RegionPopup, LocationPopup } from '../../../components';
|
|
|
+import { LocationPopup, RegionPopup } from '../../../components';
|
|
|
|
|
|
import { styles } from './style';
|
|
|
import {
|
|
|
- findRegionInDataset,
|
|
|
calculateMapRegion,
|
|
|
clusterMarkers,
|
|
|
filterCandidates,
|
|
|
- processMarkerData,
|
|
|
+ filterCandidatesMarkers,
|
|
|
+ findRegionInDataset,
|
|
|
processIconUrl,
|
|
|
- filterCandidatesMarkers
|
|
|
+ processMarkerData
|
|
|
} from '../../../utils/mapHelpers';
|
|
|
import { getData } from '../../../modules/map/regionData';
|
|
|
import { fetchSeriesData } from '../../../modules/map/series/queries/use-post-get-series';
|
|
|
import MarkerItem from './MarkerItem';
|
|
|
import ClusterItem from './ClusterItem';
|
|
|
import {
|
|
|
- Region,
|
|
|
- Series,
|
|
|
- ItemSeries,
|
|
|
- MarkerData,
|
|
|
ClusterData,
|
|
|
+ FeatureCollection,
|
|
|
+ ItemSeries,
|
|
|
MapScreenProps,
|
|
|
- FeatureCollection
|
|
|
+ MarkerData,
|
|
|
+ Region,
|
|
|
+ Series
|
|
|
} from '../../../types/map';
|
|
|
+
|
|
|
const MAP_HOST = 'https://maps.nomadmania.eu';
|
|
|
|
|
|
const tilesBaseURL = `${MAP_HOST}/tiles_osm`;
|
|
@@ -58,8 +59,8 @@ const localDareDir = `${FileSystem.cacheDirectory}tiles/regions_mqp`;
|
|
|
const AnimatedMarker = Animated.createAnimatedComponent(Marker);
|
|
|
|
|
|
const MapScreen: React.FC<MapScreenProps> = ({ navigation }) => {
|
|
|
- const [userId, setUserId] = useState<string | null>('');
|
|
|
- const [token, setToken] = useState<string | null>('');
|
|
|
+ const userId = storage.get('uid', StoreType.STRING);
|
|
|
+ const token = storage.get('token', StoreType.STRING);
|
|
|
const visitedTiles = `${MAP_HOST}/tiles_nm/user_visited/${userId}`;
|
|
|
|
|
|
const mapRef = useRef<MapView>(null);
|
|
@@ -82,18 +83,6 @@ const MapScreen: React.FC<MapScreenProps> = ({ navigation }) => {
|
|
|
const currentTokenRef = useRef(0);
|
|
|
const strokeWidthAnim = useRef(new Animated.Value(2)).current;
|
|
|
|
|
|
- useEffect(() => {
|
|
|
- const fetchData = async () => {
|
|
|
- const fetchedUserId = await storageGet('uid');
|
|
|
- const fetchedToken = await storageGet('token');
|
|
|
-
|
|
|
- setUserId(fetchedUserId);
|
|
|
- setToken(fetchedToken);
|
|
|
- };
|
|
|
-
|
|
|
- fetchData();
|
|
|
- }, []);
|
|
|
-
|
|
|
useEffect(() => {
|
|
|
Animated.loop(
|
|
|
Animated.sequence([
|
|
@@ -193,7 +182,7 @@ const MapScreen: React.FC<MapScreenProps> = ({ navigation }) => {
|
|
|
const regionIds = regionsFound.map(
|
|
|
(region: { properties: { id: any } }) => region.properties.id
|
|
|
);
|
|
|
- const candidatesMarkers = await fetchSeriesData(token, JSON.stringify(regionIds));
|
|
|
+ const candidatesMarkers = await fetchSeriesData(String(token), JSON.stringify(regionIds));
|
|
|
|
|
|
if (thisToken !== currentTokenRef.current) return;
|
|
|
|
|
@@ -325,7 +314,7 @@ const MapScreen: React.FC<MapScreenProps> = ({ navigation }) => {
|
|
|
mapRef.current?.animateToRegion(region, 1000);
|
|
|
|
|
|
if (tableName === 'regions') {
|
|
|
- const seriesData = await fetchSeriesData(token, JSON.stringify([id]));
|
|
|
+ const seriesData = await fetchSeriesData(String(token), JSON.stringify([id]));
|
|
|
setSeries(seriesData.series);
|
|
|
const allMarkers = seriesData.items.map(processMarkerData);
|
|
|
setProcessedMarkers(allMarkers);
|