Skip to content

Commit

Permalink
sleeptracker(reusing exercisetracker code to build sleeptracker)
Browse files Browse the repository at this point in the history
  • Loading branch information
iKAN2025 authored Dec 15, 2023
1 parent bf80a6e commit 6e6349f
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions BF_sleep.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,80 @@ layout: base
title: Sleep
permalink: /sleep/
---
<meta charset="UTF-8">
<title>Sleep Tracker</title>
<style>
/* Basic styling for demonstration purposes */
/* Your CSS styles here */
</style>

<div class="purple-form">
<form id="sleepForm">
<label for="name">Name:</label>
<input type="text" id="name" name="name" placeholder="Enter your name" required>
<label for="sleepHours">Hours of Sleep:</label>
<input type="number" id="sleepHours" name="sleepHours" placeholder="Enter hours of sleep" required>
<label for="quality">Quality of Sleep:</label>
<select id="quality" name="quality" required>
<option value="" disabled selected>Select quality</option>
<option value="excellent">Excellent</option>
<option value="good">Good</option>
<option value="fair">Fair</option>
<option value="poor">Poor</option>
</select>
<label for="sleepDate">Date:</label>
<input type="date" id="sleepDate" name="sleepDate" required>
<input type="submit" value="Submit">
</form>
</div>

<script>
document.getElementById('sleepForm').addEventListener('submit', function (event) {
event.preventDefault();

const name = document.getElementById('name').value;
const sleepHours = document.getElementById('sleepHours').value;
const quality = document.getElementById('quality').value;
const sleepDate = document.getElementById('sleepDate').value;

const backendURL = 'http://127.0.0.1:8240/api/users'; // Replace with your API endpoint

const sleepData = {
"name": name,
"sleepHours": sleepHours,
"quality": quality,
"sleepDate": sleepDate
};

fetch(backendURL, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
"id": userIDFromLocalStorage, // id from local storage
"name": name,
"uid": "life", // database decides
"dob": "10/12/13", //
"age": "16",
"exercise": [], // Corrected to an empty array
"tracking": sleepData // Corrected variable name to sleepData
})
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
console.log('Data submitted successfully:', data);
// You can add additional logic here after successful submission
})
.catch(error => {
console.error('Error:', error);
});
});
</script>


0 comments on commit 6e6349f

Please sign in to comment.