Update DB Connection & Other changes

parent 7486cb3f
......@@ -2,15 +2,15 @@ import firebase from 'firebase/compat/app';
import { getDatabase } from 'firebase/database';
const firebaseConfig = {
apiKey: "AIzaSyCGepr7j41wWYOcq2KgfT2TU9U7ye723Ko",
authDomain: "researchproject-ded92.firebaseapp.com",
databaseURL: "https://researchproject-ded92-default-rtdb.asia-southeast1.firebasedatabase.app",
projectId: "researchproject-ded92",
storageBucket: "researchproject-ded92.appspot.com",
messagingSenderId: "315494030749",
appId: "1:315494030749:web:4f25e1e9f44228e2b02374",
measurementId: "G-52Y793E4LV"
}
apiKey: "AIzaSyCr8EgrdjVYrI936R0MY2xTdNvLW9d_IVc",
authDomain: "research-4aa0d.firebaseapp.com",
databaseURL: "https://research-4aa0d-default-rtdb.firebaseio.com",
projectId: "research-4aa0d",
storageBucket: "research-4aa0d.appspot.com",
messagingSenderId: "953444486465",
appId: "1:953444486465:web:68681174589c1d1c54e5c0",
measurementId: "G-SDEQKTS8D4"
}
if (firebase.apps.length === 0){
firebase.initializeApp(firebaseConfig);
......
import { View, Text, StyleSheet, TextInput, Button, Image } from 'react-native'
import React, { useState } from 'react'
import { db } from '../config'
import { ref, set } from 'firebase/database'
const AddData = () => {
const [title, setTitle] = useState('');
const [body, setBody] = useState('');
//function to add data to forebase realtime db
const dataAddOn = () => {
set(ref(db, 'posts/' + title),{
title: title,
body: body,
});
setTitle('')
setBody('')
}
return (
<View style={styles.container}>
<Text style={styles.header}>STRESS TRACKER </Text>
<Image
source={require('../images/Home.jpg')}
style={styles.image}
/>
<TextInput
placeholder='Job Satisfication'
value={title}
onChangeText={(text) => setTitle(text)}
style={styles.input}
/>
<TextInput
placeholder='Body'
value={body}
onChangeText={(text) => setBody(text)}
style={styles.input}
/>
<Button
title='Add Data'
onPress={dataAddOn}
/>
</View>
)
}
export default AddData
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
},
header:{
fontSize:40,
textAlign:'center',
marginTop:50,
color:'black',
fontWeight: 'bold'
},
input:{
borderWidth:1,
borderColor:'black',
margin:10,
padding:10,
fontSize:18,
borderRadius:6,
},
image: {
width: '100%',
height: 200,
}
});
\ No newline at end of file
import React from 'react';
import { View, Text, StyleSheet, TouchableOpacity, Image } from 'react-native';
import { View, Text, StyleSheet, TextInput, Button, Image } from 'react-native'
import React, { useState } from 'react'
import { db } from '../config'
import { ref, set } from 'firebase/database'
const AddData = () => {
const [Job_Satisfaction, setTitle] = useState('');
const [Sleep_Hours, setSleepHours] = useState('');
const [Additional_Text, setText] = useState('');
// function to update data in Firebase Realtime DB
const updateData = () => {
const jobSatisfactionValue = parseInt(Job_Satisfaction);
const sleepHoursValue = parseInt(Sleep_Hours);
if (!isNaN(jobSatisfactionValue) && !isNaN(sleepHoursValue)) {
const postData = {
Job_Satisfaction: jobSatisfactionValue,
Sleep_Hours: sleepHoursValue,
Text: Additional_Text,
isNew: false
};
set(ref(db, 'live_data'), postData);
} else {
console.error("Invalid input for Job Satisfaction or Sleep Hours. Please enter valid numbers.");
}
}
const NewJournalEntry = ({ onGoBack }) => {
return (
<View style={styles.container}>
<View style={styles.rectangle}>
<Text style={styles.text}>HELLO SHASHINI !{'\n'}WHAT WOULD YOU LIKE TO DO?</Text>
<TouchableOpacity style={styles.button} onPress={onGoBack}>
<Text style={styles.buttonText}>Go Back</Text>
</TouchableOpacity>
<View style={styles.innerRectangle}>
<Text style={styles.whiteText}>Journal Entry</Text>
<Text style={styles.header}>STRESS TRACKER </Text>
<Image
source={require('../images/redCircle.png')}
style={styles.backgroundImage}
source={require('../images/Home.jpg')}
style={styles.image}
/>
<View style={styles.innerRectangle1}>
<Text style={styles.whiteText}>View History</Text>
<Image
source={require('../images/historyicon.png')}
style={styles.backgroundImage}
<TextInput
placeholder='Job Satisfaction'
value={Job_Satisfaction}
onChangeText={(text) => setTitle(text)}
style={styles.input}
keyboardType='numeric'
/>
<TextInput
placeholder='Sleep hours'
value={Sleep_Hours}
onChangeText={(text) => setSleepHours(text)}
style={styles.input}
keyboardType='numeric'
/>
<TextInput
placeholder='Additional text'
value={Additional_Text}
onChangeText={(text) => setText(text)}
style={styles.input}
/>
<Button
title='Update Data'
onPress={updateData}
/>
</View>
)
}
<View style={styles.innerRectangle2}>
<Text style={styles.whiteText1}>MOOD HISTORY {'\n'}</Text>
<View style={styles.daysContainer}>
<View style={styles.dayContainer}>
<Text style={styles.emoji}>😊</Text>
<Text style={styles.dayText}>Mon</Text>
</View>
<View style={styles.dayContainer}>
<Text style={styles.emoji}>😊</Text>
<Text style={styles.dayText}>Tue</Text>
</View>
<View style={styles.dayContainer}>
<Text style={styles.emoji}>😊</Text>
<Text style={styles.dayText}>Wed</Text>
</View>
<View style={styles.dayContainer}>
<Text style={styles.emoji}>😊</Text>
<Text style={styles.dayText}>Thu</Text>
</View>
<View style={styles.dayContainer}>
<Text style={styles.emoji}>😊</Text>
<Text style={styles.dayText}>Fri</Text>
</View>
<View style={styles.dayContainer}>
<Text style={styles.emoji}>😊</Text>
<Text style={styles.dayText}>Sat</Text>
</View>
<View style={styles.dayContainer}>
<Text style={styles.emoji}>😊</Text>
<Text style={styles.dayText}>Sun</Text>
</View>
</View>
</View>
</View>
</View>
</View>
);
};
export default AddData
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
rectangle: {
width: 320,
height: 650,
justifyContent: 'space-between',
alignItems: 'center',
borderColor: 'black',
borderWidth: 1,
borderRadius: 10,
padding: 30,
backgroundColor:'#FDEDEC',
},
text: {
marginLeft: -70,
},
button: {
backgroundColor: 'blue',
paddingVertical: 10,
paddingHorizontal: 20,
borderRadius: 5,
alignSelf: 'flex-end',
},
buttonText: {
color: 'white',
fontWeight: 'bold',
},
innerRectangle: {
width: 130,
height: 100,
borderColor: '#F1948A',
borderWidth: 1,
borderRadius: 10,
marginTop: -600,
top:-410,
marginLeft:-150,
backgroundColor: '#F1948A',
backgroundColor: '#fff',
},
innerRectangle1: {
width: 130,
height: 100,
borderColor: '#F1948A',
borderWidth: 1,
borderRadius: 10,
top:-85,
marginLeft:150,
backgroundColor: '#F1948A',
header:{
fontSize:40,
textAlign:'center',
marginTop:50,
color:'black',
fontWeight: 'bold'
},
innerRectangle2: {
width: 300,
height: 120,
borderColor: 'white',
borderWidth: 1,
borderRadius: 12,
top:-70,
marginLeft:-10,
backgroundColor: 'white',
paddingTop: 10,
alignItems: 'center',
input:{
borderWidth:1,
borderColor:'black',
margin:10,
padding:10,
fontSize:18,
borderRadius:6,
},
whiteText: {
color: 'white',
textAlign: 'center',
fontWeight: 'bold',
fontSize: 18,
},
whiteText1: {
color:'#E74C3C',
fontWeight: 'bold',
fontSize: 15,
},
backgroundImage: {
width: 60,
height: 60,
marginLeft:30,
},
daysContainer: {
flexDirection: 'row',
justifyContent: 'space-between',
image: {
width: '100%',
paddingHorizontal: 20,
},
dayContainer: {
alignItems: 'center',
},
dayText: {
fontSize: 16,
fontWeight: 'bold',
color:'#273746',
},
emoji: {
fontSize: 20,
},
height: 200,
}
});
export default NewJournalEntry;
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