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: eye prescription CRUD and fix display bug

Adam Eivy2984d149657f
diff --git a/.changelog/v1.11.x.md b/.changelog/v1.11.x.md
index a8145f0627..e5510a2238 100644
--- a/.changelog/v1.11.x.md
+++ b/.changelog/v1.11.x.md
@@ -12,11 +12,17 @@ Alcohol data table: view and edit all imported drink entries with inline editing
- **Paginated display**: shows 50 days at a time with "Load More" for full history, scrollable with sticky header
- **Update drink API**: `PUT /api/meatspace/alcohol/log/:date/:index` with partial update schema (any combination of name, oz, abv, count)
- 3 new tests for drink update logic with standard drink recalculation verification
+- **Eye prescription CRUD**: Add, edit, and delete eye exams with inline form — tabular display showing SPH, CYL, and AXIS for both eyes
+- Eye exam API: `PUT /api/meatspace/eyes/:index` and `DELETE /api/meatspace/eyes/:index`
## Improvements
- **Day of week labels** in alcohol data table — each date group shows abbreviated day (M, T, W, TH, F, Sat, Sun) for quick pattern recognition
+## Fixes
+
+- **Eye prescription display** now correctly reads flat field names (`leftSphere`, `rightCylinder`, etc.) instead of broken nested object access — prescriptions were showing as empty cards with only dates
+
## Removed
- **Mercury exposure tracking** removed from nutrition dashboard, TSV import, health service, and daily log data
diff --git a/client/src/components/meatspace/tabs/BloodTab.jsx b/client/src/components/meatspace/tabs/BloodTab.jsx
index b7c5c98a60..04821f3a13 100644
--- a/client/src/components/meatspace/tabs/BloodTab.jsx
+++ b/client/src/components/meatspace/tabs/BloodTab.jsx
@@ -1,15 +1,29 @@
import { useState, useEffect, useCallback } from 'react';
-import { HeartPulse, Eye, Dna, Scale } from 'lucide-react';
+import { HeartPulse, Eye, Dna, Scale, Plus, Pencil, Trash2, Check, X } from 'lucide-react';
import * as api from '../../../services/api';
import BrailleSpinner from '../../BrailleSpinner';
import BloodTestCard from '../BloodTestCard';
import BodyCompChart from '../BodyCompChart';
+const EMPTY_EYE_FORM = {
+ date: '', leftSphere: '', leftCylinder: '', leftAxis: '',
+ rightSphere: '', rightCylinder: '', rightAxis: ''
+};
+
+function formatSph(val) {
+ if (val == null) return '—';
+ return (val > 0 ? '+' : '') + val.toFixed(2);
+}
+
export default function BloodTab() {
const [bloodData, setBloodData] = useState(null);
const [epigeneticData, setEpigeneticData] = useState(null);
const [eyeData, setEyeData] = useState(null);
const [loading, setLoading] = useState(true);
+ const [refreshKey, setRefreshKey] = useState(0);
+ const [showEyeForm, setShowEyeForm] = useState(false);
+ const [eyeForm, setEyeForm] = useState(EMPTY_EYE_FORM);
+ const [editingEyeIdx, setEditingEyeIdx] = useState(null);
const fetchData = useCallback(async () => {
const [blood, epigenetic, eyes] = await Promise.all([
@@ -25,7 +39,56 @@ export default function BloodTab() {
useEffect(() => {
fetchData();
- }, [fetchData]);
+ }, [fetchData, refreshKey]);
+
+ const parseNum = (v) => {
+ if (v === '' || v === null || v === undefined) return null;
+ const n = parseFloat(v);
+ return isNaN(n) ? null : n;
+ };
+
+ const buildEyePayload = (form) => {
+ const payload = { date: form.date };
+ for (const key of ['leftSphere', 'leftCylinder', 'leftAxis', 'rightSphere', 'rightCylinder', 'rightAxis']) {
+ const v = parseNum(form[key]);
+ if (v !== null) payload[key] = v;
+ }
+ return payload;
+ };
+
+ const handleAddEye = async () => {
+ if (!eyeForm.date) return;
+ await api.addEyeExam(buildEyePayload(eyeForm));
+ setEyeForm(EMPTY_EYE_FORM);
+ setShowEyeForm(false);
+ setRefreshKey(k => k + 1);
+ };
+
+ const startEditEye = (exam, idx) => {
+ setEditingEyeIdx(idx);
+ setEyeForm({
+ date: exam.date,
+ leftSphere: exam.leftSphere ?? '',
+ leftCylinder: exam.leftCylinder ?? '',
+ leftAxis: exam.leftAxis ?? '',
+ rightSphere: exam.rightSphere ?? '',
+ rightCylinder: exam.rightCylinder ?? '',
+ rightAxis: exam.rightAxis ?? ''
+ });
+ };
+
+ const handleUpdateEye = async () => {
+ if (editingEyeIdx == null) return;
+ await api.updateEyeExam(editingEyeIdx, buildEyePayload(eyeForm));
+ setEditingEyeIdx(null);
+ setEyeForm(EMPTY_EYE_FORM);
+ setRefreshKey(k => k + 1);
+ };
+
+ const handleDeleteEye = async (idx) => {
+ await api.removeEyeExam(idx);
+ setRefreshKey(k => k + 1);
+ };
if (loading) {
return (
@@ -146,62 +209,145 @@ export default function BloodTab() {
{/* Eye Exams */}
<div>
- <div className="flex items-center gap-2 mb-3">
- <Eye size={18} className="text-blue-400" />
- <h3 className="text-sm font-medium text-gray-400 uppercase tracking-wider">
- Eye Prescriptions ({eyeExams.length})
- </h3>
+ <div className="flex items-center justify-between mb-3">
+ <div className="flex items-center gap-2">
+ <Eye size={18} className="text-blue-400" />
+ <h3 className="text-sm font-medium text-gray-400 uppercase tracking-wider">
+ Eye Prescriptions ({eyeExams.length})
+ </h3>
+ </div>
+ {!showEyeForm && editingEyeIdx == null && (
+ <button
+ onClick={() => { setShowEyeForm(true); setEyeForm({ ...EMPTY_EYE_FORM, date: new Date().toISOString().split('T')[0] }); }}
+ className="flex items-center gap-1 text-xs text-port-accent hover:text-blue-300 transition-colors"
+ >
+ <Plus size={14} /> Add Exam
+ </button>
+ )}
</div>
+
+ {/* Add / Edit Form */}
+ {(showEyeForm || editingEyeIdx != null) && (
+ <div className="bg-port-card border border-port-border rounded-xl p-4 mb-3">
+ <h4 className="text-sm font-medium text-gray-300 mb-3">
+ {editingEyeIdx != null ? 'Edit Eye Exam' : 'New Eye Exam'}
+ </h4>
+ <div className="grid grid-cols-7 gap-2 mb-3">
+ <div>
+ <label className="text-xs text-gray-500">Date</label>
+ <input type="date" value={eyeForm.date}
+ onChange={e => setEyeForm(f => ({ ...f, date: e.target.value }))}
+ className="w-full bg-port-bg border border-port-border rounded px-2 py-1 text-sm text-gray-200 font-mono" />
+ </div>
+ <div>
+ <label className="text-xs text-gray-500">L SPH</label>
+ <input type="number" step="0.25" value={eyeForm.leftSphere}
+ onChange={e => setEyeForm(f => ({ ...f, leftSphere: e.target.value }))}
+ className="w-full bg-port-bg border border-port-border rounded px-2 py-1 text-sm text-gray-200 font-mono" />
+ </div>
+ <div>
+ <label className="text-xs text-gray-500">L CYL</label>
+ <input type="number" step="0.25" value={eyeForm.leftCylinder}
+ onChange={e => setEyeForm(f => ({ ...f, leftCylinder: e.target.value }))}
+ className="w-full bg-port-bg border border-port-border rounded px-2 py-1 text-sm text-gray-200 font-mono" />
+ </div>
+ <div>
+ <label className="text-xs text-gray-500">L AXIS</label>
+ <input type="number" step="1" min="0" max="180" value={eyeForm.leftAxis}
+ onChange={e => setEyeForm(f => ({ ...f, leftAxis: e.target.value }))}
+ className="w-full bg-port-bg border border-port-border rounded px-2 py-1 text-sm text-gray-200 font-mono" />
+ </div>
+ <div>
+ <label className="text-xs text-gray-500">R SPH</label>
+ <input type="number" step="0.25" value={eyeForm.rightSphere}
+ onChange={e => setEyeForm(f => ({ ...f, rightSphere: e.target.value }))}
+ className="w-full bg-port-bg border border-port-border rounded px-2 py-1 text-sm text-gray-200 font-mono" />
+ </div>
+ <div>
+ <label className="text-xs text-gray-500">R CYL</label>
+ <input type="number" step="0.25" value={eyeForm.rightCylinder}
+ onChange={e => setEyeForm(f => ({ ...f, rightCylinder: e.target.value }))}
+ className="w-full bg-port-bg border border-port-border rounded px-2 py-1 text-sm text-gray-200 font-mono" />
+ </div>
+ <div>
+ <label className="text-xs text-gray-500">R AXIS</label>
+ <input type="number" step="1" min="0" max="180" value={eyeForm.rightAxis}
+ onChange={e => setEyeForm(f => ({ ...f, rightAxis: e.target.value }))}
+ className="w-full bg-port-bg border border-port-border rounded px-2 py-1 text-sm text-gray-200 font-mono" />
+ </div>
+ </div>
+ <div className="flex gap-2">
+ <button
+ onClick={editingEyeIdx != null ? handleUpdateEye : handleAddEye}
+ disabled={!eyeForm.date}
+ className="flex items-center gap-1 px-3 py-1 bg-port-accent/20 text-port-accent rounded text-sm hover:bg-port-accent/30 disabled:opacity-40"
+ >
+ <Check size={14} /> {editingEyeIdx != null ? 'Save' : 'Add'}
+ </button>
+ <button
+ onClick={() => { setShowEyeForm(false); setEditingEyeIdx(null); setEyeForm(EMPTY_EYE_FORM); }}
+ className="flex items-center gap-1 px-3 py-1 text-gray-400 hover:text-gray-200 text-sm"
+ >
+ <X size={14} /> Cancel
+ </button>
+ </div>
+ </div>
+ )}
+
{eyeExams.length === 0 ? (
<div className="bg-port-card border border-port-border rounded-xl p-6">
<p className="text-gray-500 text-sm">No eye exam data. Import your health spreadsheet or add exams manually.</p>
</div>
) : (
- <div className="space-y-3">
- {[...eyeExams].reverse().map((exam, i) => (
- <div key={i} className="bg-port-card border border-port-border rounded-xl p-4">
- <h4 className="text-sm font-medium text-gray-300 mb-3">{exam.date}</h4>
- <div className="grid grid-cols-2 gap-4">
- {['right', 'left'].map(side => {
- const eye = exam[side];
- if (!eye) return null;
- return (
- <div key={side}>
- <p className="text-xs font-medium text-gray-500 uppercase mb-1">
- {side === 'right' ? 'OD (Right)' : 'OS (Left)'}
- </p>
- <div className="grid grid-cols-3 gap-2 text-sm">
- {eye.sphere != null && (
- <div>
- <span className="text-xs text-gray-600">SPH</span>
- <p className="font-mono text-gray-300">{eye.sphere > 0 ? '+' : ''}{eye.sphere}</p>
- </div>
- )}
- {eye.cylinder != null && (
- <div>
- <span className="text-xs text-gray-600">CYL</span>
- <p className="font-mono text-gray-300">{eye.cylinder > 0 ? '+' : ''}{eye.cylinder}</p>
- </div>
- )}
- {eye.axis != null && (
- <div>
- <span className="text-xs text-gray-600">AXIS</span>
- <p className="font-mono text-gray-300">{eye.axis}°</p>
- </div>
- )}
+ <div className="bg-port-card border border-port-border rounded-xl overflow-hidden">
+ <table className="w-full text-sm">
+ <thead>
+ <tr className="text-xs text-gray-500 uppercase border-b border-port-border">
+ <th className="text-left py-2 px-3">Date</th>
+ <th className="text-right py-2 px-2">L SPH</th>
+ <th className="text-right py-2 px-2">L CYL</th>
+ <th className="text-right py-2 px-2">L AXIS</th>
+ <th className="text-right py-2 px-2">R SPH</th>
+ <th className="text-right py-2 px-2">R CYL</th>
+ <th className="text-right py-2 px-2">R AXIS</th>
+ <th className="w-16"></th>
+ </tr>
+ </thead>
+ <tbody>
+ {[...eyeExams].reverse().map((exam, revIdx) => {
+ const realIdx = eyeExams.length - 1 - revIdx;
+ return (
+ <tr key={realIdx} className="border-b border-port-border/50 hover:bg-port-bg/30">
+ <td className="py-1.5 px-3 font-mono text-gray-400">{exam.date}</td>
+ <td className="py-1.5 px-2 text-right font-mono text-gray-300">{formatSph(exam.leftSphere)}</td>
+ <td className="py-1.5 px-2 text-right font-mono text-gray-300">{formatSph(exam.leftCylinder)}</td>
+ <td className="py-1.5 px-2 text-right font-mono text-gray-300">{exam.leftAxis != null ? `${exam.leftAxis}°` : '—'}</td>
+ <td className="py-1.5 px-2 text-right font-mono text-gray-300">{formatSph(exam.rightSphere)}</td>
+ <td className="py-1.5 px-2 text-right font-mono text-gray-300">{formatSph(exam.rightCylinder)}</td>
+ <td className="py-1.5 px-2 text-right font-mono text-gray-300">{exam.rightAxis != null ? `${exam.rightAxis}°` : '—'}</td>
+ <td className="py-1.5 px-2 text-right">
+ <div className="flex items-center justify-end gap-1">
+ <button
+ onClick={() => startEditEye(exam, realIdx)}
+ className="p-1 text-gray-600 hover:text-port-accent transition-colors"
+ title="Edit"
+ >
+ <Pencil size={12} />
+ </button>
+ <button
+ onClick={() => handleDeleteEye(realIdx)}
+ className="p-1 text-gray-600 hover:text-port-error transition-colors"
+ title="Delete"
+ >
+ <Trash2 size={12} />
+ </button>
</div>
- </div>
- );
- })}
- </div>
- {exam.add != null && (
- <div className="mt-2 pt-2 border-t border-port-border">
- <span className="text-xs text-gray-600">ADD</span>
- <span className="font-mono text-gray-300 ml-2">+{exam.add}</span>
- </div>
- )}
- </div>
- ))}
+ </td>
+ </tr>
+ );
+ })}
+ </tbody>
+ </table>
</div>
)}
</div>
diff --git a/client/src/services/api.js b/client/src/services/api.js
index b72ed6a9c3..3da1c8f899 100644
--- a/client/src/services/api.js
+++ b/client/src/services/api.js
@@ -1314,6 +1314,13 @@ export const addEyeExam = (data) => request('/meatspace/eyes', {
method: 'POST',
body: JSON.stringify(data)
});
+export const updateEyeExam = (index, data) => request(`/meatspace/eyes/${index}`, {
+ method: 'PUT',
+ body: JSON.stringify(data)
+});
+export const removeEyeExam = (index) => request(`/meatspace/eyes/${index}`, {
+ method: 'DELETE'
+});
export const getNutritionSummary = () => request('/meatspace/nutrition');
export const getDailyNutrition = (from, to) => {
const params = new URLSearchParams();
diff --git a/server/lib/meatspaceValidation.js b/server/lib/meatspaceValidation.js
index cb218c1e18..9ea1dfd2ef 100644
--- a/server/lib/meatspaceValidation.js
+++ b/server/lib/meatspaceValidation.js
@@ -101,6 +101,16 @@ export const eyeExamSchema = z.object({
leftAxis: z.number().nullable().optional()
});
+export const eyeExamUpdateSchema = z.object({
+ date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional(),
+ rightSphere: z.number().nullable().optional(),
+ rightCylinder: z.number().nullable().optional(),
+ rightAxis: z.number().nullable().optional(),
+ leftSphere: z.number().nullable().optional(),
+ leftCylinder: z.number().nullable().optional(),
+ leftAxis: z.number().nullable().optional()
+});
+
// =============================================================================
// TSV IMPORT
// =============================================================================
diff --git a/server/routes/meatspace.js b/server/routes/meatspace.js
index 786393a66b..ac19766184 100644
--- a/server/routes/meatspace.js
+++ b/server/routes/meatspace.js
@@ -10,6 +10,7 @@ import {
bodyEntrySchema,
epigeneticTestSchema,
eyeExamSchema,
+ eyeExamUpdateSchema,
tsvImportSchema
} from '../lib/meatspaceValidation.js';
import * as meatspaceService from '../services/meatspace.js';
@@ -226,6 +227,33 @@ router.post('/eyes', asyncHandler(async (req, res) => {
res.status(201).json(exam);
}));
+/**
+ * PUT /api/meatspace/eyes/:index
+ * Update an eye exam
+ */
+router.put('/eyes/:index', asyncHandler(async (req, res) => {
+ const index = parseInt(req.params.index, 10);
+ const data = validateRequest(eyeExamUpdateSchema, req.body);
+ const exam = await healthService.updateEyeExam(index, data);
+ if (!exam) {
+ throw new ServerError('Eye exam not found', { status: 404, code: 'NOT_FOUND' });
+ }
+ res.json(exam);
+}));
+
+/**
+ * DELETE /api/meatspace/eyes/:index
+ * Remove an eye exam
+ */
+router.delete('/eyes/:index', asyncHandler(async (req, res) => {
+ const index = parseInt(req.params.index, 10);
+ const removed = await healthService.removeEyeExam(index);
+ if (!removed) {
+ throw new ServerError('Eye exam not found', { status: 404, code: 'NOT_FOUND' });
+ }
+ res.json(removed);
+}));
+
// =============================================================================
// NUTRITION
// =============================================================================
diff --git a/server/services/meatspaceHealth.js b/server/services/meatspaceHealth.js
index 823149bd3b..a40f93e23a 100644
--- a/server/services/meatspaceHealth.js
+++ b/server/services/meatspaceHealth.js
@@ -98,6 +98,33 @@ export async function addEyeExam(exam) {
return exam;
}
+export async function updateEyeExam(index, updates) {
+ const data = await getEyeExams();
+ if (index < 0 || index >= data.exams.length) return null;
+
+ const exam = data.exams[index];
+ for (const key of ['date', 'leftSphere', 'leftCylinder', 'leftAxis', 'rightSphere', 'rightCylinder', 'rightAxis']) {
+ if (updates[key] !== undefined) exam[key] = updates[key];
+ }
+
+ data.exams.sort((a, b) => a.date.localeCompare(b.date));
+ await ensureMeatspaceDir();
+ await writeFile(EYES_FILE, JSON.stringify(data, null, 2));
+ console.log(`👁️ Eye exam updated at index ${index}: ${exam.date}`);
+ return exam;
+}
+
+export async function removeEyeExam(index) {
+ const data = await getEyeExams();
+ if (index < 0 || index >= data.exams.length) return null;
+
+ const [removed] = data.exams.splice(index, 1);
+ await ensureMeatspaceDir();
+ await writeFile(EYES_FILE, JSON.stringify(data, null, 2));
+ console.log(`👁️ Eye exam removed: ${removed.date}`);
+ return removed;
+}
+
// === Nutrition ===
export async function getNutritionSummary() {