forked from cemaden-educacao/WPD-MobileApp
GabrielTrettel
4 years ago
6 changed files with 263 additions and 142 deletions
-
45src/app/database/databaseLoader.js
-
14src/app/database/db.js
-
72src/app/hooks/selectFromDB.js
-
2src/app/screens/MapFeedScreen.js
-
47src/app/screens/RainSharingDataScreen.js
-
225src/app/screens/RiverFloodSharingDataScreen.js
@ -1,139 +1,138 @@ |
|||||
import React, { useState } from "react"; |
import React, { useState } from "react"; |
||||
import { Button, StyleSheet, View } from "react-native"; |
|
||||
|
import { StyleSheet, View } from "react-native"; |
||||
import * as Yup from "yup"; |
import * as Yup from "yup"; |
||||
|
|
||||
import { |
|
||||
Form, |
|
||||
FormField, |
|
||||
FormPicker as Picker, |
|
||||
SubmitButton, |
|
||||
} from "../components/forms"; |
|
||||
import CategoryPickerItem from "../components/CategoryPickerItem"; |
|
||||
|
import { Form, FormPicker as Picker, SubmitButton } from "../components/forms"; |
||||
import Screen from "../components/Screen"; |
import Screen from "../components/Screen"; |
||||
import FormImagePicker from "../components/forms/FormImagePicker"; |
import FormImagePicker from "../components/forms/FormImagePicker"; |
||||
import useLocation from "../hooks/useLocation"; |
import useLocation from "../hooks/useLocation"; |
||||
import { Image, Text, TouchableOpacity } from "react-native"; |
|
||||
|
import { Image, Text } from "react-native"; |
||||
import colors from "../config/colors"; |
import colors from "../config/colors"; |
||||
import { TouchableNativeFeedback } from "react-native-gesture-handler"; |
import { TouchableNativeFeedback } from "react-native-gesture-handler"; |
||||
|
import { insertRiverData } from "../database/databaseLoader"; |
||||
|
|
||||
const validationSchema = Yup.object().shape({ |
const validationSchema = Yup.object().shape({ |
||||
images: Yup.array().min(1, "Por favor, selecione ao menos uma imagem"), |
|
||||
description: Yup.string() |
|
||||
.label("Description") |
|
||||
.required("Por favor, forneça uma descrição"), |
|
||||
|
images: Yup.array().min(1, "Por favor, selecione ao menos uma imagem"), |
||||
}); |
}); |
||||
|
|
||||
const borderWidth = 4; |
const borderWidth = 4; |
||||
|
|
||||
function RiverFloodSharingDataScreen() { |
function RiverFloodSharingDataScreen() { |
||||
const [passable, setPassable] = useState(0); |
|
||||
|
const [riverScale, setRiverScale] = useState(0); |
||||
|
const location = useLocation(); |
||||
|
|
||||
return ( |
|
||||
<Screen style={styles.container}> |
|
||||
<Text style={{ fontSize: 18, fontWeight: 'bold', color: '#1976D2', textAlign: 'center', marginBottom: 30 }}> |
|
||||
Nível da água do rio |
|
||||
</Text> |
|
||||
<Form |
|
||||
initialValues={{ |
|
||||
title: "", |
|
||||
price: "", |
|
||||
description: "", |
|
||||
category: null, |
|
||||
images: [], |
|
||||
}} |
|
||||
onSubmit={(values) => submitForm({ ...values, passable, location })} |
|
||||
validationSchema={validationSchema} |
|
||||
> |
|
||||
<View> |
|
||||
<View |
|
||||
style={{ flexDirection: "row", justifyContent: "space-around" }} |
|
||||
> |
|
||||
<TouchableNativeFeedback onPress={() => setPassable(0)}> |
|
||||
<View |
|
||||
borderWidth={passable == 0 ? borderWidth : 0} |
|
||||
style={styles.img_block} |
|
||||
> |
|
||||
<Image |
|
||||
style={styles.floodingLogo} |
|
||||
source={require("../assets/rio_baixo.png")} |
|
||||
/> |
|
||||
<Text style={styles.text}>Baixo</Text> |
|
||||
</View> |
|
||||
</TouchableNativeFeedback> |
|
||||
|
return ( |
||||
|
<Screen style={styles.container}> |
||||
|
<Text |
||||
|
style={{ |
||||
|
fontSize: 18, |
||||
|
fontWeight: "bold", |
||||
|
color: "#1976D2", |
||||
|
textAlign: "center", |
||||
|
marginBottom: 30, |
||||
|
}} |
||||
|
> |
||||
|
Nível da água do rio |
||||
|
</Text> |
||||
|
<Form |
||||
|
initialValues={{ |
||||
|
images: [], |
||||
|
}} |
||||
|
onSubmit={(values) => |
||||
|
insertRiverData({ ...values, riverScale, location }) |
||||
|
} |
||||
|
validationSchema={validationSchema} |
||||
|
> |
||||
|
<View> |
||||
|
<View |
||||
|
style={{ flexDirection: "row", justifyContent: "space-around" }} |
||||
|
> |
||||
|
<TouchableNativeFeedback onPress={() => setRiverScale(0)}> |
||||
|
<View |
||||
|
borderWidth={riverScale == 0 ? borderWidth : 0} |
||||
|
style={styles.img_block} |
||||
|
> |
||||
|
<Image |
||||
|
style={styles.floodingLogo} |
||||
|
source={require("../assets/rio_baixo.png")} |
||||
|
/> |
||||
|
<Text style={styles.text}>Baixo</Text> |
||||
|
</View> |
||||
|
</TouchableNativeFeedback> |
||||
|
|
||||
<TouchableNativeFeedback onPress={() => setPassable(1)}> |
|
||||
<View |
|
||||
borderWidth={passable == 1 ? borderWidth : 0} |
|
||||
style={styles.img_block} |
|
||||
> |
|
||||
<Image |
|
||||
style={styles.floodingLogo} |
|
||||
source={require("../assets/rio_normal.png")} |
|
||||
/> |
|
||||
<Text style={styles.text}>Rio normal</Text> |
|
||||
</View> |
|
||||
</TouchableNativeFeedback> |
|
||||
</View> |
|
||||
|
<TouchableNativeFeedback onPress={() => setRiverScale(1)}> |
||||
|
<View |
||||
|
borderWidth={riverScale == 1 ? borderWidth : 0} |
||||
|
style={styles.img_block} |
||||
|
> |
||||
|
<Image |
||||
|
style={styles.floodingLogo} |
||||
|
source={require("../assets/rio_normal.png")} |
||||
|
/> |
||||
|
<Text style={styles.text}>Rio normal</Text> |
||||
|
</View> |
||||
|
</TouchableNativeFeedback> |
||||
|
</View> |
||||
|
|
||||
<View |
|
||||
style={{ flexDirection: "row", justifyContent: "space-around" }} |
|
||||
> |
|
||||
<TouchableNativeFeedback onPress={() => setPassable(2)}> |
|
||||
<View |
|
||||
borderWidth={passable == 2 ? borderWidth : 0} |
|
||||
style={styles.img_block} |
|
||||
> |
|
||||
<Image |
|
||||
style={styles.floodingLogo} |
|
||||
source={require("../assets/rio_alto.png")} |
|
||||
/> |
|
||||
<Text style={styles.text}>Alto</Text> |
|
||||
</View> |
|
||||
</TouchableNativeFeedback> |
|
||||
|
<View |
||||
|
style={{ flexDirection: "row", justifyContent: "space-around" }} |
||||
|
> |
||||
|
<TouchableNativeFeedback onPress={() => setRiverScale(2)}> |
||||
|
<View |
||||
|
borderWidth={riverScale == 2 ? borderWidth : 0} |
||||
|
style={styles.img_block} |
||||
|
> |
||||
|
<Image |
||||
|
style={styles.floodingLogo} |
||||
|
source={require("../assets/rio_alto.png")} |
||||
|
/> |
||||
|
<Text style={styles.text}>Alto</Text> |
||||
|
</View> |
||||
|
</TouchableNativeFeedback> |
||||
|
|
||||
<TouchableNativeFeedback onPress={() => setPassable(3)}> |
|
||||
<View |
|
||||
borderWidth={passable == 3 ? borderWidth : 0} |
|
||||
style={styles.img_block} |
|
||||
> |
|
||||
<Image |
|
||||
style={styles.floodingLogo} |
|
||||
source={require("../assets/rio_transbordando.png")} |
|
||||
/> |
|
||||
<Text style={styles.text}>Transbordando</Text> |
|
||||
</View> |
|
||||
</TouchableNativeFeedback> |
|
||||
</View> |
|
||||
</View> |
|
||||
<FormImagePicker backgroundColor="#1976D2" name="images" /> |
|
||||
|
<TouchableNativeFeedback onPress={() => setRiverScale(3)}> |
||||
|
<View |
||||
|
borderWidth={riverScale == 3 ? borderWidth : 0} |
||||
|
style={styles.img_block} |
||||
|
> |
||||
|
<Image |
||||
|
style={styles.floodingLogo} |
||||
|
source={require("../assets/rio_transbordando.png")} |
||||
|
/> |
||||
|
<Text style={styles.text}>Transbordando</Text> |
||||
|
</View> |
||||
|
</TouchableNativeFeedback> |
||||
|
</View> |
||||
|
</View> |
||||
|
<FormImagePicker backgroundColor="#1976D2" name="images" /> |
||||
|
|
||||
<SubmitButton title="Enviar" backgroundColor={colors.primary} /> |
|
||||
</Form> |
|
||||
</Screen> |
|
||||
); |
|
||||
|
<SubmitButton title="Enviar" backgroundColor={colors.primary} /> |
||||
|
</Form> |
||||
|
</Screen> |
||||
|
); |
||||
} |
} |
||||
|
|
||||
const styles = StyleSheet.create({ |
const styles = StyleSheet.create({ |
||||
container: { |
|
||||
padding: 10, |
|
||||
}, |
|
||||
img_block: { |
|
||||
borderRadius: 5, |
|
||||
padding: 10, |
|
||||
borderStyle: "dotted", |
|
||||
borderColor: colors.primary, |
|
||||
alignItems: "center", |
|
||||
width:130, |
|
||||
}, |
|
||||
floodingLogo: { |
|
||||
width: 85, |
|
||||
height: 85, |
|
||||
}, |
|
||||
text: { |
|
||||
fontSize: 14, |
|
||||
textAlign: "center", |
|
||||
marginTop: 10, |
|
||||
}, |
|
||||
|
container: { |
||||
|
padding: 10, |
||||
|
}, |
||||
|
img_block: { |
||||
|
borderRadius: 5, |
||||
|
padding: 10, |
||||
|
borderStyle: "dotted", |
||||
|
borderColor: colors.primary, |
||||
|
alignItems: "center", |
||||
|
width: 130, |
||||
|
}, |
||||
|
floodingLogo: { |
||||
|
width: 85, |
||||
|
height: 85, |
||||
|
}, |
||||
|
text: { |
||||
|
fontSize: 14, |
||||
|
textAlign: "center", |
||||
|
marginTop: 10, |
||||
|
}, |
||||
}); |
}); |
||||
|
|
||||
export default RiverFloodSharingDataScreen; |
export default RiverFloodSharingDataScreen; |
Write
Preview
Loading…
Cancel
Save
Reference in new issue