Browse Source

correcting pluviometers registration issues

master
analuizaff 3 years ago
parent
commit
7ea555818d
  1. 2
      src/app/components/forms/OnSubmitMessageModal.js
  2. 16
      src/app/hooks/useFiltering.js
  3. 8
      src/app/hooks/usePluviometricStation.js
  4. 1
      src/app/navigation/AppNavigator.js
  5. 44
      src/app/screens/PluviometerRegisterScreen.js
  6. 34
      src/app/screens/SharingDataScreen.js

2
src/app/components/forms/OnSubmitMessageModal.js

@ -24,7 +24,7 @@ const onModalClose = () =>{
> >
<View style={[styles.container, { bottom: (screen_height - 267) / 2 }]}> <View style={[styles.container, { bottom: (screen_height - 267) / 2 }]}>
<View style={{ flex: 0.85 }}> <View style={{ flex: 0.85 }}>
{!sucess && (
{sucess == false && (
<View> <View>
<AntDesign <AntDesign
name="warning" name="warning"

16
src/app/hooks/useFiltering.js

@ -12,37 +12,37 @@ function useFiltering(location) {
{ {
name: "floodZones", name: "floodZones",
url: endpoint + url: endpoint +
`type=FLOODZONES_FORM&time=${finalDate}/${initialDate}&lat=${location.lat}&lon=${location.long}&buffer=50000&limit=50`,
`type=FLOODZONES_FORM&time=${finalDate}/${initialDate}&lat=${location.lat}&lon=${location.long}&buffer=5000&limit=50`,
socketUrl: new WebSocket( socketUrl: new WebSocket(
endpoint + endpoint +
`type=FLOODZONES_FORM&time=${finalDate}/${initialDate}&lat=${location.lat}&lon=${location.long}&buffer=50000&limit=50`
`type=FLOODZONES_FORM&time=${finalDate}/${initialDate}&lat=${location.lat}&lon=${location.long}&buffer=5000&limit=50`
), ),
}, },
{ {
name: "rain", name: "rain",
url: endpoint + url: endpoint +
`type=RAIN_FORM&time=${finalDate}/${initialDate}&lat=${location.lat}&lon=${location.long}&buffer=50000&limit=50`,
`type=RAIN_FORM&time=${finalDate}/${initialDate}&lat=${location.lat}&lon=${location.long}&buffer=5000&limit=50`,
socketUrl: new WebSocket( socketUrl: new WebSocket(
endpoint + endpoint +
`type=RAIN_FORM&time=${finalDate}/${initialDate}&lat=${location.lat}&lon=${location.long}&buffer=50000&limit=50`
`type=RAIN_FORM&time=${finalDate}/${initialDate}&lat=${location.lat}&lon=${location.long}&buffer=5000&limit=50`
), ),
}, },
{ {
name: "riverFlood", name: "riverFlood",
url: endpoint + url: endpoint +
`type=RIVERFLOOD_FORM&time=${finalDate}/${initialDate}&lat=${location.lat}&lon=${location.long}&buffer=50000&limit=50`,
`type=RIVERFLOOD_FORM&time=${finalDate}/${initialDate}&lat=${location.lat}&lon=${location.long}&buffer=5000&limit=50`,
socketUrl: new WebSocket( socketUrl: new WebSocket(
endpoint + endpoint +
`type=RIVERFLOOD_FORM&time=${finalDate}/${initialDate}&lat=${location.lat}&lon=${location.long}&buffer=50000&limit=50`
`type=RIVERFLOOD_FORM&time=${finalDate}/${initialDate}&lat=${location.lat}&lon=${location.long}&buffer=5000&limit=50`
), ),
}, },
{ {
name: "pluviometer", name: "pluviometer",
url: endpoint + url: endpoint +
`type=PLUVIOMETER_REGISTRATION&lat=${location.lat}&lon=${location.long}&buffer=50000&limit=50`,
`type=PLUVIOMETER_REGISTRATION&lat=${location.lat}&lon=${location.long}&buffer=5000&limit=50`,
socketUrl: new WebSocket( socketUrl: new WebSocket(
endpoint + endpoint +
`type=PLUVIOMETER_REGISTRATION&lat=${location.lat}&lon=${location.long}&buffer=50000&limit=50`
`type=PLUVIOMETER_REGISTRATION&lat=${location.lat}&lon=${location.long}&buffer=5000&limit=50`
), ),
}, },
{ {

8
src/app/hooks/usePluviometricStation.js

@ -51,8 +51,9 @@ async function getPluviometerStation(userId, setPluviometerStation) {
socketObject.onmessage = async ({ data }) => { socketObject.onmessage = async ({ data }) => {
const dataObject = JSON.parse(data); const dataObject = JSON.parse(data);
if (dataObject?.success) { if (dataObject?.success) {
pluvStation_id = dataObject.responseData.array_to_json[0].formsanswersid;
pluvStation_data = await getPluvStation_data(pluvStation_id);
const pluvStation_id =
dataObject.responseData.array_to_json[0].formsanswersid;
const pluvStation_data = await getPluvStation_data(pluvStation_id);
const pluvObject = assemblePluvStationObject( const pluvObject = assemblePluvStationObject(
pluvStation_data.data.responseData.array_to_json[0] pluvStation_data.data.responseData.array_to_json[0]
); );
@ -60,14 +61,13 @@ async function getPluviometerStation(userId, setPluviometerStation) {
} else { } else {
setPluviometerStation(false); setPluviometerStation(false);
} }
socketObject.close();
}; };
socketObject.onerror = (e) => { socketObject.onerror = (e) => {
console.log(e.message); console.log(e.message);
setPluviometerStation(undefined); setPluviometerStation(undefined);
}; };
socketObject.close();
} }
export default getPluviometerStation; export default getPluviometerStation;

1
src/app/navigation/AppNavigator.js

@ -63,6 +63,7 @@ function tabScreens() {
name="Perfil" name="Perfil"
component={AccountNavigator} component={AccountNavigator}
options={{ options={{
unmountOnBlur: true,
headerShown: false, headerShown: false,
tabBarIcon: ({ color, size }) => ( tabBarIcon: ({ color, size }) => (
<MaterialCommunityIcons name="account" color={color} size={size} /> <MaterialCommunityIcons name="account" color={color} size={size} />

44
src/app/screens/PluviometerRegisterScreen.js

@ -1,4 +1,4 @@
import React, { useState, useContext } from "react";
import React, { useState, useContext, useEffect } from "react";
import { MaterialIcons } from "@expo/vector-icons"; import { MaterialIcons } from "@expo/vector-icons";
import { StyleSheet, Text, View } from "react-native"; import { StyleSheet, Text, View } from "react-native";
import { Form, SubmitButton } from "../components/forms"; import { Form, SubmitButton } from "../components/forms";
@ -15,7 +15,6 @@ import { AssembleIngestionPluvRegistration } from "../components/forms/AssembleI
import OnSubmitAwaitModal from "../components/forms/OnSubmitAwaitModal"; import OnSubmitAwaitModal from "../components/forms/OnSubmitAwaitModal";
import OnSubmitMessageModal from "../components/forms/OnSubmitMessageModal"; import OnSubmitMessageModal from "../components/forms/OnSubmitMessageModal";
function Institution({ user }) { function Institution({ user }) {
const institutionMap = { const institutionMap = {
E: "Escola", E: "Escola",
@ -131,7 +130,7 @@ function PluvDateTimePicker({
pluviometer, pluviometer,
}) { }) {
return ( return (
<View style={{height: 58}}>
<View style={{ height: 58 }}>
{!pluviometer && ( {!pluviometer && (
<FormDatePicker <FormDatePicker
onDateChange={onDateChange} onDateChange={onDateChange}
@ -173,27 +172,48 @@ function PluviometerRegisterScreen(props) {
const [time, setTime] = useState(moment()); const [time, setTime] = useState(moment());
const [location, setLocationAddr] = useState("Defina o endereço no mapa"); const [location, setLocationAddr] = useState("Defina o endereço no mapa");
const [coordinates, setCoordinates] = useState(null); const [coordinates, setCoordinates] = useState(null);
const { user, _ } = useContext(AuthContext);
const { user, setUser } = useContext(AuthContext);
const [showAwaitModal, setShowAwaitModal] = useState(false); const [showAwaitModal, setShowAwaitModal] = useState(false);
const [showMessageModal, setShowMessageModal] = useState(false); const [showMessageModal, setShowMessageModal] = useState(false);
const [apiMessage, setApiMessage] = useState(null); const [apiMessage, setApiMessage] = useState(null);
const sendForm = async (date, time, user, address, coordinates) => { const sendForm = async (date, time, user, address, coordinates) => {
const isSent = await AssembleIngestionPluvRegistration(
const isSent = AssembleIngestionPluvRegistration(
date, date,
time, time,
user, user,
address, address,
coordinates coordinates
);
).then((isSent) => {
if (isSent) { if (isSent) {
setApiMessage(isSent.ok); setApiMessage(isSent.ok);
}
return apiMessage;
setShowAwaitModal(false);
setShowMessageModal(true);
}
return isSent;
});
}; };
useEffect(() => {
if (apiMessage) {
setUser({
...user,
pluviometer: {
regiterDate: date + " | " + time,
address: location,
institutionType: user.institutionType,
institutionName: user.institutionName,
coordinates: {
lat: coordinates["latitude"],
long: coordinates["longitude"],
},
},
});
}
}, [apiMessage]);
return ( return (
<View style={{ padding: 10, flex: 1 }}> <View style={{ padding: 10, flex: 1 }}>
<OnSubmitAwaitModal show={showAwaitModal} /> <OnSubmitAwaitModal show={showAwaitModal} />
@ -207,10 +227,7 @@ function PluviometerRegisterScreen(props) {
initialValues={{}} initialValues={{}}
onSubmit={async () => { onSubmit={async () => {
setShowAwaitModal(true); setShowAwaitModal(true);
sendForm(date, time, user, location, coordinates).then((isSent) => {
setShowAwaitModal(false);
setShowMessageModal(true);
});
sendForm(date, time, user, location, coordinates);
}} }}
> >
<View <View
@ -224,7 +241,6 @@ function PluviometerRegisterScreen(props) {
: "Cadastro do Pluviômetro"} : "Cadastro do Pluviômetro"}
</Text> </Text>
<Text <Text
style={{ style={{
marginTop: 24, marginTop: 24,
@ -247,7 +263,6 @@ function PluviometerRegisterScreen(props) {
pluviometer={user.pluviometer} pluviometer={user.pluviometer}
/> />
<Text style={styles.label}>Endereço do pluviômetro*: </Text> <Text style={styles.label}>Endereço do pluviômetro*: </Text>
<View marginBottom={24} marginTop={12}> <View marginBottom={24} marginTop={12}>
@ -304,7 +319,6 @@ const styles = StyleSheet.create({
textAlign: "center", textAlign: "center",
color: colors.primary, color: colors.primary,
}, },
}); });
export default PluviometerRegisterScreen; export default PluviometerRegisterScreen;

34
src/app/screens/SharingDataScreen.js

@ -18,15 +18,22 @@ function SharingDataScreen({ navigation }) {
console.log(authContext.user?.pluviometer); console.log(authContext.user?.pluviometer);
const currentUser = authContext.user; const currentUser = authContext.user;
const onConfirmPluv = () => {
if (authContext.user?.pluviometer == false) {
setShowLogPluv(false);
navigation.navigate("Perfil");
} else if (authContext.user?.pluviometer == undefined) {
setShowLogPluv(false);
}
};
return ( return (
<View style={styles.container}> <View style={styles.container}>
<ConfirmationModal <ConfirmationModal
show={showLogPluv} show={showLogPluv}
description="Para enviar uma informação pluviométrica cadastre um pluviômetro"
confirmationLabel="OK"
onConfirm={() => setShowLogPluv(false)}//{setShowLogPluv(false), navigation.navigate("Perfil")}}
description="Para enviar um dado pluviométrico cadastre um pluviômetro"
confirmationLabel="Cadastrar"
onConfirm={() => onConfirmPluv()} //{setShowLogPluv(false), navigation.navigate("Perfil")}}
onDecline={() => setShowLogPluv(false)} onDecline={() => setShowLogPluv(false)}
/> />
<ConfirmationModal <ConfirmationModal
@ -49,7 +56,9 @@ function SharingDataScreen({ navigation }) {
label={"ÁREA DE \nALAGAMENTO"} label={"ÁREA DE \nALAGAMENTO"}
style={{ marginRight: 24 }} style={{ marginRight: 24 }}
SvgImage={assets.floodZones.FloodZonesIcon} SvgImage={assets.floodZones.FloodZonesIcon}
onPress={() => navigation.navigate("FloodSharingData", { user: currentUser })}
onPress={() =>
navigation.navigate("FloodSharingData", { user: currentUser })
}
active={isRegistered} active={isRegistered}
inactiveOnPress={() => setShowLog(true)} inactiveOnPress={() => setShowLog(true)}
/> />
@ -76,15 +85,24 @@ function SharingDataScreen({ navigation }) {
<SvgLabeledButton <SvgLabeledButton
style={{ marginRight: 24 }} style={{ marginRight: 24 }}
label={"DIÁRIO DO\nPLUVIÔMETRO"} label={"DIÁRIO DO\nPLUVIÔMETRO"}
onPress={() => navigation.navigate("PluviometerSharingData", { user: currentUser })}
onPress={() =>
navigation.navigate("PluviometerSharingData", {
user: currentUser,
})
}
SvgImage={assets.PluviometricDataIcon} SvgImage={assets.PluviometricDataIcon}
active={isRegistered && pluviometer} active={isRegistered && pluviometer}
inactiveOnPress={() => {setShowLog(!isRegistered), setShowLogPluv(!pluviometer && isRegistered)}}
inactiveOnPress={() => {
setShowLog(!isRegistered),
setShowLogPluv(!pluviometer && isRegistered);
}}
/> />
<SvgLabeledButton <SvgLabeledButton
label={"NÍVEL ÁGUA\nNO RIO"} label={"NÍVEL ÁGUA\nNO RIO"}
onPress={() => navigation.navigate("RiverFloodData", { user: currentUser })}
onPress={() =>
navigation.navigate("RiverFloodData", { user: currentUser })
}
SvgImage={assets.riverLevel.RiverIcon} SvgImage={assets.riverLevel.RiverIcon}
active={isRegistered} active={isRegistered}
inactiveOnPress={() => setShowLog(true)} inactiveOnPress={() => setShowLog(true)}

Loading…
Cancel
Save