show sync failed toast if internet is available

This commit is contained in:
ammarahm-ed
2021-06-10 13:39:57 +05:00
parent 081adcd01f
commit 7cdd882ca2
2 changed files with 21 additions and 16 deletions

View File

@@ -281,11 +281,14 @@ export const AppRootEvents = React.memo(
setLastSynced(await db.lastSynced());
} catch (e) {
setSyncing(false);
ToastEvent.show({
heading: 'Sync failed',
message: e.message,
context: 'global',
});
let status = await NetInfo.fetch();
if (status.isConnected && status.isInternetReachable) {
ToastEvent.show({
heading: 'Sync failed',
message: e.message,
context: 'global',
});
}
} finally {
setSyncing(false);
}

View File

@@ -1,14 +1,14 @@
import NetInfo from '@react-native-community/netinfo';
import {updateEvent} from '../components/DialogManager/recievers';
import {Actions} from '../provider/Actions';
import { initialize, useUserStore } from '../provider/stores';
import {initialize, useUserStore} from '../provider/stores';
import {doInBackground} from '../utils';
import {db} from '../utils/DB';
import {eOpenLoginDialog} from '../utils/Events';
import {eSendEvent, ToastEvent} from './EventManager';
const run = async (context = 'global', forced) => {
let userstore = useUserStore.getState()
let userstore = useUserStore.getState();
userstore.setSyncing(true);
try {
let res = await doInBackground(async () => {
@@ -19,7 +19,7 @@ const run = async (context = 'global', forced) => {
return e.message;
}
});
if (res !== true) throw new Error(res);
ToastEvent.show({
@@ -40,16 +40,18 @@ const run = async (context = 'global', forced) => {
actionText: 'Login',
});
} else {
userstore.setSyncing(false);
ToastEvent.show({
heading: 'Sync failed',
message: e.message,
context: context,
});
let status = await NetInfo.fetch();
if (status.isConnected && status.isInternetReachable) {
ToastEvent.show({
heading: 'Sync failed',
message: e.message,
context: context,
});
}
}
} finally {
userstore.setLastSynced(await db.lastSynced())
userstore.setLastSynced(await db.lastSynced());
initialize();
userstore.setSyncing(false);
}