From 5348b2dc0b8d4ed3e4555ecd8f78a121cd5e2dc9 Mon Sep 17 00:00:00 2001 From: analuizaff Date: Fri, 15 Apr 2022 16:49:55 -0300 Subject: [PATCH] disabling events reports when disconected from internet --- src/app/screens/SharingDataScreen.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/app/screens/SharingDataScreen.js b/src/app/screens/SharingDataScreen.js index 593321f..b3d4ce5 100644 --- a/src/app/screens/SharingDataScreen.js +++ b/src/app/screens/SharingDataScreen.js @@ -6,12 +6,14 @@ import assets from "../config/assets"; import { dimensions } from "../config/dimensions"; import SvgLabeledButton from "../components/SvgLabeledButton"; import { AuthContext } from "../auth/context"; -import colors from "../config/colors"; +import { useNetInfo } from "@react-native-community/netinfo"; function SharingDataScreen({ navigation }) { const authContext = useContext(AuthContext); const [showLog, setShowLog] = useState(false); const [showLogPluv, setShowLogPluv] = useState(false); + const connection = useNetInfo().isConnected; + console.log(connection) const isRegistered = authContext.user?.username != null; const pluviometer = authContext.user?.pluviometer ? true : false; @@ -40,7 +42,9 @@ function SharingDataScreen({ navigation }) { authContext.setUser(false)} onDecline={() => setShowLog(false)} @@ -61,7 +65,7 @@ function SharingDataScreen({ navigation }) { onPress={() => navigation.navigate("FloodSharingData", { user: currentUser }) } - active={isRegistered} + active={isRegistered && connection} inactiveOnPress={() => setShowLog(true)} /> @@ -71,7 +75,7 @@ function SharingDataScreen({ navigation }) { navigation.navigate("RainSharingData", { user: currentUser }) } SvgImage={assets.rainLevel.RainIcon} - active={isRegistered} + active={isRegistered && connection} inactiveOnPress={() => setShowLog(true)} /> @@ -93,7 +97,7 @@ function SharingDataScreen({ navigation }) { }) } SvgImage={assets.PluviometricDataIcon} - active={isRegistered && pluviometer} + active={isRegistered && pluviometer && connection} inactiveOnPress={() => { setShowLog(!isRegistered), setShowLogPluv(!pluviometer && isRegistered); @@ -106,7 +110,7 @@ function SharingDataScreen({ navigation }) { navigation.navigate("RiverFloodData", { user: currentUser }) } SvgImage={assets.riverLevel.RiverIcon} - active={isRegistered} + active={isRegistered && connection} inactiveOnPress={() => setShowLog(true)} />