Browse Source

resolve conflicts

Viktoriia 9 months ago
parent
commit
95cfb4d629

+ 6 - 3
app.config.ts

@@ -22,7 +22,7 @@ export default ({ config }: ConfigContext): ExpoConfig => ({
   owner: 'nomadmaniaou',
   owner: 'nomadmaniaou',
   scheme: 'nm',
   scheme: 'nm',
   // Should be updated after every production release (deploy to AppStore/PlayMarket)
   // Should be updated after every production release (deploy to AppStore/PlayMarket)
-  version: '2.0.17',
+  version: '2.0.18',
   // Should be updated after every dependency change
   // Should be updated after every dependency change
   runtimeVersion: '1.5',
   runtimeVersion: '1.5',
   orientation: 'portrait',
   orientation: 'portrait',
@@ -69,9 +69,12 @@ export default ({ config }: ConfigContext): ExpoConfig => ({
         'Enable NomadMania.com to access your photo library to upload your profile picture. Any violence, excess of nudity, stolen picture, or scam is forbidden',
         'Enable NomadMania.com to access your photo library to upload your profile picture. Any violence, excess of nudity, stolen picture, or scam is forbidden',
       NSPushNotificationsDescription:
       NSPushNotificationsDescription:
         'This will allow NomadMania.com to send you notifications. Also you can disable it in app settings',
         'This will allow NomadMania.com to send you notifications. Also you can disable it in app settings',
+
       NSMicrophoneUsageDescription: "Nomadmania app needs access to the microphone to record audio.",
       NSMicrophoneUsageDescription: "Nomadmania app needs access to the microphone to record audio.",
       NSDocumentsFolderUsageDescription: "Nomadmania app needs access to the documents folder to select files.",
       NSDocumentsFolderUsageDescription: "Nomadmania app needs access to the documents folder to select files.",
-      NSCameraUsageDescription: "Nomadmania app needs access to the camera to record video."
+      NSCameraUsageDescription: "Nomadmania app needs access to the camera to record video.",
+      NSLocationWhenInUseUsageDescription:
+        'NomadMania app needs access to your location to show relevant data.',
     },
     },
     privacyManifests: {
     privacyManifests: {
       NSPrivacyAccessedAPITypes: [
       NSPrivacyAccessedAPITypes: [
@@ -103,7 +106,7 @@ export default ({ config }: ConfigContext): ExpoConfig => ({
       "RECORD_AUDIO",
       "RECORD_AUDIO",
       'MODIFY_AUDIO_SETTINGS'
       'MODIFY_AUDIO_SETTINGS'
     ],
     ],
-    versionCode: 70 // next version submitted to Google Play needs to be higher than that 2.0.17
+    versionCode: 71 // next version submitted to Google Play needs to be higher than that 2.0.18
   },
   },
   plugins: [
   plugins: [
     [
     [

+ 17 - 6
src/db/index.ts

@@ -113,17 +113,28 @@ export async function refreshDatabases() {
   }
   }
 }
 }
 
 
-export function getFirstDatabase() {
+export const loadDatabases = async () => {
+  if (!db1 || !db2 || !db3) {
+    await openDatabases();
+  }
+
+  return { db1, db2, db3 };
+};
+
+export const getFirstDatabase = async () => {
+  const { db1 } = await loadDatabases();
   return db1;
   return db1;
-}
+};
 
 
-export function getSecondDatabase() {
+export const getSecondDatabase = async () => {
+  const { db2 } = await loadDatabases();
   return db2;
   return db2;
-}
+};
 
 
-export function getCountriesDatabase() {
+export const getCountriesDatabase = async () => {
+  const { db3 } = await loadDatabases();
   return db3;
   return db3;
-}
+};
 
 
 const openDatabase = (dbName: string) => SQLite.openDatabase(dbName);
 const openDatabase = (dbName: string) => SQLite.openDatabase(dbName);
 
 

+ 25 - 7
src/screens/InAppScreens/MapScreen/index.tsx

@@ -66,6 +66,7 @@ import { useFocusEffect } from '@react-navigation/native';
 import { openstreetmapUrl } from 'src/constants/constants';
 import { openstreetmapUrl } from 'src/constants/constants';
 import { fetchCountryUserData } from '@api/countries';
 import { fetchCountryUserData } from '@api/countries';
 import EditModal from '../TravelsScreen/Components/EditSlowModal';
 import EditModal from '../TravelsScreen/Components/EditSlowModal';
+import { SQLiteDatabase } from 'expo-sqlite/legacy';
 
 
 const localTileDir = `${FileSystem.cacheDirectory}tiles/background`;
 const localTileDir = `${FileSystem.cacheDirectory}tiles/background`;
 const localGridDir = `${FileSystem.cacheDirectory}tiles/grid`;
 const localGridDir = `${FileSystem.cacheDirectory}tiles/grid`;
@@ -149,6 +150,23 @@ const MapScreen: React.FC<MapScreenProps> = ({ navigation, route }) => {
   const [userInfoData, setUserInfoData] = useState<any>(null);
   const [userInfoData, setUserInfoData] = useState<any>(null);
 
 
   const [initialRegion, setInitialRegion] = useState(INITIAL_REGION);
   const [initialRegion, setInitialRegion] = useState(INITIAL_REGION);
+  const [db1, setDb1] = useState<SQLiteDatabase | null>(null);
+  const [db2, setDb2] = useState<SQLiteDatabase | null>(null);
+  const [db3, setDb3] = useState<SQLiteDatabase | null>(null);
+
+  useEffect(() => {
+    const loadDatabases = async () => {
+      const firstDb = await getFirstDatabase();
+      const secondDb = await getSecondDatabase();
+      const countriesDb = await getCountriesDatabase();
+
+      setDb1(firstDb);
+      setDb2(secondDb);
+      setDb3(countriesDb);
+    };
+
+    loadDatabases();
+  }, []);
 
 
   useFocusEffect(
   useFocusEffect(
     useCallback(() => {
     useCallback(() => {
@@ -440,7 +458,7 @@ const MapScreen: React.FC<MapScreenProps> = ({ navigation, route }) => {
     const { latitude, longitude } = event.nativeEvent.coordinate;
     const { latitude, longitude } = event.nativeEvent.coordinate;
     const point = turf.point([longitude, latitude]);
     const point = turf.point([longitude, latitude]);
 
 
-    let db = getSecondDatabase();
+    let db = db2;
     let tableName = 'places';
     let tableName = 'places';
     let foundRegion: any;
     let foundRegion: any;
 
 
@@ -448,7 +466,7 @@ const MapScreen: React.FC<MapScreenProps> = ({ navigation, route }) => {
 
 
     if (type === 1) {
     if (type === 1) {
       foundRegion = regions ? findRegionInDataset(regions, point) : null;
       foundRegion = regions ? findRegionInDataset(regions, point) : null;
-      db = getFirstDatabase();
+      db = db1;
       tableName = 'regions';
       tableName = 'regions';
 
 
       if (foundRegion) {
       if (foundRegion) {
@@ -461,7 +479,7 @@ const MapScreen: React.FC<MapScreenProps> = ({ navigation, route }) => {
           setMarkers([]);
           setMarkers([]);
           setProcessedMarkers([]);
           setProcessedMarkers([]);
 
 
-          db = getCountriesDatabase();
+          db = db3;
           tableName = 'countries';
           tableName = 'countries';
 
 
           await getData(db, countryId, tableName, handleRegionData)
           await getData(db, countryId, tableName, handleRegionData)
@@ -495,7 +513,7 @@ const MapScreen: React.FC<MapScreenProps> = ({ navigation, route }) => {
 
 
     if (!foundRegion) {
     if (!foundRegion) {
       foundRegion = regions ? findRegionInDataset(regions, point) : null;
       foundRegion = regions ? findRegionInDataset(regions, point) : null;
-      db = getFirstDatabase();
+      db = db1;
       tableName = 'regions';
       tableName = 'regions';
     }
     }
 
 
@@ -575,10 +593,10 @@ const MapScreen: React.FC<MapScreenProps> = ({ navigation, route }) => {
     cancelTokenRef.current = true;
     cancelTokenRef.current = true;
     const db =
     const db =
       type === 'regions'
       type === 'regions'
-        ? getFirstDatabase()
+        ? db1
         : type === 'countries'
         : type === 'countries'
-          ? getCountriesDatabase()
-          : getSecondDatabase();
+          ? db3
+          : db2;
 
 
     if (type === 'countries') {
     if (type === 'countries') {
       setSelectedRegion(null);
       setSelectedRegion(null);

+ 19 - 2
src/screens/InAppScreens/TravelsScreen/utils/useRegionData.ts

@@ -3,15 +3,32 @@ import { useState, useEffect } from 'react';
 import { getFirstDatabase, getSecondDatabase, refreshDatabases } from 'src/db';
 import { getFirstDatabase, getSecondDatabase, refreshDatabases } from 'src/db';
 import { getData } from 'src/modules/map/regionData';
 import { getData } from 'src/modules/map/regionData';
 import { DbRegion } from './types';
 import { DbRegion } from './types';
+import { SQLiteDatabase } from 'expo-sqlite/legacy';
 
 
 const useRegionData = (regionId: number, dare: boolean = false) => {
 const useRegionData = (regionId: number, dare: boolean = false) => {
   const [regionData, setRegionData] = useState<DbRegion | null>(null);
   const [regionData, setRegionData] = useState<DbRegion | null>(null);
   const [avatars, setAvatars] = useState<string[] | null>(null);
   const [avatars, setAvatars] = useState<string[] | null>(null);
+  const [db1, setDb1] = useState<SQLiteDatabase | null>(null);
+  const [db2, setDb2] = useState<SQLiteDatabase | null>(null);
+
+  useEffect(() => {
+    const loadDatabases = async () => {
+      const firstDb = await getFirstDatabase();
+      const secondDb = await getSecondDatabase();
+
+      setDb1(firstDb);
+      setDb2(secondDb);
+    };
+
+    loadDatabases();
+  }, []);
 
 
   useEffect(() => {
   useEffect(() => {
     const fetchRegionData = async () => {
     const fetchRegionData = async () => {
-      const db = dare ? getSecondDatabase() : getFirstDatabase();
+      const db = dare ? db2 : db1;
       const tableName = dare ? 'places' : 'regions';
       const tableName = dare ? 'places' : 'regions';
+      if (!db) return;
+      
       try {
       try {
         await getData(db, regionId, tableName, (data, avatars) => {
         await getData(db, regionId, tableName, (data, avatars) => {
           setRegionData(data);
           setRegionData(data);
@@ -24,7 +41,7 @@ const useRegionData = (regionId: number, dare: boolean = false) => {
     };
     };
 
 
     fetchRegionData();
     fetchRegionData();
-  }, [regionId]);
+  }, [regionId, db1, db2]);
 
 
   return { regionData, avatars };
   return { regionData, avatars };
 };
 };