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(alcohol): add Modelo Especial default + CRUD for custom drink buttons

Adam Eivy2879892b0631
diff --git a/client/src/components/meatspace/tabs/AlcoholTab.jsx b/client/src/components/meatspace/tabs/AlcoholTab.jsx
index e867f5b223..112f78eed6 100644
--- a/client/src/components/meatspace/tabs/AlcoholTab.jsx
+++ b/client/src/components/meatspace/tabs/AlcoholTab.jsx
@@ -1,12 +1,13 @@
import { useState, useEffect, useCallback } from 'react';
-import { Beer, Plus, Trash2, AlertTriangle, TrendingDown, TrendingUp, Pencil, Check, X } from 'lucide-react';
+import { Beer, Plus, Trash2, AlertTriangle, TrendingDown, TrendingUp, Pencil, Check, X, Settings } from 'lucide-react';
import * as api from '../../../services/api';
import BrailleSpinner from '../../BrailleSpinner';
import AlcoholChart from '../AlcoholChart';
import AlcoholHrvCorrelation from '../AlcoholHrvCorrelation';
import StandardDrinkCalculator from '../StandardDrinkCalculator';
-const COMMON_DRINKS = [
+const DEFAULT_DRINKS = [
+ { name: 'Modelo Especial (12oz)', oz: 12, abv: 4.4 },
{ name: 'Nitro Guinness (14.9oz)', oz: 14.9, abv: 4.2 },
{ name: 'Old Fashioned (2oz)', oz: 2, abv: 40 },
{ name: 'Guinness 0 (14.9oz)', oz: 14.9, abv: 0.4 },
@@ -46,6 +47,12 @@ export default function AlcoholTab() {
const [refreshKey, setRefreshKey] = useState(0);
const [visibleDays, setVisibleDays] = useState(DAYS_PER_PAGE);
+ // Custom drink buttons
+ const [drinkButtons, setDrinkButtons] = useState(DEFAULT_DRINKS);
+ const [managingButtons, setManagingButtons] = useState(false);
+ const [editingButtonIdx, setEditingButtonIdx] = useState(null);
+ const [buttonForm, setButtonForm] = useState({ name: '', oz: '', abv: '' });
+
// Form state
const [name, setName] = useState('');
const [oz, setOz] = useState('');
@@ -61,6 +68,11 @@ export default function AlcoholTab() {
const [chartView, setChartView] = useState('30d');
const [correlationData, setCorrelationData] = useState(null);
+ const fetchDrinkButtons = useCallback(async () => {
+ const buttons = await api.getCustomDrinks().catch(() => null);
+ if (buttons?.length) setDrinkButtons(buttons);
+ }, []);
+
const fetchData = useCallback(async () => {
const [summaryData, entries] = await Promise.all([
api.getAlcoholSummary().catch(() => null),
@@ -72,8 +84,9 @@ export default function AlcoholTab() {
}, []);
useEffect(() => {
+ fetchDrinkButtons();
fetchData();
- }, [fetchData, refreshKey]);
+ }, [fetchDrinkButtons, fetchData, refreshKey]);
// Fetch correlation data for HRV chart
const chartDays = { '7d': 7, '30d': 30, '90d': 90 }[chartView] || 30;
@@ -151,6 +164,45 @@ export default function AlcoholTab() {
setRefreshKey(k => k + 1);
};
+ // === Custom drink button management ===
+
+ const handleAddButton = async (e) => {
+ e.preventDefault();
+ const parsedOz = parseFloat(buttonForm.oz);
+ const parsedAbv = parseFloat(buttonForm.abv);
+ if (!buttonForm.name || !parsedOz || isNaN(parsedAbv)) return;
+ await api.addCustomDrink({ name: buttonForm.name, oz: parsedOz, abv: parsedAbv }).catch(() => null);
+ setButtonForm({ name: '', oz: '', abv: '' });
+ fetchDrinkButtons();
+ };
+
+ const startEditButton = (idx) => {
+ const btn = drinkButtons[idx];
+ setEditingButtonIdx(idx);
+ setButtonForm({ name: btn.name, oz: String(btn.oz), abv: String(btn.abv) });
+ };
+
+ const saveEditButton = async () => {
+ if (editingButtonIdx === null) return;
+ const parsedOz = parseFloat(buttonForm.oz);
+ const parsedAbv = parseFloat(buttonForm.abv);
+ if (!buttonForm.name || !parsedOz || isNaN(parsedAbv)) return;
+ await api.updateCustomDrink(editingButtonIdx, { name: buttonForm.name, oz: parsedOz, abv: parsedAbv }).catch(() => null);
+ setEditingButtonIdx(null);
+ setButtonForm({ name: '', oz: '', abv: '' });
+ fetchDrinkButtons();
+ };
+
+ const cancelEditButton = () => {
+ setEditingButtonIdx(null);
+ setButtonForm({ name: '', oz: '', abv: '' });
+ };
+
+ const handleRemoveButton = async (idx) => {
+ await api.removeCustomDrink(idx).catch(() => null);
+ fetchDrinkButtons();
+ };
+
if (loading) {
return (
<div className="flex items-center justify-center h-64">
@@ -232,22 +284,132 @@ export default function AlcoholTab() {
{/* Log a Drink */}
<div className="bg-port-card border border-port-border rounded-xl p-6">
- <h3 className="text-sm font-medium text-gray-400 uppercase tracking-wider mb-4">Log a Drink</h3>
+ <div className="flex items-center justify-between mb-4">
+ <h3 className="text-sm font-medium text-gray-400 uppercase tracking-wider">Log a Drink</h3>
+ <button
+ onClick={() => setManagingButtons(v => !v)}
+ className={`flex items-center gap-1 px-2 py-1 text-xs rounded-lg transition-colors ${
+ managingButtons ? 'bg-port-accent/20 text-port-accent' : 'text-gray-500 hover:text-gray-300'
+ }`}
+ title="Manage quick-add buttons"
+ >
+ <Settings size={14} />
+ {managingButtons ? 'Done' : 'Manage'}
+ </button>
+ </div>
{/* Quick-add buttons */}
- <div className="flex flex-wrap gap-2 mb-4">
- {COMMON_DRINKS.map(drink => (
- <button
- key={drink.name}
- onClick={() => handleQuickAdd(drink)}
- disabled={logging}
- className="flex items-center gap-1 px-3 py-1.5 text-xs bg-port-border/50 text-gray-300 rounded-lg hover:bg-port-accent/10 hover:text-port-accent transition-colors disabled:opacity-50"
- >
- <Plus size={12} />
- {drink.name}
- </button>
- ))}
- </div>
+ {!managingButtons && (
+ <div className="flex flex-wrap gap-2 mb-4">
+ {drinkButtons.map((drink, idx) => (
+ <button
+ key={`${drink.name}-${idx}`}
+ onClick={() => handleQuickAdd(drink)}
+ disabled={logging}
+ className="flex items-center gap-1 px-3 py-1.5 text-xs bg-port-border/50 text-gray-300 rounded-lg hover:bg-port-accent/10 hover:text-port-accent transition-colors disabled:opacity-50"
+ >
+ <Plus size={12} />
+ {drink.name}
+ </button>
+ ))}
+ </div>
+ )}
+
+ {/* Manage quick-add buttons */}
+ {managingButtons && (
+ <div className="mb-4 space-y-2">
+ {drinkButtons.map((drink, idx) => (
+ <div key={`manage-${idx}`} className="flex items-center gap-2">
+ {editingButtonIdx === idx ? (
+ <>
+ <input
+ type="text"
+ value={buttonForm.name}
+ onChange={e => setButtonForm(f => ({ ...f, name: e.target.value }))}
+ placeholder="Name"
+ className="flex-1 px-2 py-1.5 bg-port-bg border border-port-border rounded-lg text-xs text-white"
+ />
+ <input
+ type="number"
+ step="0.1"
+ min="0.1"
+ value={buttonForm.oz}
+ onChange={e => setButtonForm(f => ({ ...f, oz: e.target.value }))}
+ placeholder="Oz"
+ className="w-16 px-2 py-1.5 bg-port-bg border border-port-border rounded-lg text-xs text-white text-right"
+ />
+ <input
+ type="number"
+ step="0.1"
+ min="0"
+ max="100"
+ value={buttonForm.abv}
+ onChange={e => setButtonForm(f => ({ ...f, abv: e.target.value }))}
+ placeholder="ABV%"
+ className="w-16 px-2 py-1.5 bg-port-bg border border-port-border rounded-lg text-xs text-white text-right"
+ />
+ <button onClick={saveEditButton} className="p-1.5 text-port-success hover:text-port-success/80" title="Save">
+ <Check size={14} />
+ </button>
+ <button onClick={cancelEditButton} className="p-1.5 text-gray-500 hover:text-gray-300" title="Cancel">
+ <X size={14} />
+ </button>
+ </>
+ ) : (
+ <>
+ <span className="flex-1 text-xs text-gray-300">{drink.name}</span>
+ <span className="text-xs text-gray-500">{drink.oz}oz</span>
+ <span className="text-xs text-gray-500">{drink.abv}%</span>
+ <button onClick={() => startEditButton(idx)} className="p-1.5 text-gray-600 hover:text-port-accent" title="Edit">
+ <Pencil size={12} />
+ </button>
+ <button onClick={() => handleRemoveButton(idx)} className="p-1.5 text-gray-600 hover:text-port-error" title="Remove">
+ <Trash2 size={12} />
+ </button>
+ </>
+ )}
+ </div>
+ ))}
+ {editingButtonIdx === null && (
+ <form onSubmit={handleAddButton} className="flex items-center gap-2 pt-2 border-t border-port-border/50">
+ <input
+ type="text"
+ value={buttonForm.name}
+ onChange={e => setButtonForm(f => ({ ...f, name: e.target.value }))}
+ placeholder="New button name"
+ className="flex-1 px-2 py-1.5 bg-port-bg border border-port-border rounded-lg text-xs text-white placeholder-gray-600"
+ />
+ <input
+ type="number"
+ step="0.1"
+ min="0.1"
+ value={buttonForm.oz}
+ onChange={e => setButtonForm(f => ({ ...f, oz: e.target.value }))}
+ placeholder="Oz"
+ className="w-16 px-2 py-1.5 bg-port-bg border border-port-border rounded-lg text-xs text-white text-right placeholder-gray-600"
+ />
+ <input
+ type="number"
+ step="0.1"
+ min="0"
+ max="100"
+ value={buttonForm.abv}
+ onChange={e => setButtonForm(f => ({ ...f, abv: e.target.value }))}
+ placeholder="ABV%"
+ className="w-16 px-2 py-1.5 bg-port-bg border border-port-border rounded-lg text-xs text-white text-right placeholder-gray-600"
+ />
+ <button
+ type="submit"
+ disabled={!buttonForm.name || !buttonForm.oz}
+ className="flex items-center gap-1 px-2 py-1.5 text-xs bg-port-accent text-white rounded-lg hover:bg-port-accent/80 disabled:opacity-50"
+ >
+ <Plus size={12} />
+ Add
+ </button>
+ </form>
+ )}
+ </div>
+ )}
{/* Custom entry form */}
<form onSubmit={handleCustomAdd} className="flex flex-wrap items-end gap-3">
diff --git a/client/src/services/api.js b/client/src/services/api.js
index 2ff705bbcd..9fff14d35f 100644
--- a/client/src/services/api.js
+++ b/client/src/services/api.js
@@ -1405,6 +1405,18 @@ export const updateAlcoholDrink = (date, index, data) => request(`/meatspace/alc
export const removeAlcoholDrink = (date, index) => request(`/meatspace/alcohol/log/${date}/${index}`, {
method: 'DELETE'
});
+export const getCustomDrinks = () => request('/meatspace/alcohol/custom-drinks');
+export const addCustomDrink = (data) => request('/meatspace/alcohol/custom-drinks', {
+ method: 'POST',
+ body: JSON.stringify(data)
+});
+export const updateCustomDrink = (index, data) => request(`/meatspace/alcohol/custom-drinks/${index}`, {
+ method: 'PUT',
+ body: JSON.stringify(data)
+});
+export const removeCustomDrink = (index) => request(`/meatspace/alcohol/custom-drinks/${index}`, {
+ method: 'DELETE'
+});
export const getBloodTests = () => request('/meatspace/blood');
export const addBloodTest = (data) => request('/meatspace/blood', {
method: 'POST',
diff --git a/server/lib/meatspaceValidation.js b/server/lib/meatspaceValidation.js
index 40bc609086..430b2fdc71 100644
--- a/server/lib/meatspaceValidation.js
+++ b/server/lib/meatspaceValidation.js
@@ -47,6 +47,14 @@ export const drinkUpdateSchema = z.object({
count: z.number().int().min(1).max(100).optional()
});
+export const customDrinkSchema = z.object({
+ name: z.string().min(1).max(200),
+ oz: z.number().min(0.1).max(1000),
+ abv: z.number().min(0).max(100)
+});
+
+export const customDrinkUpdateSchema = customDrinkSchema.partial();
+
// =============================================================================
// BLOOD TESTS
// =============================================================================
diff --git a/server/routes/meatspace.js b/server/routes/meatspace.js
index e60b03927c..87f62ab04c 100644
--- a/server/routes/meatspace.js
+++ b/server/routes/meatspace.js
@@ -6,6 +6,8 @@ import {
lifestyleUpdateSchema,
drinkLogSchema,
drinkUpdateSchema,
+ customDrinkSchema,
+ customDrinkUpdateSchema,
bloodTestSchema,
bodyEntrySchema,
epigeneticTestSchema,
@@ -151,6 +153,56 @@ router.delete('/alcohol/log/:date/:index', asyncHandler(async (req, res) => {
res.json(removed);
}));
+// =============================================================================
+// CUSTOM DRINK BUTTONS
+// =============================================================================
+
+/**
+ * GET /api/meatspace/alcohol/custom-drinks
+ * List custom drink quick-add buttons
+ */
+router.get('/alcohol/custom-drinks', asyncHandler(async (req, res) => {
+ const drinks = await alcoholService.getCustomDrinks();
+ res.json(drinks);
+}));
+
+/**
+ * POST /api/meatspace/alcohol/custom-drinks
+ * Add a custom drink button
+ */
+router.post('/alcohol/custom-drinks', asyncHandler(async (req, res) => {
+ const data = validateRequest(customDrinkSchema, req.body);
+ const drink = await alcoholService.addCustomDrink(data);
+ res.status(201).json(drink);
+}));
+
+/**
+ * PUT /api/meatspace/alcohol/custom-drinks/:index
+ * Update a custom drink button
+ */
+router.put('/alcohol/custom-drinks/:index', asyncHandler(async (req, res) => {
+ const index = parseInt(req.params.index, 10);
+ const data = validateRequest(customDrinkUpdateSchema, req.body);
+ const drink = await alcoholService.updateCustomDrink(index, data);
+ if (!drink) {
+ throw new ServerError('Custom drink not found', { status: 404, code: 'NOT_FOUND' });
+ }
+ res.json(drink);
+}));
+
+/**
+ * DELETE /api/meatspace/alcohol/custom-drinks/:index
+ * Remove a custom drink button
+ */
+router.delete('/alcohol/custom-drinks/:index', asyncHandler(async (req, res) => {
+ const index = parseInt(req.params.index, 10);
+ const removed = await alcoholService.removeCustomDrink(index);
+ if (!removed) {
+ throw new ServerError('Custom drink not found', { status: 404, code: 'NOT_FOUND' });
+ }
+ res.json(removed);
+}));
+
// =============================================================================
// BLOOD & BODY
// =============================================================================
diff --git a/server/services/meatspaceAlcohol.js b/server/services/meatspaceAlcohol.js
index 4aa387e800..6bfb42c236 100644
--- a/server/services/meatspaceAlcohol.js
+++ b/server/services/meatspaceAlcohol.js
@@ -12,6 +12,15 @@ import { PATHS, ensureDir, readJSONFile } from '../lib/fileUtils.js';
const MEATSPACE_DIR = PATHS.meatspace;
const DAILY_LOG_FILE = join(MEATSPACE_DIR, 'daily-log.json');
const CONFIG_FILE = join(MEATSPACE_DIR, 'config.json');
+const CUSTOM_DRINKS_FILE = join(MEATSPACE_DIR, 'custom-drinks.json');
+
+const DEFAULT_DRINK_BUTTONS = [
+ { name: 'Modelo Especial (12oz)', oz: 12, abv: 4.4 },
+ { name: 'Nitro Guinness (14.9oz)', oz: 14.9, abv: 4.2 },
+ { name: 'Old Fashioned (2oz)', oz: 2, abv: 40 },
+ { name: 'Guinness 0 (14.9oz)', oz: 14.9, abv: 0.4 },
+ { name: 'N/A Beer (12oz)', oz: 12, abv: 0.4 }
+];
// Cache for rolling averages (invalidated on writes)
let averageCache = null;
@@ -252,3 +261,66 @@ export async function removeDrink(date, index) {
await saveDailyLog(log);
return removed;
}
+
+// === Custom Drink Buttons ===
+
+async function loadCustomDrinks() {
+ const data = await readJSONFile(CUSTOM_DRINKS_FILE, null);
+ if (!data) {
+ // Seed with defaults on first access
+ const seeded = { drinks: DEFAULT_DRINK_BUTTONS };
+ await saveCustomDrinks(seeded);
+ return seeded;
+ }
+ return data;
+}
+
+async function saveCustomDrinks(data) {
+ await ensureDir(MEATSPACE_DIR);
+ await writeFile(CUSTOM_DRINKS_FILE, JSON.stringify(data, null, 2));
+}
+
+export async function getCustomDrinks() {
+ const data = await loadCustomDrinks();
+ return data.drinks || [];
+}
+
+export async function addCustomDrink({ name, oz, abv }) {
+ const data = await loadCustomDrinks();
+ const drink = { name, oz, abv };
+ data.drinks.push(drink);
+ await saveCustomDrinks(data);
+ console.log(`🍺 Added custom drink button: ${name} ${oz}oz @ ${abv}%`);
+ return drink;
+}
+
+export async function updateCustomDrink(index, updates) {
+ const data = await loadCustomDrinks();
+ if (index < 0 || index >= data.drinks.length) return null;
+ const drink = data.drinks[index];
+ if (updates.name !== undefined) drink.name = updates.name;
+ if (updates.oz !== undefined) drink.oz = updates.oz;
+ if (updates.abv !== undefined) drink.abv = updates.abv;
+ await saveCustomDrinks(data);
+ console.log(`📝 Updated custom drink button [${index}]: ${drink.name}`);
+ return drink;
+}
+
+export async function removeCustomDrink(index) {
+ const data = await loadCustomDrinks();
+ if (index < 0 || index >= data.drinks.length) return null;
+ const removed = data.drinks.splice(index, 1)[0];
+ await saveCustomDrinks(data);
+ console.log(`🗑️ Removed custom drink button: ${removed.name}`);
+ return removed;
+}
+
+export async function reorderCustomDrinks(fromIndex, toIndex) {
+ const data = await loadCustomDrinks();
+ if (fromIndex < 0 || fromIndex >= data.drinks.length) return null;
+ if (toIndex < 0 || toIndex >= data.drinks.length) return null;
+ const [moved] = data.drinks.splice(fromIndex, 1);
+ data.drinks.splice(toIndex, 0, moved);
+ await saveCustomDrinks(data);
+ return data.drinks;
+}