diff --git a/Components/AboutInfo.js b/Components/AboutInfo.js
index 0c87c3a..c26fc5f 100644
--- a/Components/AboutInfo.js
+++ b/Components/AboutInfo.js
@@ -1,30 +1,13 @@
-import React, { useState, useEffect, useCallback } from "react";
+import React from "react";
import {
View,
StyleSheet,
Text,
} from "react-native";
import { Divider } from "react-native-elements";
-import AsyncStorage from "@react-native-async-storage/async-storage";
import { FontAwesome } from "@expo/vector-icons";
-const AboutInfo = () => {
- const [status, setStatus] = useState(true);
- const [userData, setUserData] = useState({});
-
- useEffect(() => {
- getUserData();
- }, [])
-
-
- const getUserData = useCallback(() => {
-
- AsyncStorage.getItem("userData").then((value) => {
- let parseData = JSON.parse(value);
- setUserData(parseData);
- });
-
- }, [])
+const AboutInfo = ({userData}) => {
const username = (name) => {
var str = name;
@@ -49,15 +32,11 @@ const AboutInfo = () => {
- {status ? (
+
{username(userData.name)}
- ) : (
-
-
-
- )}
+
diff --git a/Components/History.js b/Components/History.js
new file mode 100644
index 0000000..53e83aa
--- /dev/null
+++ b/Components/History.js
@@ -0,0 +1,161 @@
+import { StyleSheet, Text, View, FlatList, ActivityIndicator, TouchableOpacity } from 'react-native'
+import React, { useEffect, useState } from 'react'
+import { FontAwesome } from '@expo/vector-icons';
+import { Divider } from "react-native-elements";
+
+const History = ({ token }) => {
+
+ const [loading, setLoading] = useState();
+ const [historyData, setHistoryData] = useState([]);
+
+ const parameters = ['Nitrogen(N)', 'Phosphorus(P)', 'Potassium(K)', 'Avg. Temperature', 'Avg. Humidity', 'pH', 'Avg. Rainfall']
+
+ useEffect(() => {
+ fetchHistory();
+ }, [])
+
+ const fetchHistory = () => {
+ setLoading(true);
+ var myHeaders = new Headers();
+ myHeaders.append("Authorization", `Bearer ${token}`);
+
+ var requestOptions = {
+ method: 'GET',
+ headers: myHeaders,
+ redirect: 'follow'
+ };
+
+ fetch("https://growmoreweb.herokuapp.com/v1/model/history", requestOptions)
+ .then((response) => {
+ // if (response.ok)
+ return response.json()
+ // else
+ // throw 'Fetch History API error : ' + response.status;
+ })
+ .then(result => setHistoryData(result.history))
+ .finally(() => setLoading(false))
+ .catch(error => console.log(error));
+ }
+ console.log(historyData)
+
+ const renderItem = ({ item, index }) => {
+
+ return (
+
+
+ {
+ parameters.map((i, idx) => (
+ {`${i}: ${item.details[idx]}`}
+ ))
+ }
+
+
+ {item.cropSuggested}
+
+
+
+ )
+ }
+
+ return (
+
+
+
+
+ History
+
+ fetchHistory()}>
+
+
+
+
+
+ Parameters
+ Crop Recommended
+
+
+ {
+ loading ?
+ :
+ historyData.length === 0 ?
+ No Data Found !
+ : item._id}
+ renderItem={renderItem}
+ />
+ }
+
+ )
+}
+
+export default History
+
+const styles = StyleSheet.create({
+ cardView: {
+ width: "95%",
+ backgroundColor: "white",
+ alignSelf: "center",
+ // minHeight:'65%',
+ flex:1,
+ padding: 1,
+ marginHorizontal: 10,
+ marginBottom:10,
+ borderRadius: 10,
+ shadowColor: "#000",
+ shadowOffset: {
+ width: 0,
+ height: 2,
+ },
+ shadowOpacity: 0.25,
+ shadowRadius: 10,
+
+ elevation: 5,
+ },
+ container: {
+ flex: 1,
+ backgroundColor: '#fff',
+ padding: 10
+ },
+ emptyDataText: {
+ flex: 1,
+ backgroundColor: '#fff',
+ alignItems: 'center',
+ justifyContent: 'center',
+ },
+ historyItems:{
+ margin:5,
+ flexDirection:'row',
+ padding:5,
+ justifyContent:'space-between',
+ borderBottomColor:'#707070',
+ borderBottomWidth:0.5,
+ },
+ headingIcon: {
+ flexDirection: "row",
+ justifyContent:'space-between',
+ padding: 10,
+ },
+ cvHeading: {
+ color: "#707070",
+ marginLeft: 5,
+ fontSize: 18,
+ },
+ parametersText:{
+ fontSize:16,
+ fontWeight:'700',
+ color:'#909090'
+ },
+ headingText:{
+ fontSize:16,
+ fontWeight:'bold',
+ color:'black'
+ },
+ cropText:{
+ fontSize:16,
+ fontWeight:'bold',
+ color:'#0cac75'
+ }
+
+
+})
\ No newline at end of file
diff --git a/Navigation/GrowMoreNavigation.js b/Navigation/GrowMoreNavigation.js
index c7e4685..cebb666 100644
--- a/Navigation/GrowMoreNavigation.js
+++ b/Navigation/GrowMoreNavigation.js
@@ -52,13 +52,14 @@ export const TabNavigation = (props) => {
return (
({
+
tabBarIcon: ({ focused, color, size }) => {
let iconName;
if (route.name === "News") {
iconName = focused ? "newspaper-variant" : "newspaper-variant-outline";
} else if (route.name === "Recommender") {
iconName = focused ? "thumb-up" : "thumb-up-outline";
- } else if (route.name === "Dashboard") {
+ } else if (route.name === "Dashboard") {
iconName = focused ? "view-dashboard" : "view-dashboard-outline";
}
@@ -70,18 +71,15 @@ export const TabNavigation = (props) => {
/>
);
},
+ tabBarHideOnKeyboard: true,
+ tabBarActiveTintColor: "#2b5c4c",
+ tabBarInactiveTintColor: "grey",
+ tabBarStyle: [
+ {
+ display: "flex"
+ },]
})}
- tabBarOptions={{
- keyboardHidesTabBar: true,
- style: {
- backgroundColor: "white",
- justifyContent: "center",
- alignItems: "center",
- alignSelf: "center",
- },
- activeTintColor: "#2b5c4c",
- inactiveTintColor: "grey",
- }}
+
>
{
headerTitleStyle: { color: "#fff" },
}}
/>
-
+
{
}
}, [weatherData])
-
+
+
const getWeatherData = async () => {
setLoading('weatherFetching');
@@ -211,7 +212,7 @@ const CropRecommender = ({ navigation }) => {
setPredictedCrop(result.prediction);
setCropVisible(true);
setLoading(false);
-
+ saveHistory(result.prediction);
})
.catch(error => console.log('error', error));
@@ -219,17 +220,15 @@ const CropRecommender = ({ navigation }) => {
}
- const saveHistory = () => {
+ const saveHistory = (crop) => {
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Authorization", `Bearer ${accessToken}`);
- console.log(`Bearer ${accessToken}`)
-
+
var raw = JSON.stringify({
"details": [nitrogen, phosphorus, potassium, temperature.toString(), humidity.toString(), pH, rainfall.toString()],
- "cropSuggested": predictedCrop
+ "cropSuggested": crop
});
- console.log(raw)
var requestOptions = {
method: 'POST',
@@ -240,12 +239,12 @@ const CropRecommender = ({ navigation }) => {
fetch("https://growmoreweb.herokuapp.com/v1/model/history", requestOptions)
.then((response) => {
- // if (response.ok)
+ if (response.ok)
return response.json()
- // else
- // throw 'History API error : ' + response.status;
+ else
+ throw 'History API error : ' + response.status;
})
- .then(result => console.log(result))
+ .then(result => console.log("history success"))
.catch(error => console.warn(error));
}
@@ -274,7 +273,7 @@ const CropRecommender = ({ navigation }) => {
editable={!(loading === 'toWeather')}
onChangeText={(text) => setPhosphorus(text)}
value={phosphorus}
- placeholder="Enter value of Nitrogen"
+ placeholder="Enter value of Phosphorus"
autoCapitalize="none"
keyboardType="numeric"
/>
@@ -285,7 +284,7 @@ const CropRecommender = ({ navigation }) => {
editable={!(loading === 'toWeather')}
onChangeText={(text) => setPotassium(text)}
value={potassium}
- placeholder="Enter value of Nitrogen"
+ placeholder="Enter value of Potassium"
autoCapitalize="none"
keyboardType="numeric"
/>
@@ -295,7 +294,7 @@ const CropRecommender = ({ navigation }) => {
editable={!(loading === 'toWeather')}
onChangeText={(text) => setpH(text)}
value={pH}
- placeholder="Enter value of Nitrogen"
+ placeholder="Enter value of pH"
autoCapitalize="none"
keyboardType="numeric"
/>
diff --git a/Screens/Dashboard.js b/Screens/Dashboard.js
index db6a25a..5c9ed31 100644
--- a/Screens/Dashboard.js
+++ b/Screens/Dashboard.js
@@ -1,18 +1,42 @@
-import React from 'react'
+import React, { useState, useEffect, useCallback } from 'react'
import { StyleSheet, View, TouchableOpacity, Alert, ScrollView } from 'react-native'
import AboutInfo from '../Components/AboutInfo';
+import History from '../Components/History';
+import AsyncStorage from "@react-native-async-storage/async-storage";
const Dashboard = () => {
+
+ const [userData, setUserData] = useState({});
+
+ useEffect(() => {
+ getUserData();
+ }, [])
+
+
+ const getUserData = useCallback(() => {
+
+ AsyncStorage.getItem("userData").then((value) => {
+ let parseData = JSON.parse(value);
+ setUserData(parseData);
+ });
+
+ }, [])
return (
-
-
-
-
-
+
+ {/* */}
+
+
+
+ {/* */}
)
}
export default Dashboard
-const styles = StyleSheet.create({})
+const styles = StyleSheet.create({
+ container:{
+ flex:1,
+ backgroundColor:'#fff'
+ }
+})
diff --git a/Screens/LoginPage.js b/Screens/LoginPage.js
index 0783092..cfe985e 100644
--- a/Screens/LoginPage.js
+++ b/Screens/LoginPage.js
@@ -69,7 +69,7 @@ const LoginPage = ({ navigation }) => {
if (response.ok)
return response.json()
else
- throw 'SignUp API error : ' + response.status;
+ throw 'Login API error : ' + response.status;
})
.then((result) => {
diff --git a/Screens/SignUpPage.js b/Screens/SignUpPage.js
index 34ea5f1..1a27a04 100644
--- a/Screens/SignUpPage.js
+++ b/Screens/SignUpPage.js
@@ -24,14 +24,7 @@ const SignUpPage = ({ navigation }) => {
const [email, setEmail] = useState("")
const [passHidden, setPassHidden] = useState(true);
const [loading, setLoading] = useState();
- const { login } = React.useContext(AuthContext);
-
- const saveDataToStorage = async (userName, userEmail, accessToken) => {
- await AsyncStorage.setItem(
- "userData",
- JSON.stringify({ name: userName, email: userEmail, token: accessToken, Status: 'success' })
- );
- };
+
const SubmitSignUp = () => {
if (!name) {
showMessage({
@@ -83,13 +76,12 @@ const SignUpPage = ({ navigation }) => {
.then(result => {
showMessage({
- message: "Signed Up Successfully !",
+ message: "Signed Up Successfully, Please login now!",
type: "success",
icon: "success",
duration: 3500,
});
- saveDataToStorage(result.user.name, result.user.email, result.tokens.access.token)
- login()
+ navigation.navigate('LoginPage');
})
.finally(() => setLoading(false))