-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: check network state on mount (#362)
- Loading branch information
Showing
10 changed files
with
75 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"networkStateCheck": { | ||
"message": "Please check your internet connection. The app might not work properly without it.", | ||
"title": "No internet connection" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"networkStateCheck": { | ||
"message": "Vérifiez la connexion internet. L'app peut ne pas fonctionner correctement sans connexion internet.", | ||
"title": "Pas de connexion internet" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import * as Network from 'expo-network'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { ErrorMonitoring } from '$core/monitoring'; | ||
import { Toaster } from '$core/toaster'; | ||
import { sleep } from '$shared/utils/sleep'; | ||
|
||
import { useRunOnMount } from './useRunOnMount'; | ||
|
||
const ONE_SECOND = 1000; | ||
|
||
export const useCheckNetworkStateOnMount = () => { | ||
const { t } = useTranslation('appConfig'); | ||
|
||
const checkNetworkState = async () => { | ||
await sleep(ONE_SECOND); | ||
const { isInternetReachable } = await Network.getNetworkStateAsync(); | ||
|
||
if (!isInternetReachable) { | ||
Toaster.show({ | ||
type: 'info', | ||
text1: t('networkStateCheck.title'), | ||
text2: t('networkStateCheck.message'), | ||
}); | ||
} | ||
}; | ||
|
||
useRunOnMount(() => { | ||
checkNetworkState().catch(() => { | ||
ErrorMonitoring.breadcrumbs({ | ||
category: 'network', | ||
type: 'network', | ||
message: 'Failed to check network state', | ||
}); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters