HydroFlux 0.1.1

This commit is contained in:
2026-02-10 09:31:02 +11:00
parent d8c222b667
commit 6f766b7a96
3 changed files with 46 additions and 10 deletions

View File

@@ -40,12 +40,16 @@ export class SleepView {
<div class="bg-white rounded-3xl p-8 shadow-xl mb-6 relative overflow-hidden">
<div class="absolute top-0 right-0 w-32 h-32 bg-indigo-100 rounded-full blur-3xl -mr-10 -mt-10"></div>
<div class="space-y-4">
<div class="space-y-4">
<!-- REM -->
<div>
<div class="flex justify-between text-sm mb-1">
<span class="text-purple-500 font-medium">REM</span>
<span class="font-bold text-gray-700">${formatTime(remHours)}</span>
<div class="flex items-center gap-2">
<span class="font-bold text-gray-700">${formatTime(remHours)}</span>
<span class="text-xs text-gray-400">(25%)</span>
</div>
</div>
<div class="h-2 w-full bg-gray-100 rounded-full overflow-hidden">
<div class="h-full bg-purple-400" style="width: 25%"></div>
@@ -56,7 +60,10 @@ export class SleepView {
<div>
<div class="flex justify-between text-sm mb-1">
<span class="text-blue-600 font-medium">Deep Sleep</span>
<span class="font-bold text-gray-700">${formatTime(deepHours)}</span>
<div class="flex items-center gap-2">
<span class="font-bold text-gray-700">${formatTime(deepHours)}</span>
<span class="text-xs text-gray-400">(20%)</span>
</div>
</div>
<div class="h-2 w-full bg-gray-100 rounded-full overflow-hidden">
<div class="h-full bg-blue-600" style="width: 20%"></div>
@@ -67,7 +74,10 @@ export class SleepView {
<div>
<div class="flex justify-between text-sm mb-1">
<span class="text-blue-400 font-medium">Light Sleep</span>
<span class="font-bold text-gray-700">${formatTime(lightHours)}</span>
<div class="flex items-center gap-2">
<span class="font-bold text-gray-700">${formatTime(lightHours)}</span>
<span class="text-xs text-gray-400">(55%)</span>
</div>
</div>
<div class="h-2 w-full bg-gray-100 rounded-full overflow-hidden">
<div class="h-full bg-blue-300" style="width: 55%"></div>

View File

@@ -179,14 +179,40 @@ export class WaterView {
});
this.container.querySelector('#removeWater').addEventListener('click', () => {
// Removing doesn't add to history, usually just undoes
const data = JSON.parse(localStorage.getItem('hydroflux_data') || '{"current":0,"goal":3.0}');
const drinkSize = parseInt(localStorage.getItem('hydroflux_drink_size') || '250');
data.current = Math.max(data.current - (drinkSize / 1000), 0);
localStorage.setItem('hydroflux_data', JSON.stringify(data));
// Find last entry for today
const todayStart = new Date();
todayStart.setHours(0, 0, 0, 0);
const todayTimestamp = todayStart.getTime();
// Filter history for today
const todaysEntries = this.history.filter(h => h.timestamp >= todayTimestamp);
if (todaysEntries.length > 0) {
// Get the last added entry
const lastEntry = todaysEntries[todaysEntries.length - 1];
// Remove it from the main history array (find index)
const index = this.history.indexOf(lastEntry);
if (index > -1) {
this.history.splice(index, 1);
}
localStorage.setItem('hydroflux_water_history', JSON.stringify(this.history));
// Update Total
const data = JSON.parse(localStorage.getItem('hydroflux_data') || '{"current":0,"goal":3.0}');
// Ensure we don't go below 0
data.current = Math.max(data.current - (lastEntry.amount / 1000), 0);
localStorage.setItem('hydroflux_data', JSON.stringify(data));
} else {
// Fallback: If no history for today, just decrement by drink size
const data = JSON.parse(localStorage.getItem('hydroflux_data') || '{"current":0,"goal":3.0}');
const drinkSize = parseInt(localStorage.getItem('hydroflux_drink_size') || '250');
if (data.current > 0) {
data.current = Math.max(data.current - (drinkSize / 1000), 0);
localStorage.setItem('hydroflux_data', JSON.stringify(data));
}
}
// Optionally remove last history entry if it matches?
// For now just keep it simple
this.render();
this.attachEvents();
});

Binary file not shown.