Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(offline): added checks for network connectivity #153

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scheme": "com.zaniluca.ping4gitlab",
"description": "Multiplatform react-native app that sends you instant notifications about gitlab activities",
"slug": "ping4gitlab",
"version": "2.1.4",
"version": "2.1.5",
"privacy": "public",
"orientation": "portrait",
"userInterfaceStyle": "automatic",
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,28 @@
"@shopify/restyle": "2.0.0",
"@tanstack/react-query": "^4.0.10",
"axios": "^0.27.2",
"expo": "^51.0.0",
"expo": "~51.0.20",
"expo-application": "~5.9.1",
"expo-clipboard": "~6.0.3",
"expo-constants": "~16.0.2",
"expo-device": "~6.0.2",
"expo-font": "~12.0.7",
"expo-font": "~12.0.8",
"expo-haptics": "~13.0.1",
"expo-insights": "~0.7.0",
"expo-linear-gradient": "~13.0.2",
"expo-linking": "~6.3.1",
"expo-notifications": "~0.28.9",
"expo-secure-store": "~13.0.1",
"expo-secure-store": "~13.0.2",
"expo-splash-screen": "~0.27.5",
"expo-status-bar": "~1.12.1",
"expo-system-ui": "~3.0.6",
"expo-updates": "~0.25.17",
"expo-system-ui": "~3.0.7",
"expo-updates": "~0.25.19",
"expo-web-browser": "~13.0.3",
"formik": "^2.2.9",
"jwt-decode": "^3.1.2",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-native": "0.74.2",
"react-native": "0.74.3",
"react-native-feather": "^1.1.2",
"react-native-progress": "^5.0.0",
"react-native-safe-area-context": "4.10.1",
Expand Down
31 changes: 25 additions & 6 deletions src/hooks/use-online-manager.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
import NetInfo from "@react-native-community/netinfo";
import { onlineManager } from "@tanstack/react-query";
import { useEffect } from "react";
import { useEffect, useState } from "react";
import { Platform } from "react-native";
import { Toast } from "react-native-toast-message/lib/src/Toast";

export function useOnlineManager() {
const [isOnline, setIsOnline] = useState(false);

useEffect(() => {
if (Platform.OS !== "web") {
return NetInfo.addEventListener((state) => {
onlineManager.setOnline(
const unsubscribe = NetInfo.addEventListener((state) => {
const isOnline =
state.isConnected != null &&
state.isConnected &&
Boolean(state.isInternetReachable)
);
state.isConnected &&
Boolean(state.isInternetReachable);

if (!isOnline)
Toast.show({
type: "error",
text1: "No internet connection",
text2: "It seems you are offline",
autoHide: false,
});

onlineManager.setOnline(isOnline);
setIsOnline(isOnline);
});

return () => {
unsubscribe();
};
}
}, []);

return isOnline;
}
Loading