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. 3
      src/app/navigation/AppNavigator.js
  5. 48
      src/app/screens/PluviometerRegisterScreen.js
  6. 36
      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={{ flex: 0.85 }}>
{!sucess && (
{sucess == false && (
<View>
<AntDesign
name="warning"

16
src/app/hooks/useFiltering.js

@ -12,37 +12,37 @@ function useFiltering(location) {
{
name: "floodZones",
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(
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",
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(
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",
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(
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",
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(
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 }) => {
const dataObject = JSON.parse(data);
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(
pluvStation_data.data.responseData.array_to_json[0]
);
@ -60,14 +61,13 @@ async function getPluviometerStation(userId, setPluviometerStation) {
} else {
setPluviometerStation(false);
}
socketObject.close();
};
socketObject.onerror = (e) => {
console.log(e.message);
setPluviometerStation(undefined);
};
socketObject.close();
}
export default getPluviometerStation;

3
src/app/navigation/AppNavigator.js

@ -61,8 +61,9 @@ function tabScreens() {
<Tab.Screen
name="Perfil"
component={AccountNavigator}
component={AccountNavigator}
options={{
unmountOnBlur: true,
headerShown: false,
tabBarIcon: ({ color, size }) => (
<MaterialCommunityIcons name="account" color={color} size={size} />

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

36
src/app/screens/SharingDataScreen.js

@ -10,7 +10,7 @@ import colors from "../config/colors";
function SharingDataScreen({ navigation }) {
const authContext = useContext(AuthContext);
const [showLog, setShowLog] = useState(false);
const [showLog, setShowLog] = useState(false);
const [showLogPluv, setShowLogPluv] = useState(false);
const isRegistered = authContext.user?.username != null;
@ -18,15 +18,22 @@ function SharingDataScreen({ navigation }) {
console.log(authContext.user?.pluviometer);
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 (
<View style={styles.container}>
<ConfirmationModal
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)}
/>
<ConfirmationModal
@ -49,7 +56,9 @@ function SharingDataScreen({ navigation }) {
label={"ÁREA DE \nALAGAMENTO"}
style={{ marginRight: 24 }}
SvgImage={assets.floodZones.FloodZonesIcon}
onPress={() => navigation.navigate("FloodSharingData", { user: currentUser })}
onPress={() =>
navigation.navigate("FloodSharingData", { user: currentUser })
}
active={isRegistered}
inactiveOnPress={() => setShowLog(true)}
/>
@ -76,15 +85,24 @@ function SharingDataScreen({ navigation }) {
<SvgLabeledButton
style={{ marginRight: 24 }}
label={"DIÁRIO DO\nPLUVIÔMETRO"}
onPress={() => navigation.navigate("PluviometerSharingData", { user: currentUser })}
onPress={() =>
navigation.navigate("PluviometerSharingData", {
user: currentUser,
})
}
SvgImage={assets.PluviometricDataIcon}
active={isRegistered && pluviometer}
inactiveOnPress={() => {setShowLog(!isRegistered), setShowLogPluv(!pluviometer && isRegistered)}}
inactiveOnPress={() => {
setShowLog(!isRegistered),
setShowLogPluv(!pluviometer && isRegistered);
}}
/>
<SvgLabeledButton
label={"NÍVEL ÁGUA\nNO RIO"}
onPress={() => navigation.navigate("RiverFloodData", { user: currentUser })}
onPress={() =>
navigation.navigate("RiverFloodData", { user: currentUser })
}
SvgImage={assets.riverLevel.RiverIcon}
active={isRegistered}
inactiveOnPress={() => setShowLog(true)}

Loading…
Cancel
Save