Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

feat: date editing, timezone fix, and sidebar nav for alcohol/nicotine

Adam Eivye8b43c22cf73
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index bf6d9c694d..6e975b0496 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -5,13 +5,20 @@
- Nicotine chart (7d/30d/90d bar chart) and nicotine vs heart rate correlation visualization
- Nicotine data integrated into health correlation endpoint (HR, resting HR alongside nicotine mg)
- Server-side nicotine service with daily log persistence, custom product management, and caching
+- Date editing on alcohol and nicotine history entries (move items between dates)
+- Nicotine sub-nav link in MeatSpace sidebar
## Changed
- Extracted shared `dayOfWeek` utility and `DAY_LABELS` constant to meatspace constants (deduplicated from AlcoholTab)
- Health correlation endpoint now includes heart rate, resting heart rate, and nicotine data alongside existing HRV/alcohol/steps
- NicotineHealthCorrelation tooltip uses Tailwind classes instead of inline styles for consistency
+- Extracted `recalcAlcoholTotal()` helper and reuse across logDrink, updateDrink, removeDrink
+- AlcoholTab correlation date range wrapped in useMemo to prevent unnecessary API refetches
+- Nicotine mg/unit form field uses placeholder instead of default value
## Fixed
- Stokes Pick default nicotine amount corrected from 3mg to 5mg
+- UTC timezone shift showing tomorrow's date in alcohol/nicotine forms — replaced `toISOString()` with local `localDateStr()` utility
+- Empty entry objects no longer accumulate in daily-log.json after moving the last item from a date
## Removed
diff --git a/client/src/components/Layout.jsx b/client/src/components/Layout.jsx
index 74b0e283d9..41e01a23ef 100644
--- a/client/src/components/Layout.jsx
+++ b/client/src/components/Layout.jsx
@@ -45,6 +45,7 @@ import {
Ticket,
Network,
Flame,
+ Cigarette,
Skull,
HeartPulse,
ClipboardList,
@@ -188,6 +189,7 @@ const navItems = [
{ to: '/meatspace/health', label: 'Health', icon: Heart },
{ to: '/meatspace/import', label: 'Import', icon: Upload },
{ to: '/meatspace/lifestyle', label: 'Lifestyle', icon: ClipboardList },
+ { to: '/meatspace/nicotine', label: 'Nicotine', icon: Cigarette },
{ to: '/meatspace/overview', label: 'Overview', icon: Activity },
]
},
diff --git a/client/src/components/meatspace/AlcoholChart.jsx b/client/src/components/meatspace/AlcoholChart.jsx
index 40722681e3..d72b491fb1 100644
--- a/client/src/components/meatspace/AlcoholChart.jsx
+++ b/client/src/components/meatspace/AlcoholChart.jsx
@@ -4,6 +4,7 @@ import {
} from 'recharts';
import * as api from '../../services/api';
import BrailleSpinner from '../BrailleSpinner';
+import { localDateStr } from './constants';
const VIEWS = [
{ id: '7d', label: '7 Days', days: 7 },
@@ -25,8 +26,8 @@ export default function AlcoholChart({ sex = 'male', onRefreshKey, onViewChange
const days = VIEWS.find(v => v.id === view)?.days || 30;
const from = new Date();
from.setDate(from.getDate() - days);
- const fromStr = from.toISOString().split('T')[0];
- const toStr = new Date().toISOString().split('T')[0];
+ const fromStr = localDateStr(from);
+ const toStr = localDateStr();
const entries = await api.getDailyAlcohol(fromStr, toStr).catch(() => []);
@@ -40,7 +41,7 @@ export default function AlcoholChart({ sex = 'male', onRefreshKey, onViewChange
const cursor = new Date(from);
const end = new Date(toStr);
while (cursor <= end) {
- const dateStr = cursor.toISOString().split('T')[0];
+ const dateStr = localDateStr(cursor);
const drinks = dateMap[dateStr] || 0;
chartData.push({
date: dateStr,
diff --git a/client/src/components/meatspace/NicotineChart.jsx b/client/src/components/meatspace/NicotineChart.jsx
index e8f239e839..041867c3fc 100644
--- a/client/src/components/meatspace/NicotineChart.jsx
+++ b/client/src/components/meatspace/NicotineChart.jsx
@@ -4,6 +4,7 @@ import {
} from 'recharts';
import * as api from '../../services/api';
import BrailleSpinner from '../BrailleSpinner';
+import { localDateStr } from './constants';
const VIEWS = [
{ id: '7d', label: '7 Days', days: 7 },
@@ -33,8 +34,8 @@ export default function NicotineChart({ onRefreshKey, onViewChange }) {
const days = VIEWS.find(v => v.id === view)?.days || 30;
const from = new Date();
from.setDate(from.getDate() - days);
- const fromStr = from.toISOString().split('T')[0];
- const toStr = new Date().toISOString().split('T')[0];
+ const fromStr = localDateStr(from);
+ const toStr = localDateStr();
const entries = await api.getDailyNicotine(fromStr, toStr).catch(() => []);
@@ -47,7 +48,7 @@ export default function NicotineChart({ onRefreshKey, onViewChange }) {
const cursor = new Date(from);
const end = new Date(toStr);
while (cursor <= end) {
- const dateStr = cursor.toISOString().split('T')[0];
+ const dateStr = localDateStr(cursor);
const mg = dateMap[dateStr] || 0;
chartData.push({
date: dateStr,
diff --git a/client/src/components/meatspace/constants.js b/client/src/components/meatspace/constants.js
index 81a8560585..bd13150cc4 100644
--- a/client/src/components/meatspace/constants.js
+++ b/client/src/components/meatspace/constants.js
@@ -107,6 +107,11 @@ export const STATUS_COLORS = {
unknown: 'text-gray-500'
};
+// Local date string (YYYY-MM-DD) — avoids UTC timezone shift from toISOString()
+export function localDateStr(d = new Date()) {
+ return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
+}
+
// Shared day-of-week helpers (used by AlcoholTab, NicotineTab, etc.)
export const DAY_LABELS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
diff --git a/client/src/components/meatspace/tabs/AlcoholTab.jsx b/client/src/components/meatspace/tabs/AlcoholTab.jsx
index 0823aaa41c..1d30dae32e 100644
--- a/client/src/components/meatspace/tabs/AlcoholTab.jsx
+++ b/client/src/components/meatspace/tabs/AlcoholTab.jsx
@@ -1,4 +1,4 @@
-import { useState, useEffect, useCallback } from 'react';
+import { useState, useEffect, useCallback, useMemo } from 'react';
import { Beer, Plus, Trash2, AlertTriangle, TrendingDown, TrendingUp, Pencil, Check, X, Settings } from 'lucide-react';
import toast from 'react-hot-toast';
import * as api from '../../../services/api';
@@ -6,7 +6,7 @@ import BrailleSpinner from '../../BrailleSpinner';
import AlcoholChart from '../AlcoholChart';
import AlcoholHrvCorrelation from '../AlcoholHrvCorrelation';
import StandardDrinkCalculator from '../StandardDrinkCalculator';
-import { dayOfWeek } from '../constants';
+import { dayOfWeek, localDateStr } from '../constants';
const ML_PER_OZ = 29.5735;
@@ -59,7 +59,7 @@ export default function AlcoholTab() {
const [oz, setOz] = useState('');
const [abv, setAbv] = useState('');
const [count, setCount] = useState(1);
- const [date, setDate] = useState(new Date().toISOString().split('T')[0]);
+ const [date, setDate] = useState(localDateStr());
const [volumeUnit, setVolumeUnit] = useState('oz');
// Inline edit state
@@ -99,9 +99,12 @@ export default function AlcoholTab() {
}, [fetchData, refreshKey]);
// Fetch correlation data for HRV chart
- const chartDays = { '7d': 7, '30d': 30, '90d': 90 }[chartView] || 30;
- const correlationFrom = (() => { const d = new Date(); d.setDate(d.getDate() - chartDays); return d.toISOString().split('T')[0]; })();
- const correlationTo = new Date().toISOString().split('T')[0];
+ const { correlationFrom, correlationTo } = useMemo(() => {
+ const days = { '7d': 7, '30d': 30, '90d': 90 }[chartView] || 30;
+ const d = new Date();
+ d.setDate(d.getDate() - days);
+ return { correlationFrom: localDateStr(d), correlationTo: localDateStr() };
+ }, [chartView]);
useEffect(() => {
api.getAppleHealthCorrelation(correlationFrom, correlationTo)
@@ -153,7 +156,8 @@ export default function AlcoholTab() {
name: drink.name || '',
oz: String(drink.oz || ''),
abv: String(drink.abv || ''),
- count: drink.count || 1
+ count: drink.count || 1,
+ date: entryDate
});
};
@@ -169,7 +173,8 @@ export default function AlcoholTab() {
name: editForm.name,
oz: Math.round(toOz(parseFloat(editForm.oz), editVolumeUnit) * 100) / 100,
abv: parseFloat(editForm.abv),
- count: parseInt(editForm.count, 10) || 1
+ count: parseInt(editForm.count, 10) || 1,
+ date: editForm.date !== entryDate ? editForm.date : undefined
}).catch(() => null);
setEditingKey(null);
setRefreshKey(k => k + 1);
@@ -567,7 +572,14 @@ export default function AlcoholTab() {
}`}
>
<td className="px-3 py-1.5">
- {idx === 0 ? (
+ {isEditing ? (
+ <input
+ type="date"
+ value={editForm.date}
+ onChange={e => setEditForm(f => ({ ...f, date: e.target.value }))}
+ className="bg-port-bg border border-port-border rounded px-2 py-1 text-xs text-white"
+ />
+ ) : idx === 0 ? (
<div>
<span className="text-gray-500 text-xs w-7 inline-block">{dayOfWeek(entry.date)}</span>
<span className="text-gray-300 font-medium">{entry.date}</span>
diff --git a/client/src/components/meatspace/tabs/NicotineTab.jsx b/client/src/components/meatspace/tabs/NicotineTab.jsx
index bce28b909f..8e702ec7f6 100644
--- a/client/src/components/meatspace/tabs/NicotineTab.jsx
+++ b/client/src/components/meatspace/tabs/NicotineTab.jsx
@@ -5,7 +5,7 @@ import * as api from '../../../services/api';
import BrailleSpinner from '../../BrailleSpinner';
import NicotineChart from '../NicotineChart';
import NicotineHealthCorrelation from '../NicotineHealthCorrelation';
-import { dayOfWeek } from '../constants';
+import { dayOfWeek, localDateStr } from '../constants';
const DAYS_PER_PAGE = 50;
@@ -24,9 +24,9 @@ export default function NicotineTab() {
const [buttonForm, setButtonForm] = useState({ name: '', mgPerUnit: '' });
// Form state
- const today = useMemo(() => new Date().toISOString().split('T')[0], []);
+ const today = useMemo(() => localDateStr(), []);
const [product, setProduct] = useState('');
- const [mgPerUnit, setMgPerUnit] = useState('3');
+ const [mgPerUnit, setMgPerUnit] = useState('');
const [count, setCount] = useState(1);
const [date, setDate] = useState(today);
@@ -68,7 +68,7 @@ export default function NicotineTab() {
const days = { '7d': 7, '30d': 30, '90d': 90 }[chartView] || 30;
const d = new Date();
d.setDate(d.getDate() - days);
- return { correlationFrom: d.toISOString().split('T')[0], correlationTo: new Date().toISOString().split('T')[0] };
+ return { correlationFrom: localDateStr(d), correlationTo: localDateStr() };
}, [chartView]);
useEffect(() => {
@@ -101,7 +101,7 @@ export default function NicotineTab() {
}).catch(() => null);
setLogging(false);
setProduct('');
- setMgPerUnit('3');
+ setMgPerUnit('');
setCount(1);
setRefreshKey(k => k + 1);
};
@@ -116,7 +116,8 @@ export default function NicotineTab() {
setEditForm({
product: item.product || '',
mgPerUnit: String(item.mgPerUnit || ''),
- count: item.count || 1
+ count: item.count || 1,
+ date: entryDate
});
};
@@ -131,7 +132,8 @@ export default function NicotineTab() {
await api.updateNicotineEntry(entryDate, index, {
product: editForm.product,
mgPerUnit: parseFloat(editForm.mgPerUnit),
- count: parseInt(editForm.count, 10) || 1
+ count: parseInt(editForm.count, 10) || 1,
+ date: editForm.date !== entryDate ? editForm.date : undefined
}).catch(() => null);
setEditingKey(null);
setRefreshKey(k => k + 1);
@@ -373,6 +375,7 @@ export default function NicotineTab() {
value={mgPerUnit}
onChange={e => setMgPerUnit(e.target.value)}
className="w-full bg-port-bg border border-port-border rounded px-3 py-2 text-sm text-white"
+ placeholder="5"
step="0.1"
min="0.1"
required
@@ -431,14 +434,20 @@ export default function NicotineTab() {
const isEditing = editingKey === key;
return (
- <div key={idx} className="flex items-center gap-2 py-1 pl-4 text-sm">
+ <div key={idx} className="flex flex-wrap items-center gap-2 py-1 pl-4 text-sm">
{isEditing ? (
<>
+ <input
+ type="date"
+ value={editForm.date}
+ onChange={e => setEditForm({ ...editForm, date: e.target.value })}
+ className="bg-port-bg border border-port-border rounded px-2 py-1 text-sm text-white"
+ />
<input
type="text"
value={editForm.product}
onChange={e => setEditForm({ ...editForm, product: e.target.value })}
- className="flex-1 bg-port-bg border border-port-border rounded px-2 py-1 text-sm text-white"
+ className="flex-1 min-w-[80px] bg-port-bg border border-port-border rounded px-2 py-1 text-sm text-white"
/>
<input
type="number"
diff --git a/server/lib/meatspaceValidation.js b/server/lib/meatspaceValidation.js
index 405dbfb9a4..48f6b21123 100644
--- a/server/lib/meatspaceValidation.js
+++ b/server/lib/meatspaceValidation.js
@@ -74,7 +74,8 @@ export const drinkUpdateSchema = z.object({
name: z.string().max(200).optional(),
oz: z.number().min(0.1).max(1000).optional(),
abv: z.number().min(0).max(100).optional(),
- count: z.number().int().min(1).max(100).optional()
+ count: z.number().int().min(1).max(100).optional(),
+ date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional()
});
export const customDrinkSchema = z.object({
@@ -99,7 +100,8 @@ export const nicotineLogSchema = z.object({
export const nicotineUpdateSchema = z.object({
product: z.string().max(200).optional(),
mgPerUnit: z.number().min(0.1).max(100).optional(),
- count: z.number().int().min(1).max(100).optional()
+ count: z.number().int().min(1).max(100).optional(),
+ date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional()
});
export const customNicotineProductSchema = z.object({
diff --git a/server/services/meatspaceAlcohol.js b/server/services/meatspaceAlcohol.js
index 309aa61e15..e0d8295208 100644
--- a/server/services/meatspaceAlcohol.js
+++ b/server/services/meatspaceAlcohol.js
@@ -205,11 +205,7 @@ export async function logDrink({ name, oz, abv, count = 1, date }) {
entry.alcohol.drinks.push(drink);
- // Recalculate total standard drinks for the day
- entry.alcohol.standardDrinks = entry.alcohol.drinks.reduce((sum, d) => {
- return sum + computeStandardDrinks((d.oz || 0) * (d.count || 1), d.abv || 0);
- }, 0);
- entry.alcohol.standardDrinks = Math.round(entry.alcohol.standardDrinks * 100) / 100;
+ recalcAlcoholTotal(entry);
// Re-sort and update lastEntryDate
log.entries.sort((a, b) => a.date.localeCompare(b.date));
@@ -221,6 +217,13 @@ export async function logDrink({ name, oz, abv, count = 1, date }) {
return { drink, standardDrinks, date: targetDate, dayTotal: entry.alcohol.standardDrinks };
}
+function recalcAlcoholTotal(entry) {
+ entry.alcohol.standardDrinks = entry.alcohol.drinks.reduce((sum, d) => {
+ return sum + computeStandardDrinks((d.oz || 0) * (d.count || 1), d.abv || 0);
+ }, 0);
+ entry.alcohol.standardDrinks = Math.round(entry.alcohol.standardDrinks * 100) / 100;
+}
+
export async function updateDrink(date, index, updates) {
const log = await loadDailyLog();
const entry = log.entries.find(e => e.date === date);
@@ -232,11 +235,38 @@ export async function updateDrink(date, index, updates) {
if (updates.abv !== undefined) drink.abv = updates.abv;
if (updates.count !== undefined) drink.count = updates.count;
- // Recalculate total
- entry.alcohol.standardDrinks = entry.alcohol.drinks.reduce((sum, d) => {
- return sum + computeStandardDrinks((d.oz || 0) * (d.count || 1), d.abv || 0);
- }, 0);
- entry.alcohol.standardDrinks = Math.round(entry.alcohol.standardDrinks * 100) / 100;
+ // Move to different date if requested
+ const newDate = updates.date;
+ if (newDate && newDate !== date) {
+ entry.alcohol.drinks.splice(index, 1);
+ if (entry.alcohol.drinks.length === 0) {
+ delete entry.alcohol;
+ // Remove entry entirely if no other data keys remain
+ if (Object.keys(entry).length <= 1) {
+ log.entries = log.entries.filter(e => e !== entry);
+ }
+ } else {
+ recalcAlcoholTotal(entry);
+ }
+
+ let targetEntry = log.entries.find(e => e.date === newDate);
+ if (!targetEntry) {
+ targetEntry = { date: newDate };
+ log.entries.push(targetEntry);
+ }
+ if (!targetEntry.alcohol) targetEntry.alcohol = { drinks: [], standardDrinks: 0 };
+ targetEntry.alcohol.drinks.push(drink);
+ recalcAlcoholTotal(targetEntry);
+
+ log.entries.sort((a, b) => a.date.localeCompare(b.date));
+ log.lastEntryDate = log.entries[log.entries.length - 1].date;
+
+ await saveDailyLog(log);
+ console.log(`📝 Moved drink from ${date}[${index}] to ${newDate}: ${drink.name || 'unnamed'} ${drink.oz}oz @ ${drink.abv}%`);
+ return { drink, dayTotal: targetEntry.alcohol.standardDrinks, date: newDate };
+ }
+
+ recalcAlcoholTotal(entry);
await saveDailyLog(log);
console.log(`📝 Updated drink on ${date}[${index}]: ${drink.name || 'unnamed'} ${drink.oz}oz @ ${drink.abv}%`);
@@ -250,15 +280,11 @@ export async function removeDrink(date, index) {
const removed = entry.alcohol.drinks.splice(index, 1)[0];
- // Recalculate total
- entry.alcohol.standardDrinks = entry.alcohol.drinks.reduce((sum, d) => {
- return sum + computeStandardDrinks((d.oz || 0) * (d.count || 1), d.abv || 0);
- }, 0);
- entry.alcohol.standardDrinks = Math.round(entry.alcohol.standardDrinks * 100) / 100;
-
- // Remove alcohol section if empty
+ // Remove alcohol section if empty, else recalculate total
if (entry.alcohol.drinks.length === 0) {
delete entry.alcohol;
+ } else {
+ recalcAlcoholTotal(entry);
}
await saveDailyLog(log);
diff --git a/server/services/meatspaceNicotine.js b/server/services/meatspaceNicotine.js
index 9bef5fb7b1..465540d7d0 100644
--- a/server/services/meatspaceNicotine.js
+++ b/server/services/meatspaceNicotine.js
@@ -183,6 +183,37 @@ export async function updateNicotine(date, index, updates) {
if (updates.mgPerUnit !== undefined) item.mgPerUnit = updates.mgPerUnit;
if (updates.count !== undefined) item.count = updates.count;
+ // Move to different date if requested
+ const newDate = updates.date;
+ if (newDate && newDate !== date) {
+ entry.nicotine.items.splice(index, 1);
+ if (entry.nicotine.items.length === 0) {
+ delete entry.nicotine;
+ // Remove entry entirely if no other data keys remain
+ if (Object.keys(entry).length <= 1) {
+ log.entries = log.entries.filter(e => e !== entry);
+ }
+ } else {
+ recalcDayTotal(entry);
+ }
+
+ let targetEntry = log.entries.find(e => e.date === newDate);
+ if (!targetEntry) {
+ targetEntry = { date: newDate };
+ log.entries.push(targetEntry);
+ }
+ if (!targetEntry.nicotine) targetEntry.nicotine = { items: [], totalMg: 0 };
+ targetEntry.nicotine.items.push(item);
+ recalcDayTotal(targetEntry);
+
+ log.entries.sort((a, b) => a.date.localeCompare(b.date));
+ log.lastEntryDate = log.entries[log.entries.length - 1].date;
+
+ await saveDailyLog(log);
+ console.log(`📝 Moved nicotine from ${date}[${index}] to ${newDate}: ${item.product || 'unnamed'} ${item.mgPerUnit}mg x${item.count}`);
+ return { item, dayTotal: targetEntry.nicotine.totalMg, date: newDate };
+ }
+
recalcDayTotal(entry);
await saveDailyLog(log);