Commit a4f7f641 authored by di-nethra's avatar di-nethra

home screen added

parent 117c1cf5
No preview for this file type
...@@ -5,6 +5,7 @@ import TestWithButton from './components/recomendationComponentsBySoil/TestWithB ...@@ -5,6 +5,7 @@ import TestWithButton from './components/recomendationComponentsBySoil/TestWithB
import SoilDataOptions from './components/recomendationComponentsBySoil/SoilDataOptions'; import SoilDataOptions from './components/recomendationComponentsBySoil/SoilDataOptions';
import ManualSoilData from './components/recomendationComponentsBySoil/ManualSoilData'; import ManualSoilData from './components/recomendationComponentsBySoil/ManualSoilData';
import MostSutaibleCrops from './components/recomendationComponentsBySoil/MostSutaibleCrops'; import MostSutaibleCrops from './components/recomendationComponentsBySoil/MostSutaibleCrops';
import HomePage from './components/common/Home';
...@@ -13,8 +14,9 @@ export default function App() { ...@@ -13,8 +14,9 @@ export default function App() {
return ( return (
<NavigationContainer> <NavigationContainer>
<Stack.Navigator> <Stack.Navigator>
<Stack.Screen name="Home" component={HomePage}/>
<Stack.Screen name="Soil Data Options" component={SoilDataOptions}/> <Stack.Screen name="Soil Data Options" component={SoilDataOptions}/>
<Stack.Screen name="Most Sutaible Crops" component={MostSutaibleCrops}/> <Stack.Screen name="Most Suitable Crops" component={MostSutaibleCrops}/>
<Stack.Screen name="Add Soil Data Manually " component={ManualSoilData}/> <Stack.Screen name="Add Soil Data Manually " component={ManualSoilData}/>
<Stack.Screen name="TestWithButton" component={TestWithButton}/> <Stack.Screen name="TestWithButton" component={TestWithButton}/>
</Stack.Navigator> </Stack.Navigator>
......
import React from 'react';
import { View, Text, TouchableOpacity, StyleSheet, ImageBackground } from 'react-native';
const HomePage = ({ navigation }) => {
const handleOptionSelect = (option) => {
// Handle navigation to the selected option
if (option === 'pestDisease') {
navigation.navigate('PestDiseasePage');
} else if (option === 'soilData') {
navigation.navigate('Soil Data Options');
} else if (option === 'weatherData') {
navigation.navigate('Weather Data Options');
} else if (option === 'cropRotationPlan') {
navigation.navigate('CropRotationPlanPage');
}
};
return (
<ImageBackground source={require('../../assets/homepage.png')} style={styles.backgroundImage}>
<View style={styles.container}>
<TouchableOpacity style={styles.optionButton} onPress={() => handleOptionSelect('pestDisease')}>
<Text style={styles.optionText}>Pest and Disease</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.optionButton} onPress={() => handleOptionSelect('soilData')}>
<Text style={styles.optionText}>Soil Data</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.optionButton} onPress={() => handleOptionSelect('weatherData')}>
<Text style={styles.optionText}>Weather Data</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.optionButton} onPress={() => handleOptionSelect('cropRotationPlan')}>
<Text style={styles.optionText}>Crop Rotation Plan</Text>
</TouchableOpacity>
</View>
</ImageBackground>
);
};
const styles = StyleSheet.create({
backgroundImage: {
flex: 1,
resizeMode: 'cover',
justifyContent: 'center',
},
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
paddingHorizontal: 20,
},
optionButton: {
backgroundColor: '#fff',
borderRadius: 8,
paddingVertical: 20,
marginBottom: 20,
shadowColor: '#000',
shadowOffset: {
width: 0,
height: 2,
},
shadowOpacity: 0.25,
shadowRadius: 3.84,
elevation: 5,
width: '100%', // Set the width to occupy the entire container
},
optionText: {
fontSize: 20,
fontWeight: 'bold',
color: '#000',
textAlign: 'center',
},
});
export default HomePage;
...@@ -18,7 +18,7 @@ const ManualSoilData = ({navigation}) => { ...@@ -18,7 +18,7 @@ const ManualSoilData = ({navigation}) => {
Potassium:parsedPotassiumLevel Potassium:parsedPotassiumLevel
} }
console.log(userNpkData); console.log(userNpkData);
navigation.navigate("Most Sutaible Crops",{userNpkData}) navigation.navigate("Most Suitable Crops",{userNpkData})
}; };
return ( return (
......
...@@ -26,42 +26,31 @@ const cropImages = { ...@@ -26,42 +26,31 @@ const cropImages = {
const MostSuitableCrops = () => { const MostSuitableCrops = () => {
const [cropData, setCropData] = useState(null); const [cropData, setCropData] = useState(null);
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(true); // Set initial loading state to true
const [mapObject,setMapObject]=useState({}); const [mapObject, setMapObject] = useState({});
const route = useRoute(); const route = useRoute();
const { userNpkData } = route.params; const { userNpkData } = route.params;
console.log("inside sutaible",userNpkData);
// setMapObject(data)
// const { userNpkData } = route.params;
// if(data && Object.keys(data).length === 0){ // const handleArduinoClick = async () => {
// setMapObject(userNpkData) // await axios.get('http://192.168.89.241')
// }else{ // .then(res => {
// setMapObject(data) // setCropData(res.data);
// } // })
// .catch(err => {
// console.log(err);
// });
// };
const handleArduinoClick = async () => { useEffect(() => {
const timer = setTimeout(() => {
await axios.get('http://192.168.89.241').then(res=>{ setIsLoading(false);
setCropData(res.data) }, 3000);
}).catch(err=>{
console.log(err);
})
// try {
// const response = await axios.get('http://192.168.89.241');
// const data = response.data;
// setCropData(data);
// console.log(data);
// } catch (error) {
// console.error('Error fetching crop data:', error);
// } finally {
// setIsLoading(false);
// }
};
return () => clearTimeout(timer);
}, []);
useEffect(() => { useEffect(() => {
const fetchCropData = async () => { const fetchCropData = async () => {
setIsLoading(true);
try { try {
const response = await axios.post('http://127.0.0.1:5000/npk-data', { const response = await axios.post('http://127.0.0.1:5000/npk-data', {
N: userNpkData['Nitrogen'], N: userNpkData['Nitrogen'],
...@@ -78,7 +67,9 @@ const MostSuitableCrops = () => { ...@@ -78,7 +67,9 @@ const MostSuitableCrops = () => {
}; };
fetchCropData(); fetchCropData();
}, []); // Empty dependency array to run effect only once on component mount }, []);
return ( return (
<ImageBackground source={BackgroundImage} style={styles.backgroundImage}> <ImageBackground source={BackgroundImage} style={styles.backgroundImage}>
......
import {React,useState} from 'react'; import React, { useState } from 'react';
import { View, TouchableOpacity, Text, StyleSheet, Image } from 'react-native'; import { View, TouchableOpacity, Text, StyleSheet, Image, ActivityIndicator } from 'react-native';
import axios from 'axios'; import axios from 'axios';
const SoilDataOptions = ({navigation}) => { const SoilDataOptions = ({ navigation }) => {
const [cropData, setCropData] =useState (null); const [cropData, setCropData] = useState(null);
const [isLoading, setIsLoading] = useState(false);
const handleArduinoRequest =async()=>{ const handleArduinoRequest = async () => {
console.log("arduino hit"); console.log("arduino hit");
const response = await axios.get('http://192.168.89.241'); setIsLoading(true);
try {
const response = await axios.get('http://192.168.227.241');
const userNpkData = response.data; const userNpkData = response.data;
setCropData(userNpkData); setCropData(userNpkData);
console.log(userNpkData); console.log(userNpkData);
navigation.navigate("Most Sutaible Crops",{userNpkData}) navigation.navigate("Most Suitable Crops", { userNpkData });
} catch (error) {
console.log(error);
} finally {
setIsLoading(false);
}
} }
return ( return (
<View style={styles.container}> <View style={styles.container}>
<Image source={require('../../assets/backgroundSoilData.jpg')} style={styles.backgroundImage} /> <Image source={require('../../assets/backgroudManualData.jpg')} style={styles.backgroundImage} />
{isLoading && (
<View style={styles.loader}>
<ActivityIndicator size="large" color="#3498db" />
<Text style={styles.loaderText}>Getting data from your sensor. Please wait...</Text>
</View>
)}
<View style={styles.buttonContainer}> <View style={styles.buttonContainer}>
<TouchableOpacity style={styles.button} onPress={() => {navigation.navigate("Add Soil Data Manually ")}}> <TouchableOpacity style={styles.button} onPress={() => { navigation.navigate("Add Soil Data Manually ") }}>
<Text style={styles.buttonText}>Add soil data manually</Text> <Text style={styles.buttonText}>Add soil data manually</Text>
</TouchableOpacity> </TouchableOpacity>
<TouchableOpacity style={styles.button} onPress={() => {handleArduinoRequest()}}> <TouchableOpacity style={styles.button} onPress={() => { handleArduinoRequest() }}>
<Text style={styles.buttonText}>Get soil data from sensor</Text> <Text style={styles.buttonText}>Get soil data from sensor</Text>
</TouchableOpacity> </TouchableOpacity>
</View> </View>
...@@ -43,7 +58,6 @@ const styles = StyleSheet.create({ ...@@ -43,7 +58,6 @@ const styles = StyleSheet.create({
left: 0, left: 0,
width: '100%', width: '100%',
height: '100%', height: '100%',
opacity: 0.8,
}, },
buttonContainer: { buttonContainer: {
backgroundColor: 'rgba(255, 255, 255, 0.8)', backgroundColor: 'rgba(255, 255, 255, 0.8)',
...@@ -69,6 +83,23 @@ const styles = StyleSheet.create({ ...@@ -69,6 +83,23 @@ const styles = StyleSheet.create({
fontSize: 16, fontSize: 16,
fontWeight: 'bold', fontWeight: 'bold',
}, },
loader: {
position: 'absolute',
top: 0,
left: 0,
width: '100%',
height: '100%',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'rgba(0, 0, 0, 0.9)',
zIndex: 999,
},
loaderText: {
color: '#fff',
fontSize: 16,
marginTop: 10,
textAlign: 'center',
},
}); });
export default SoilDataOptions; export default SoilDataOptions;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment