Browse Source

adding internet connection warning to screens

master
analuizaff 3 years ago
parent
commit
81c04fcc25
  1. 3
      src/app/config/colors.js
  2. 63
      src/app/screens/AccountScreen.js
  3. 9
      src/app/screens/MapFeedScreen.js
  4. 170
      src/app/screens/SharingDataScreen.js

3
src/app/config/colors.js

@ -20,5 +20,6 @@ export default {
toggle: "#e5eff4", toggle: "#e5eff4",
grayBG: "#EEECEC", grayBG: "#EEECEC",
blueWarning: "#75BDE0", blueWarning: "#75BDE0",
greenWarning: "#6BC69A"
greenWarning: "#6BC69A",
grayDisabled:"#838383"
}; };

63
src/app/screens/AccountScreen.js

@ -10,32 +10,40 @@ import colors from "../config/colors";
import ConfirmationModal from "../components/ConfirmationModal"; import ConfirmationModal from "../components/ConfirmationModal";
import utils from "../config/utils"; import utils from "../config/utils";
import { mask } from "react-native-mask-text"; import { mask } from "react-native-mask-text";
import { useNetInfo } from "@react-native-community/netinfo";
import ConnectionWarning from "../components/ConnectionWarning";
function UserHeader({ name, fone }) { function UserHeader({ name, fone }) {
const index = utils.hashPhoneNumber(fone) % assets.avatar.length || 2
const index = utils.hashPhoneNumber(fone) % assets.avatar.length || 2;
const Avatar = assets.avatar[index]; const Avatar = assets.avatar[index];
var _mask = ""; var _mask = "";
switch (fone?.length) { switch (fone?.length) {
case 12: case 12:
_mask = "(999) 99999-9999" ;
_mask = "(999) 99999-9999";
break; break;
case 11: case 11:
_mask = "(99) 99999-9999"
_mask = "(99) 99999-9999";
break; break;
case 10: case 10:
_mask = "(99) 9999-9999"
_mask = "(99) 9999-9999";
break; break;
default: default:
_mask = "(99) 9999-9999"
_mask = "(99) 9999-9999";
break; break;
} }
const fone_mask = mask(fone, _mask); const fone_mask = mask(fone, _mask);
return ( return (
<View style={{ flexDirection: "row", alignItems: "center", justifyContent: name ? "flex-start" : "center" }}>
<Avatar width={60} height={60}/>
<View
style={{
flexDirection: "row",
alignItems: "center",
justifyContent: name ? "flex-start" : "center",
}}
>
<Avatar width={60} height={60} />
<View style={{ marginLeft: 16 }}> <View style={{ marginLeft: 16 }}>
<Text style={[styles.text, { fontWeight: "bold" }]}>{name}</Text> <Text style={[styles.text, { fontWeight: "bold" }]}>{name}</Text>
<Text style={styles.text}>{fone ? fone_mask : ""}</Text> <Text style={styles.text}>{fone ? fone_mask : ""}</Text>
@ -45,6 +53,7 @@ function UserHeader({ name, fone }) {
} }
function ProfileItensList({ icon, IconProvider, title, onPress }) { function ProfileItensList({ icon, IconProvider, title, onPress }) {
const isConnected = useNetInfo().isConnected;
return ( return (
<View> <View>
<View <View
@ -54,7 +63,7 @@ function ProfileItensList({ icon, IconProvider, title, onPress }) {
}} }}
></View> ></View>
<TouchableOpacity onPress={onPress}>
<TouchableOpacity disabled={!isConnected} onPress={onPress}>
<View <View
style={{ style={{
marginVertical: 16, marginVertical: 16,
@ -62,13 +71,14 @@ function ProfileItensList({ icon, IconProvider, title, onPress }) {
alignItems: "center", alignItems: "center",
}} }}
> >
<IconProvider name={icon} size={18} color={colors.dark} />
<IconProvider name={icon} size={18} color={isConnected ? colors.black : colors.gray} />
<Text <Text
style={{ style={{
fontSize: 16, fontSize: 16,
marginLeft: 16, marginLeft: 16,
textTransform: "uppercase", textTransform: "uppercase",
fontWeight: "500", fontWeight: "500",
color: isConnected ? colors.black : colors.gray,
}} }}
> >
{title} {title}
@ -82,7 +92,7 @@ function ProfileItensList({ icon, IconProvider, title, onPress }) {
<MaterialCommunityIcons <MaterialCommunityIcons
name={"chevron-right"} name={"chevron-right"}
size={20} size={20}
color={colors.dark}
color={isConnected ? colors.black : colors.gray}
/> />
</View> </View>
</View> </View>
@ -98,9 +108,9 @@ function AccountScreen(props) {
//console.log(user); //console.log(user);
const logout = () => { const logout = () => {
setShowLog(false)
setShowLog(false);
setUser(true); setUser(true);
props.navigation.navigate("Home")
props.navigation.navigate("Home");
authStorage.removeToken(); authStorage.removeToken();
authStorage.removeUser(); authStorage.removeUser();
}; };
@ -108,35 +118,32 @@ function AccountScreen(props) {
const activationActions = () => { const activationActions = () => {
if (user?.providerActivationKey) if (user?.providerActivationKey)
props.navigation.navigate("ActivateInstitutionShowCode"); props.navigation.navigate("ActivateInstitutionShowCode");
else
props.navigation.navigate("ActivateInstitutionCode");
else props.navigation.navigate("ActivateInstitutionCode");
}; };
const showActivation = () => { const showActivation = () => {
if (!isRegistered)
return false
else if (user.role === "ROLE_CLIENT")
return !user.active
else
return true
}
if (!isRegistered) return false;
else if (user.role === "ROLE_CLIENT") return !user.active;
else return true;
};
const profileItems = [ const profileItems = [
{
{
icon: "lock", icon: "lock",
show: true, show: true,
IconProvider: MaterialCommunityIcons, IconProvider: MaterialCommunityIcons,
title: "alterar senha", title: "alterar senha",
onPress: () => { onPress: () => {
props.navigation.navigate("PasswordRecovery", {user: user});
props.navigation.navigate("PasswordRecovery", { user: user });
}, },
}, },
{ {
icon: "account", icon: "account",
show: user.pluviometer != undefined, show: user.pluviometer != undefined,
IconProvider: MaterialCommunityIcons, IconProvider: MaterialCommunityIcons,
title: user.pluviometer? "Dados do pluviômetro" : "Cadastrar pluviômetro",
title: user.pluviometer
? "Dados do pluviômetro"
: "Cadastrar pluviômetro",
onPress: () => { onPress: () => {
props.navigation.navigate("PluviometerRegister"); props.navigation.navigate("PluviometerRegister");
}, },
@ -182,6 +189,9 @@ function AccountScreen(props) {
]; ];
return ( return (
<View style={{flex:1, width: "100%"}}>
<ConnectionWarning />
<Screen> <Screen>
<ScrollView> <ScrollView>
<View <View
@ -189,7 +199,7 @@ function AccountScreen(props) {
padding: 16, padding: 16,
}} }}
> >
<UserHeader name={user.nickname} fone={user.username}/>
<UserHeader name={user.nickname} fone={user.username} />
<View style={{ marginTop: 24 }}> <View style={{ marginTop: 24 }}>
{profileItems.map( {profileItems.map(
@ -218,6 +228,7 @@ function AccountScreen(props) {
</View> </View>
</ScrollView> </ScrollView>
</Screen> </Screen>
</View>
); );
} }

9
src/app/screens/MapFeedScreen.js

@ -8,6 +8,7 @@ import LoadingMarkersModal from "../components/LoadingMarkersModal";
import NoGPSError from "../components/NoGPSError"; import NoGPSError from "../components/NoGPSError";
import NetInfo, { useNetInfo } from "@react-native-community/netinfo"; import NetInfo, { useNetInfo } from "@react-native-community/netinfo";
import ConnectionWarning from "../components/ConnectionWarning";
export default function MapFeedScreen(props) { export default function MapFeedScreen(props) {
HeaderBarMenu(props.navigation); HeaderBarMenu(props.navigation);
@ -33,7 +34,10 @@ export default function MapFeedScreen(props) {
// console.log("location: " + JSON.stringify(global.location)) // console.log("location: " + JSON.stringify(global.location))
return ( return (
(global.location) ? (
<View style={{flex:1, width: "100%"}}>
<ConnectionWarning />
{ (global.location) ? (
<View style={styles.container}> <View style={styles.container}>
<OpenStreetMap <OpenStreetMap
markers={markers} markers={markers}
@ -46,7 +50,8 @@ export default function MapFeedScreen(props) {
</View> </View>
):( ):(
<NoGPSError/> <NoGPSError/>
)
)}
</View>
); );
} }

170
src/app/screens/SharingDataScreen.js

@ -7,17 +7,17 @@ import { dimensions } from "../config/dimensions";
import SvgLabeledButton from "../components/SvgLabeledButton"; import SvgLabeledButton from "../components/SvgLabeledButton";
import { AuthContext } from "../auth/context"; import { AuthContext } from "../auth/context";
import { useNetInfo } from "@react-native-community/netinfo"; import { useNetInfo } from "@react-native-community/netinfo";
import ConnectionWarning from "../components/ConnectionWarning";
function SharingDataScreen({ navigation }) { function SharingDataScreen({ navigation }) {
const authContext = useContext(AuthContext); const authContext = useContext(AuthContext);
const [showLog, setShowLog] = useState(false); const [showLog, setShowLog] = useState(false);
const [showLogPluv, setShowLogPluv] = useState(false); const [showLogPluv, setShowLogPluv] = useState(false);
const [showConnectionWarning, setShowConnectionWarning] = useState(false);
const connection = useNetInfo().isConnected; const connection = useNetInfo().isConnected;
console.log(connection)
const isRegistered = authContext.user?.username != null; const isRegistered = authContext.user?.username != null;
const pluviometer = authContext.user?.pluviometer ? true : false; const pluviometer = authContext.user?.pluviometer ? true : false;
// console.log(authContext.user?.pluviometer);
const currentUser = authContext.user; const currentUser = authContext.user;
const onConfirmPluv = () => { const onConfirmPluv = () => {
@ -30,91 +30,95 @@ function SharingDataScreen({ navigation }) {
}; };
return ( return (
<View style={styles.container}>
<ConfirmationModal
show={showLogPluv}
icon={"md-warning-outline"}
description="Para enviar um dado pluviométrico, cadastre um pluviômetro"
confirmationLabel="Cadastrar"
onConfirm={() => onConfirmPluv()} //{setShowLogPluv(false), navigation.navigate("Perfil")}}
onDecline={() => setShowLogPluv(false)}
/>
<ConfirmationModal
show={showLog}
icon={"md-warning-outline"}
description={
"Para enviar uma informação," + "\n" + "faça o login ou cadastre-se"
}
confirmationLabel="LOGIN"
onConfirm={() => authContext.setUser(false)}
onDecline={() => setShowLog(false)}
/>
<ScrollView>
<View
style={{
flexDirection: "row",
justifyContent: "center",
alignItems: "center",
marginTop: 30,
}}
>
<SvgLabeledButton
label={"ÁREA DE \nALAGAMENTO"}
style={{ marginRight: 24 }}
SvgImage={assets.floodZones.FloodZonesIcon}
onPress={() =>
navigation.navigate("FloodSharingData", { user: currentUser })
}
active={isRegistered && connection}
inactiveOnPress={() => setShowLog(true)}
/>
<View style={{flex:1, width: "100%"}}>
<SvgLabeledButton
label={"CHUVA"}
onPress={() =>
navigation.navigate("RainSharingData", { user: currentUser })
}
SvgImage={assets.rainLevel.RainIcon}
active={isRegistered && connection}
inactiveOnPress={() => setShowLog(true)}
/>
</View>
<ConnectionWarning />
<View style={styles.container}>
<ConfirmationModal
show={showLogPluv}
icon={"md-warning-outline"}
description="Para enviar um dado pluviométrico, cadastre um pluviômetro"
confirmationLabel="Cadastrar"
onConfirm={() => onConfirmPluv()} //{setShowLogPluv(false), navigation.navigate("Perfil")}}
onDecline={() => setShowLogPluv(false)}
/>
<ConfirmationModal
show={showLog}
icon={"md-warning-outline"}
description={
"Para enviar uma informação," + "\n" + "faça o login ou cadastre-se"
}
confirmationLabel="LOGIN"
onConfirm={() => authContext.setUser(false)}
onDecline={() => setShowLog(false)}
/>
<ScrollView>
<View
style={{
flexDirection: "row",
justifyContent: "center",
alignItems: "center",
marginTop: 30,
}}
>
<SvgLabeledButton
label={"ÁREA DE \nALAGAMENTO"}
style={{ marginRight: 24 }}
SvgImage={assets.floodZones.FloodZonesIcon}
onPress={() =>
navigation.navigate("FloodSharingData", { user: currentUser })
}
active={isRegistered && connection}
inactiveOnPress={() => setShowLog(true)}
/>
<SvgLabeledButton
label={"CHUVA"}
onPress={() =>
navigation.navigate("RainSharingData", { user: currentUser })
}
SvgImage={assets.rainLevel.RainIcon}
active={isRegistered && connection}
inactiveOnPress={() => setShowLog(true)}
/>
</View>
<View
style={{
flexDirection: "row",
justifyContent: "center",
flex: 1,
marginVertical: 24,
}}
>
<SvgLabeledButton
style={{ marginRight: 24 }}
label={"DIÁRIO DO\nPLUVIÔMETRO"}
onPress={() =>
navigation.navigate("PluviometerSharingData", {
user: currentUser,
})
}
SvgImage={assets.PluviometricDataIcon}
active={isRegistered && pluviometer && connection}
inactiveOnPress={() => {
setShowLog(!isRegistered),
setShowLogPluv(!pluviometer && isRegistered);
<View
style={{
flexDirection: "row",
justifyContent: "center",
flex: 1,
marginVertical: 24,
}} }}
/>
>
<SvgLabeledButton
style={{ marginRight: 24 }}
label={"DIÁRIO DO\nPLUVIÔMETRO"}
onPress={() =>
navigation.navigate("PluviometerSharingData", {
user: currentUser,
})
}
SvgImage={assets.PluviometricDataIcon}
active={isRegistered && pluviometer && connection}
inactiveOnPress={() => {
setShowLog(!isRegistered),
setShowLogPluv(!pluviometer && isRegistered);
}}
/>
<SvgLabeledButton
label={"NÍVEL ÁGUA\nNO RIO"}
onPress={() =>
navigation.navigate("RiverFloodData", { user: currentUser })
}
SvgImage={assets.riverLevel.RiverIcon}
active={isRegistered && connection}
inactiveOnPress={() => setShowLog(true)}
/>
</View>
</ScrollView>
<SvgLabeledButton
label={"NÍVEL ÁGUA\nNO RIO"}
onPress={() =>
navigation.navigate("RiverFloodData", { user: currentUser })
}
SvgImage={assets.riverLevel.RiverIcon}
active={isRegistered && connection}
inactiveOnPress={() => setShowLog(true)}
/>
</View>
</ScrollView>
</View>
</View> </View>
); );
} }

Loading…
Cancel
Save