Browse Source

River form with "Descrição" field.

master
GabrielTrettel 4 years ago
parent
commit
5c060b78a7
  1. 10
      src/app/database/databaseLoader.js
  2. 2
      src/app/database/db.js
  3. 8
      src/app/hooks/selectFromDB.js
  4. 17
      src/app/screens/RiverFloodSharingDataScreen.js

10
src/app/database/databaseLoader.js

@ -55,8 +55,8 @@ function insertPluviometerData({ pluviometer, images, dateTime, location }) {
transaction(global.userDataBase, query, values);
}
function insertRainData({ images, rain, location }) {
const query = `INSERT INTO RainLevel(RainIdx, Images, Latitude, Longitude) VALUES(?, ?, ?, ?);`;
function insertRainData({ images, description, rain, location }) {
const query = `INSERT INTO RainLevel(RainIdx, Description, Images, Latitude, Longitude) VALUES(?, ?, ?, ?, ?);`;
if (location === undefined) {
console.debug("undefined location");
@ -65,6 +65,7 @@ function insertRainData({ images, rain, location }) {
const values = [
parseInt(rain),
description,
JSON.stringify(images),
parseFloat(location["latitude"]),
parseFloat(location["longitude"]),
@ -75,8 +76,8 @@ function insertRainData({ images, rain, location }) {
transaction(global.userDataBase, query, values);
}
function insertRiverData({ images, riverScale, location }) {
const query = `INSERT INTO RiverLevel(RiverIdx, Images, Latitude, Longitude) VALUES(?, ?, ?, ?);`;
function insertRiverData({ images, description, riverScale, location }) {
const query = `INSERT INTO RiverLevel(RiverIdx, Description, Images, Latitude, Longitude) VALUES(?, ?, ?, ?, ?);`;
if (location === undefined) {
console.debug("undefined location");
@ -85,6 +86,7 @@ function insertRiverData({ images, riverScale, location }) {
const values = [
parseInt(riverScale),
description,
JSON.stringify(images),
parseFloat(location["latitude"]),
parseFloat(location["longitude"]),

2
src/app/database/db.js

@ -19,6 +19,7 @@ const init_queries = [
);`,
`CREATE TABLE IF NOT EXISTS RainLevel (
Id integer PRIMARY KEY autoincrement,
Description text,
RainIdx INTEGER NOT NULL,
Images text,
Latitude real NOT NULL,
@ -26,6 +27,7 @@ const init_queries = [
);`,
`CREATE TABLE IF NOT EXISTS RiverLevel (
Id integer PRIMARY KEY autoincrement,
Description text,
RiverIdx INTEGER NOT NULL,
Images text,
Latitude real NOT NULL,

8
src/app/hooks/selectFromDB.js

@ -89,19 +89,19 @@ function parseRiverLevel(row) {
if (!is_valid(row["Id"], "river")) {
return null;
}
console.log(JSON.stringify(row));
displacement += offset;
const riverLevel = ["Baixo", "Rio normal", "Alto", "Transbordando"];
const riverLevel = ["baixo", "normal", "alto", "transbordando"];
const riverIdx = row["RiverIdx"];
return {
ID: ++ID,
title: "Nível do rio",
title: "Rio" + riverLevel[riverIdx],
coordinate: {
latitude: row["Latitude"],
longitude: row["Longitude"] + displacement,
},
image: custom_assets.riverLevel[riverIdx],
description: riverLevel[riverIdx],
description: row["Description"],
};
}

17
src/app/screens/RiverFloodSharingDataScreen.js

@ -2,7 +2,12 @@ import React, { useState } from "react";
import { StyleSheet, View } from "react-native";
import * as Yup from "yup";
import { Form, FormPicker as Picker, SubmitButton } from "../components/forms";
import {
Form,
FormPicker as Picker,
SubmitButton,
FormField,
} from "../components/forms";
import Screen from "../components/Screen";
import FormImagePicker from "../components/forms/FormImagePicker";
import useLocation from "../hooks/useLocation";
@ -17,6 +22,7 @@ import { scaleDimsFromWidth, dimensions } from "../config/dimensions";
const validationSchema = Yup.object().shape({
images: Yup.array(),
description: Yup.string().label("Description"),
});
const borderWidth = 4;
@ -46,6 +52,7 @@ function RiverFloodSharingDataScreen(props) {
<Form
initialValues={{
images: [],
description: "",
}}
onSubmit={(values) => {
if (riverScale == -1) {
@ -126,7 +133,13 @@ function RiverFloodSharingDataScreen(props) {
)}
<FormImagePicker backgroundColor={colors.primary} name="images" />
<FormField
maxLength={255}
multiline
name="description"
numberOfLines={3}
placeholder="Descrição"
/>
<SubmitButton title="Enviar" backgroundColor={colors.primary} />
</Form>
</KeyboardAwareScrollView>

Loading…
Cancel
Save