GabrielTrettel
4 years ago
3 changed files with 57 additions and 28 deletions
@ -0,0 +1,46 @@ |
|||
import { useEffect, useState } from "react"; |
|||
import "../config/globals"; |
|||
|
|||
const floodZoneAsset = require("../assets/pontos_alagamento_peq.png"); |
|||
|
|||
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 useSelect() { |
|||
const [warnings, setWarnings] = useState([]); |
|||
const query = "SELECT * FROM FloodZones;"; |
|||
|
|||
genericSelect(setWarnings, query, parseFloodZones); |
|||
|
|||
return warnings; |
|||
} |
|||
|
|||
export default useSelect; |
Write
Preview
Loading…
Cancel
Save
Reference in new issue