HydroFlux 0.0.4
This commit is contained in:
@@ -11,7 +11,8 @@ export class Dashboard {
|
|||||||
if (!this.container) return;
|
if (!this.container) return;
|
||||||
|
|
||||||
// Data Retrieval (Keeping persistence)
|
// Data Retrieval (Keeping persistence)
|
||||||
const waterData = JSON.parse(localStorage.getItem('hydroflux_data') || '{"current":1.2,"goal":3.0}');
|
// Data Retrieval (Keeping persistence)
|
||||||
|
const waterData = JSON.parse(localStorage.getItem('hydroflux_data') || '{"current":0,"goal":3.0}');
|
||||||
const stepsData = 8432;
|
const stepsData = 8432;
|
||||||
const goalData = 10000;
|
const goalData = 10000;
|
||||||
const sleepHours = 7;
|
const sleepHours = 7;
|
||||||
@@ -281,11 +282,22 @@ export class Dashboard {
|
|||||||
if (addBtn) {
|
if (addBtn) {
|
||||||
addBtn.addEventListener('click', (e) => {
|
addBtn.addEventListener('click', (e) => {
|
||||||
e.stopPropagation(); // Stop bubble to card click
|
e.stopPropagation(); // Stop bubble to card click
|
||||||
const data = JSON.parse(localStorage.getItem('hydroflux_data') || '{"current":1.2,"goal":3.0}');
|
|
||||||
|
// Use stored drink size or default to 250ml
|
||||||
|
const drinkSize = parseInt(localStorage.getItem('hydroflux_drink_size') || '250');
|
||||||
|
const drinkLitres = drinkSize / 1000;
|
||||||
|
|
||||||
|
const data = JSON.parse(localStorage.getItem('hydroflux_data') || '{"current":0,"goal":3.0}');
|
||||||
|
|
||||||
if (data.current < data.goal) {
|
if (data.current < data.goal) {
|
||||||
data.current = Math.min(data.current + 0.25, data.goal);
|
data.current = Math.min(data.current + drinkLitres, data.goal);
|
||||||
localStorage.setItem('hydroflux_data', JSON.stringify(data));
|
localStorage.setItem('hydroflux_data', JSON.stringify(data));
|
||||||
|
|
||||||
|
// Add to history (to sync with detail view)
|
||||||
|
const history = JSON.parse(localStorage.getItem('hydroflux_water_history') || '[]');
|
||||||
|
history.push({ timestamp: Date.now(), amount: drinkSize });
|
||||||
|
localStorage.setItem('hydroflux_water_history', JSON.stringify(history));
|
||||||
|
|
||||||
// Update Display without full re-render
|
// Update Display without full re-render
|
||||||
const percentage = (data.current / data.goal) * 100;
|
const percentage = (data.current / data.goal) * 100;
|
||||||
const fill = this.container.querySelector('#waterFill');
|
const fill = this.container.querySelector('#waterFill');
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export class WaterView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const data = JSON.parse(localStorage.getItem('hydroflux_data') || '{"current":1.2,"goal":3.0}');
|
const data = JSON.parse(localStorage.getItem('hydroflux_data') || '{"current":0,"goal":3.0}');
|
||||||
const drinkSize = parseInt(localStorage.getItem('hydroflux_drink_size') || '250');
|
const drinkSize = parseInt(localStorage.getItem('hydroflux_drink_size') || '250');
|
||||||
const percentage = Math.min((data.current / data.goal) * 100, 100);
|
const percentage = Math.min((data.current / data.goal) * 100, 100);
|
||||||
|
|
||||||
@@ -138,7 +138,7 @@ export class WaterView {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const updateWater = (amount) => {
|
const updateWater = (amount) => {
|
||||||
const data = JSON.parse(localStorage.getItem('hydroflux_data') || '{"current":1.2,"goal":3.0}');
|
const data = JSON.parse(localStorage.getItem('hydroflux_data') || '{"current":0,"goal":3.0}');
|
||||||
data.current = Math.min(data.current + (amount / 1000), data.goal); // amount in ml to L
|
data.current = Math.min(data.current + (amount / 1000), data.goal); // amount in ml to L
|
||||||
localStorage.setItem('hydroflux_data', JSON.stringify(data));
|
localStorage.setItem('hydroflux_data', JSON.stringify(data));
|
||||||
this.addHistory(amount);
|
this.addHistory(amount);
|
||||||
@@ -153,7 +153,7 @@ export class WaterView {
|
|||||||
|
|
||||||
this.container.querySelector('#removeWater').addEventListener('click', () => {
|
this.container.querySelector('#removeWater').addEventListener('click', () => {
|
||||||
// Removing doesn't add to history, usually just undoes
|
// Removing doesn't add to history, usually just undoes
|
||||||
const data = JSON.parse(localStorage.getItem('hydroflux_data') || '{"current":1.2,"goal":3.0}');
|
const data = JSON.parse(localStorage.getItem('hydroflux_data') || '{"current":0,"goal":3.0}');
|
||||||
const drinkSize = parseInt(localStorage.getItem('hydroflux_drink_size') || '250');
|
const drinkSize = parseInt(localStorage.getItem('hydroflux_drink_size') || '250');
|
||||||
data.current = Math.max(data.current - (drinkSize / 1000), 0);
|
data.current = Math.max(data.current - (drinkSize / 1000), 0);
|
||||||
localStorage.setItem('hydroflux_data', JSON.stringify(data));
|
localStorage.setItem('hydroflux_data', JSON.stringify(data));
|
||||||
|
|||||||
Reference in New Issue
Block a user