You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

67 lines
1.6 KiB

import { useEffect, useState } from "react";
import "../config/globals";
const floodZoneAsset = require("../assets/pontos_alagamento_peq.png");
function partsePluviometer(row) {
return {
key: "999",
title: "pluviometro",
coordinate: {
latitude: row["Latitude"] + 0.5,
longitude: row["Longitude"],
},
image: floodZoneAsset,
description: row["Pluviometer"],
};
}
function parseFloodZones(row) {
return {
key: row["Id"],
title: row["Passable"] == 0 ? "Transponível" : "Intransponível",
coordinate: { latitude: row["Latitude"], longitude: row["Longitude"] },
image: floodZoneAsset,
description: row["Description"],
};
}
function parseResult(db_result, parseRow) {
var warnings = [];
for (let i = 0; i < db_result.rows.length; ++i) {
var row = db_result.rows.item(i);
warnings.push(parseRow(row));
}
return warnings;
}
function genericSelect(setState, query, parseFunction) {
useEffect(() => {
global.userDataBase.transaction((tx) => {
tx.executeSql(query, [], (tx, results) => {
setState(parseResult(results, parseFunction));
});
});
}, []);
}
function useFlood() {
const [warnings, setWarnings] = useState([]);
const queryFloodZones = "SELECT * FROM FloodZones;";
genericSelect(setWarnings, queryFloodZones, parseFloodZones);
return warnings;
}
function usePluviometer() {
const [warnings, setWarnings] = useState([]);
const queryPluviometer = "SELECT * FROM Pluviometer;";
genericSelect(setWarnings, queryPluviometer, partsePluviometer);
return warnings;
}
export { useFlood, usePluviometer };