Viktoriia 9 mēneši atpakaļ
vecāks
revīzija
db5ae1d188

+ 1 - 1
Route.tsx

@@ -162,8 +162,8 @@ const Route = () => {
       await checkNmToken();
       await checkTokenAndUpdate();
       await openDatabases();
-      await findFastestServer();
       setDbLoaded(true);
+      await findFastestServer();
     };
 
     const findFastestServer = async () => {

+ 2 - 2
src/components/ConnectionBanner/ConnectionBanner.tsx

@@ -3,7 +3,7 @@ import { View, Text } from 'react-native';
 import { useConnection } from 'src/contexts/ConnectionContext';
 import { styles } from './styles';
 import { initializeBanner, showBanner } from 'src/utils/bannerUtils';
-import { refreshDatabases } from 'src/db';
+import { openDatabases } from 'src/db';
 
 const ConnectionBanner = () => {
   const netInfo = useConnection();
@@ -16,7 +16,7 @@ const ConnectionBanner = () => {
 
     if (netInfo?.isInternetReachable !== null) {
       if (hadConnection === false && netInfo?.isInternetReachable) {
-        refreshDatabases();
+        openDatabases();
         showBanner('Internet connection restored!');
       } else if (netInfo?.isInternetReachable === false) {
         showBanner('No internet connection!');

+ 5 - 0
src/db/index.ts

@@ -4,6 +4,7 @@ import { Asset } from 'expo-asset';
 import { API_HOST } from 'src/constants';
 import { storage } from 'src/storage';
 import { fetchLastDareDbUpdate, fetchLastRegionsDbUpdate } from '@api/app';
+import NetInfo from '@react-native-community/netinfo';
 
 let db1: SQLite.SQLiteDatabase | null = null;
 let db2: SQLite.SQLiteDatabase | null = null;
@@ -16,6 +17,10 @@ const sqliteFullPath = FileSystem.documentDirectory + sqliteDirectory;
 const DS = '/';
 
 async function copyDatabaseFile(dbName: string, dbAsset: Asset) {
+  const state = await NetInfo.fetch();
+
+  if (!state.isConnected && !state.isInternetReachable) return;
+  
   console.log('DB copy start - ' + dbName);
   await dbAsset.downloadAsync();
   await FileSystem.downloadAsync(dbAsset.uri, sqliteFullPath + DS + dbName);