Update DB configurations

parent f6d14975
...@@ -15,22 +15,38 @@ const AddData = () => { ...@@ -15,22 +15,38 @@ const AddData = () => {
const updateData = () => { const updateData = () => {
const jobSatisfactionValue = Job_Satisfaction === 'Yes' ? 0 : 1; const jobSatisfactionValue = Job_Satisfaction === 'Yes' ? 0 : 1;
const sleepHoursValue = parseInt(selectedHours); let sleepHoursValue = parseInt(selectedHours);
// Applying the logic to set sleep hours value
if (!isNaN(sleepHoursValue)) { if (!isNaN(sleepHoursValue)) {
const postData = { sleepHoursValue = sleepHoursValue > 8 ? 0 : 1;
Job_Satisfaction: jobSatisfactionValue,
Sleep_Hours: sleepHoursValue,
Text: Additional_Text,
isNew: false
};
set(ref(db, 'live_data'), postData);
} else { } else {
console.error("Invalid input for Sleep Hours. Please enter a valid number."); console.error("Invalid input for Sleep Hours. Please enter a valid number.");
return; // Exit the function if sleep hours is invalid
} }
const postData = {
Job_Satisfaction: jobSatisfactionValue,
Sleep_Hours: sleepHoursValue,
Text: Additional_Text,
isNew: true // Set isNew to true initially
};
set(ref(db, 'live_data'), postData)
.then(() => {
console.log("Data updated successfully");
// After some time or event, update isNew to false
setTimeout(() => {
set(ref(db, 'live_data/isNew'), false);
}, 5000); // Example: Set isNew to false after 5 seconds
})
.catch(error => {
console.error("Error updating data:", error);
});
setModalVisible(false); // Close the modal after updating data setModalVisible(false); // Close the modal after updating data
}; };
return ( return (
<View style={styles.container}> <View style={styles.container}>
<Text style={styles.header}>STRESS TRACKER</Text> <Text style={styles.header}>STRESS TRACKER</Text>
......
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