From 83057cf4466425cc41099e777c4260bb71aabe6d Mon Sep 17 00:00:00 2001 From: PavelSilviu Date: Wed, 1 Jun 2022 20:27:42 +0300 Subject: [PATCH 1/2] numeric keyboard MH+ spelling check CA&CU --- Frontend/screens/CarAdd.js | 34 ++++++++------ Frontend/screens/CarUpdate.js | 12 ++--- Frontend/screens/MapHomeScreen.js | 78 +++++++++++++++++++++++++------ 3 files changed, 91 insertions(+), 33 deletions(-) diff --git a/Frontend/screens/CarAdd.js b/Frontend/screens/CarAdd.js index 401c4c9..30646ba 100644 --- a/Frontend/screens/CarAdd.js +++ b/Frontend/screens/CarAdd.js @@ -53,7 +53,7 @@ eroare = { validForm = () => { //Eroare nume if (this.state.nume.length > 11) { - this.eroare.camp1 = "Maxim 10 caractere" + this.eroare.camp1 = "Maximum 10 characters" } else { this.eroare.camp1 = '' @@ -61,27 +61,33 @@ eroare = { //Eroare distanta var n = Number(this.state.distantaMax); if (isNaN(n)) { - this.eroare.camp2 = "Distanta gresita" + this.eroare.camp2 = "Wrong autonomy" } else { this.eroare.camp2 = '' } if (this.state.distantaMax[0] == '0') { - this.eroare.camp2 = "Distanta gresita" + this.eroare.camp2 = "Wrong distance" } //Eroare baterie n = Number(this.state.capacBaterie) if (this.state.capacBaterie.length > 6 || (isNaN(n) || this.state.capacBaterie[0] == '0')) { - this.eroare.camp3 = "Valoare gresita" + this.eroare.camp3 = "Wrong capacity" } else { this.eroare.camp3 = '' } //Eroare culoare + if (this.state.culoare.length > 11) { + this.eroare.camp4 = "Maximum 10 characters" + } + else { + this.eroare.camp4 = '' + } //Eroare nrkm n = Number(this.state.numarKm) if (isNaN(n) || (this.state.numarKm[0] == '0' && this.state.numarKm.length > 1)) { - this.eroare.camp5 = "Kilometraj gresit" + this.eroare.camp5 = "Wrong kilometers" } else { this.eroare.camp5 = '' @@ -89,11 +95,11 @@ eroare = { //Eroare CaiPutere n = Number(this.state.caiPutere) if (isNaN(n) == true) { - this.eroare.camp6 = "Valoare gresita" + this.eroare.camp6 = "Wrong value" } else { if (n < 50 && (this.state.caiPutere != '')) { - this.eroare.camp6 = "Valoare prea mica" + this.eroare.camp6 = "The value is too low" } else { this.eroare.camp6 = '' @@ -111,13 +117,13 @@ eroare = { fara_erori = 1; } if ((fara_erori == 1) && (campuri_necompletate == 0)) { - alert("Succer"); + alert("Succes"); } if (campuri_necompletate == 1) { - alert("Campuri necompletate"); + alert("No completed fields"); } if (fara_erori == 0) { - alert("Erori"); + alert("Errors"); } console.log(this.state) } @@ -173,7 +179,7 @@ eroare = { placeholderTextColor = "white" autoCapitalize = "none" onChangeText = {this.handleculoare}/> - {this.validForm() ? {this.eroare.camp5} : null} + {this.validForm() ? {this.eroare.camp4} : null} @@ -183,7 +189,7 @@ eroare = { placeholderTextColor = "white" autoCapitalize = "none" onChangeText = {this.handlenumarKm}/> - {this.validForm() ? {this.eroare.camp6} : null} + {this.validForm() ? {this.eroare.camp5} : null} @@ -192,8 +198,8 @@ eroare = { placeholder = "Horse power" placeholderTextColor = "white" autoCapitalize = "none" - onChangeText = {this.handlecaiPutere}/> - + onChangeText = {this.handlecaiPutere}/> + {this.validForm() ? {this.eroare.camp6} : null} { pointB.longitude + "&key=" + GOOGLE_MAPS_APIKEY; - try { - const res = await fetch(urlToFetchDistance); - const data = await res.json(); - return data.rows[0].elements[0].distance.value; - } catch(e) { - console.error(e); - return null; - } + + const res = await fetch(urlToFetchDistance); + const data = await res.json(); + return data.rows[0].elements[0].distance.value; }; const MapHomeScreen = ({ navigation }) => { @@ -74,7 +69,6 @@ const MapHomeScreen = ({ navigation }) => { const [showTheThing, setShow] = useState(false); const [autonomy, setAutonomy] = useState(""); const [dest, setDest] = useState({}); - const isFocused = useIsFocused(); const getLocation = async () => { const { status } = await Location.requestForegroundPermissionsAsync(); @@ -99,17 +93,74 @@ const MapHomeScreen = ({ navigation }) => { getAllStations() .then((res) => { dispatch(setStations(res.data.result)); - console.log("all station2") + const func = async () => { + let stationsAux = []; + let distancesAux = []; + + let counter = 0; + + const location = await Location.getLastKnownPositionAsync(); + const statii = res.data.result; + for (const station of statii) { + let dist; + //console.log(station?._fieldsProto?.coordinates?.geoPointValue); + if (station?._fieldsProto?.coordinates?.geoPointValue == undefined) + dist = 99999999; + else { + if ( + station?._fieldsProto?.coordinates?.geoPointValue !== undefined + ) { + dist = await getDistanceBetweenPoints( + station._fieldsProto.coordinates.geoPointValue, + location.coords + ); + } + } + + if (counter < 3) { + stationsAux[counter] = station; + + distancesAux[counter] = dist; + } else if (dist < distancesAux[0]) { + distancesAux[0] = dist; + stationsAux[0] = station; + } else if (dist < distancesAux[1]) { + distancesAux[1] = dist; + stationsAux[1] = station; + } else if (dist < distancesAux[2]) { + distancesAux[2] = dist; + stationsAux[2] = station; + } + counter = counter + 1; + } + + for (i = 0; i < 3; i++) { + stationsAux[i] = stationsAux[i]._fieldsProto; + let aux1 = {}; + for (const prop in stationsAux[i]) { + aux1[prop] = stationsAux[i][prop]; + } + aux1["distance"] = { + doubleValue: distancesAux[i], + valueType: "doubleValue", + }; + + stationsAux[i] = aux1; + } + dispatch(setNearByStaions(stationsAux)); + }; + + func(); }) .catch((err) => { //console.log("getAllStations: Map.js"); console.log("err"); }); - }, [isFocused]); + }, []); useEffect(() => { getLocation(); - }, [isFocused]); + }, []); return ( @@ -176,6 +227,7 @@ const MapHomeScreen = ({ navigation }) => { style={styles.input} underlineColorAndroid="transparent" placeholder="Introduce battery autonomy.." + keyboardType = 'numeric' placeholderTextColor="white" autoCapitalize="none" onChangeText={(text) => setAutonomy(text)} From 4e75ea7ba16f92a964cdd192d584ff649a07a2aa Mon Sep 17 00:00:00 2001 From: PavelSilviu Date: Wed, 1 Jun 2022 20:30:32 +0300 Subject: [PATCH 2/2] numeric keyboard MH v2 --- Frontend/screens/MapHomeScreen.js | 81 ++++++------------------------- 1 file changed, 15 insertions(+), 66 deletions(-) diff --git a/Frontend/screens/MapHomeScreen.js b/Frontend/screens/MapHomeScreen.js index 20a3e3c..36541f2 100644 --- a/Frontend/screens/MapHomeScreen.js +++ b/Frontend/screens/MapHomeScreen.js @@ -38,6 +38,7 @@ import deletee from "../assets/delete.png"; import { PressabilityDebugView } from "react-native/Libraries/Pressability/PressabilityDebug"; import Pressable from "react-native/Libraries/Components/Pressable/Pressable"; import { TouchableOpacity } from "react-native"; +import { useIsFocused } from "@react-navigation/native"; const GOOGLE_MAPS_APIKEY = Constants.manifest.web.config.gmaps_api_key; @@ -53,10 +54,14 @@ export const getDistanceBetweenPoints = async (pointA, pointB) => { pointB.longitude + "&key=" + GOOGLE_MAPS_APIKEY; - - const res = await fetch(urlToFetchDistance); - const data = await res.json(); - return data.rows[0].elements[0].distance.value; + try { + const res = await fetch(urlToFetchDistance); + const data = await res.json(); + return data.rows[0].elements[0].distance.value; + } catch(e) { + console.error(e); + return null; + } }; const MapHomeScreen = ({ navigation }) => { @@ -69,6 +74,7 @@ const MapHomeScreen = ({ navigation }) => { const [showTheThing, setShow] = useState(false); const [autonomy, setAutonomy] = useState(""); const [dest, setDest] = useState({}); + const isFocused = useIsFocused(); const getLocation = async () => { const { status } = await Location.requestForegroundPermissionsAsync(); @@ -93,74 +99,17 @@ const MapHomeScreen = ({ navigation }) => { getAllStations() .then((res) => { dispatch(setStations(res.data.result)); - const func = async () => { - let stationsAux = []; - let distancesAux = []; - - let counter = 0; - - const location = await Location.getLastKnownPositionAsync(); - const statii = res.data.result; - for (const station of statii) { - let dist; - //console.log(station?._fieldsProto?.coordinates?.geoPointValue); - if (station?._fieldsProto?.coordinates?.geoPointValue == undefined) - dist = 99999999; - else { - if ( - station?._fieldsProto?.coordinates?.geoPointValue !== undefined - ) { - dist = await getDistanceBetweenPoints( - station._fieldsProto.coordinates.geoPointValue, - location.coords - ); - } - } - - if (counter < 3) { - stationsAux[counter] = station; - - distancesAux[counter] = dist; - } else if (dist < distancesAux[0]) { - distancesAux[0] = dist; - stationsAux[0] = station; - } else if (dist < distancesAux[1]) { - distancesAux[1] = dist; - stationsAux[1] = station; - } else if (dist < distancesAux[2]) { - distancesAux[2] = dist; - stationsAux[2] = station; - } - counter = counter + 1; - } - - for (i = 0; i < 3; i++) { - stationsAux[i] = stationsAux[i]._fieldsProto; - let aux1 = {}; - for (const prop in stationsAux[i]) { - aux1[prop] = stationsAux[i][prop]; - } - aux1["distance"] = { - doubleValue: distancesAux[i], - valueType: "doubleValue", - }; - - stationsAux[i] = aux1; - } - dispatch(setNearByStaions(stationsAux)); - }; - - func(); + console.log("all station2") }) .catch((err) => { //console.log("getAllStations: Map.js"); console.log("err"); }); - }, []); + }, [isFocused]); useEffect(() => { getLocation(); - }, []); + }, [isFocused]); return ( @@ -227,8 +176,8 @@ const MapHomeScreen = ({ navigation }) => { style={styles.input} underlineColorAndroid="transparent" placeholder="Introduce battery autonomy.." - keyboardType = 'numeric' placeholderTextColor="white" + keyboardType = 'numeric' autoCapitalize="none" onChangeText={(text) => setAutonomy(text)} /> @@ -315,4 +264,4 @@ const styles = StyleSheet.create({ }, }); -export default MapHomeScreen; +export default MapHomeScreen; \ No newline at end of file