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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
feat(03-03): create four health metric cards and HealthTab container
Adam Eivy11cc0eaf6bdf
diff --git a/client/src/components/meatspace/HeartRateCard.jsx b/client/src/components/meatspace/HeartRateCard.jsxnew file mode 100644index 0000000000..df497d6dfa--- /dev/null+++ b/client/src/components/meatspace/HeartRateCard.jsx@@ -0,0 +1,51 @@+import {+ LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer+} from 'recharts';++const CustomTooltip = ({ active, payload, label }) => {+ if (!active || !payload?.length) return null;+ return (+ <div style={{ background: '#1a1a1a', border: '1px solid #2a2a2a', color: '#fff', padding: '8px', borderRadius: '6px', fontSize: '12px' }}>+ <p style={{ color: '#9ca3af', marginBottom: 2 }}>{label}</p>+ <p style={{ color: '#ef4444', fontWeight: 600 }}>{Math.round(payload[0].value)} bpm</p>+ </div>+ );+};++export default function HeartRateCard({ data = [], loading = false }) {+ const avg = data.length > 0+ ? Math.round(data.reduce((sum, d) => sum + (d.value ?? 0), 0) / data.length)+ : null;++ const chartData = data.map(d => ({+ date: d.date?.slice(5) ?? d.date,+ value: d.value ?? 0+ }));++ return (+ <div className="bg-port-card border border-port-border rounded-xl p-6">+ <h3 className="text-xs font-medium text-gray-400 uppercase tracking-wider mb-3">Heart Rate</h3>+ {loading ? (+ <div className="flex items-center justify-center h-40 text-gray-600 text-sm">Loading...</div>+ ) : avg == null ? (+ <div className="flex items-center justify-center h-40 text-gray-600 text-sm">No heart rate data available</div>+ ) : (+ <>+ <div className="mb-4">+ <span className="text-3xl font-bold text-white font-mono">{avg}</span>+ <span className="text-sm text-gray-500 ml-2">bpm</span>+ </div>+ <ResponsiveContainer width="100%" height={150}>+ <LineChart data={chartData} margin={{ top: 2, right: 8, bottom: 2, left: 0 }}>+ <CartesianGrid strokeDasharray="3 3" stroke="#2a2a2a" />+ <XAxis dataKey="date" tick={{ fill: '#9ca3af', fontSize: 11 }} interval="preserveStartEnd" />+ <YAxis tick={{ fill: '#9ca3af', fontSize: 11 }} width={40} domain={['auto', 'auto']} />+ <Tooltip content={<CustomTooltip />} />+ <Line type="monotone" dataKey="value" stroke="#ef4444" strokeWidth={2} dot={false} />+ </LineChart>+ </ResponsiveContainer>+ </>+ )}+ </div>+ );+}diff --git a/client/src/components/meatspace/HrvCard.jsx b/client/src/components/meatspace/HrvCard.jsxnew file mode 100644index 0000000000..212fdf3c74--- /dev/null+++ b/client/src/components/meatspace/HrvCard.jsx@@ -0,0 +1,51 @@+import {+ LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer+} from 'recharts';++const CustomTooltip = ({ active, payload, label }) => {+ if (!active || !payload?.length) return null;+ return (+ <div style={{ background: '#1a1a1a', border: '1px solid #2a2a2a', color: '#fff', padding: '8px', borderRadius: '6px', fontSize: '12px' }}>+ <p style={{ color: '#9ca3af', marginBottom: 2 }}>{label}</p>+ <p style={{ color: '#22c55e', fontWeight: 600 }}>{Math.round(payload[0].value)} ms</p>+ </div>+ );+};++export default function HrvCard({ data = [], loading = false }) {+ const avg = data.length > 0+ ? Math.round(data.reduce((sum, d) => sum + (d.value ?? 0), 0) / data.length)+ : null;++ const chartData = data.map(d => ({+ date: d.date?.slice(5) ?? d.date,+ value: d.value ?? 0+ }));++ return (+ <div className="bg-port-card border border-port-border rounded-xl p-6">+ <h3 className="text-xs font-medium text-gray-400 uppercase tracking-wider mb-3">HRV</h3>+ {loading ? (+ <div className="flex items-center justify-center h-40 text-gray-600 text-sm">Loading...</div>+ ) : avg == null ? (+ <div className="flex items-center justify-center h-40 text-gray-600 text-sm">No HRV data available</div>+ ) : (+ <>+ <div className="mb-4">+ <span className="text-3xl font-bold text-white font-mono">{avg}</span>+ <span className="text-sm text-gray-500 ml-2">ms</span>+ </div>+ <ResponsiveContainer width="100%" height={150}>+ <LineChart data={chartData} margin={{ top: 2, right: 8, bottom: 2, left: 0 }}>+ <CartesianGrid strokeDasharray="3 3" stroke="#2a2a2a" />+ <XAxis dataKey="date" tick={{ fill: '#9ca3af', fontSize: 11 }} interval="preserveStartEnd" />+ <YAxis tick={{ fill: '#9ca3af', fontSize: 11 }} width={40} domain={['auto', 'auto']} />+ <Tooltip content={<CustomTooltip />} />+ <Line type="monotone" dataKey="value" stroke="#22c55e" strokeWidth={2} dot={false} />+ </LineChart>+ </ResponsiveContainer>+ </>+ )}+ </div>+ );+}diff --git a/client/src/components/meatspace/SleepCard.jsx b/client/src/components/meatspace/SleepCard.jsxnew file mode 100644index 0000000000..a6a2ed79b1--- /dev/null+++ b/client/src/components/meatspace/SleepCard.jsx@@ -0,0 +1,76 @@+import {+ BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer+} from 'recharts';++const STAGE_COLORS = {+ deep: '#3b82f6',+ rem: '#8b5cf6',+ core: '#06b6d4',+ awake: '#6b7280'+};++const CustomTooltip = ({ active, payload, label }) => {+ if (!active || !payload?.length) return null;+ return (+ <div style={{ background: '#1a1a1a', border: '1px solid #2a2a2a', color: '#fff', padding: '8px', borderRadius: '6px', fontSize: '12px' }}>+ <p style={{ color: '#9ca3af', marginBottom: 4 }}>{label}</p>+ {payload.map((entry) => (+ <p key={entry.dataKey} style={{ color: entry.fill, margin: '2px 0' }}>+ {entry.name}: {entry.value != null ? entry.value.toFixed(1) : '—'}h+ </p>+ ))}+ </div>+ );+};++export default function SleepCard({ data = [], loading = false }) {+ const avg = data.length > 0+ ? (data.reduce((sum, d) => sum + (d.totalSleep ?? d.value ?? 0), 0) / data.length)+ : null;++ // Show only last 7 days in stacked bar chart+ const last7 = data.slice(-7).map(d => ({+ date: d.date?.slice(5) ?? d.date,+ deep: d.deep ?? 0,+ rem: d.rem ?? 0,+ core: d.core ?? 0,+ awake: d.awake ?? 0+ }));++ const hasStages = last7.some(d => d.deep > 0 || d.rem > 0 || d.core > 0);++ return (+ <div className="bg-port-card border border-port-border rounded-xl p-6">+ <h3 className="text-xs font-medium text-gray-400 uppercase tracking-wider mb-3">Sleep</h3>+ {loading ? (+ <div className="flex items-center justify-center h-40 text-gray-600 text-sm">Loading...</div>+ ) : avg == null ? (+ <div className="flex items-center justify-center h-40 text-gray-600 text-sm">No sleep data available</div>+ ) : (+ <>+ <div className="mb-4">+ <span className="text-3xl font-bold text-white font-mono">{avg.toFixed(1)}</span>+ <span className="text-sm text-gray-500 ml-2">avg hrs / night</span>+ </div>+ {hasStages ? (+ <ResponsiveContainer width="100%" height={150}>+ <BarChart data={last7} layout="vertical" margin={{ top: 2, right: 8, bottom: 2, left: 16 }}>+ <CartesianGrid strokeDasharray="3 3" stroke="#2a2a2a" horizontal={false} />+ <XAxis type="number" tick={{ fill: '#9ca3af', fontSize: 11 }} unit="h" />+ <YAxis type="category" dataKey="date" tick={{ fill: '#9ca3af', fontSize: 10 }} width={36} />+ <Tooltip content={<CustomTooltip />} />+ <Legend wrapperStyle={{ fontSize: 10, color: '#9ca3af' }} />+ <Bar dataKey="deep" name="Deep" stackId="a" fill={STAGE_COLORS.deep} />+ <Bar dataKey="rem" name="REM" stackId="a" fill={STAGE_COLORS.rem} />+ <Bar dataKey="core" name="Core" stackId="a" fill={STAGE_COLORS.core} />+ <Bar dataKey="awake" name="Awake" stackId="a" fill={STAGE_COLORS.awake} />+ </BarChart>+ </ResponsiveContainer>+ ) : (+ <div className="text-gray-600 text-xs">Sleep stage breakdown not available</div>+ )}+ </>+ )}+ </div>+ );+}diff --git a/client/src/components/meatspace/StepsCard.jsx b/client/src/components/meatspace/StepsCard.jsxnew file mode 100644index 0000000000..5726238edd--- /dev/null+++ b/client/src/components/meatspace/StepsCard.jsx@@ -0,0 +1,51 @@+import {+ LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer+} from 'recharts';++const CustomTooltip = ({ active, payload, label }) => {+ if (!active || !payload?.length) return null;+ return (+ <div style={{ background: '#1a1a1a', border: '1px solid #2a2a2a', color: '#fff', padding: '8px', borderRadius: '6px', fontSize: '12px' }}>+ <p style={{ color: '#9ca3af', marginBottom: 2 }}>{label}</p>+ <p style={{ color: '#3b82f6', fontWeight: 600 }}>{Number(payload[0].value).toLocaleString()} steps</p>+ </div>+ );+};++export default function StepsCard({ data = [], loading = false }) {+ const avg = data.length > 0+ ? Math.round(data.reduce((sum, d) => sum + (d.value ?? 0), 0) / data.length)+ : null;++ const chartData = data.map(d => ({+ date: d.date?.slice(5) ?? d.date,+ value: d.value ?? 0+ }));++ return (+ <div className="bg-port-card border border-port-border rounded-xl p-6">+ <h3 className="text-xs font-medium text-gray-400 uppercase tracking-wider mb-3">Steps</h3>+ {loading ? (+ <div className="flex items-center justify-center h-40 text-gray-600 text-sm">Loading...</div>+ ) : avg == null ? (+ <div className="flex items-center justify-center h-40 text-gray-600 text-sm">No step data available</div>+ ) : (+ <>+ <div className="mb-4">+ <span className="text-3xl font-bold text-white font-mono">{avg.toLocaleString()}</span>+ <span className="text-sm text-gray-500 ml-2">avg daily steps</span>+ </div>+ <ResponsiveContainer width="100%" height={150}>+ <LineChart data={chartData} margin={{ top: 2, right: 8, bottom: 2, left: 0 }}>+ <CartesianGrid strokeDasharray="3 3" stroke="#2a2a2a" />+ <XAxis dataKey="date" tick={{ fill: '#9ca3af', fontSize: 11 }} interval="preserveStartEnd" />+ <YAxis tick={{ fill: '#9ca3af', fontSize: 11 }} width={55} tickFormatter={v => v.toLocaleString()} />+ <Tooltip content={<CustomTooltip />} />+ <Line type="monotone" dataKey="value" stroke="#3b82f6" strokeWidth={2} dot={false} />+ </LineChart>+ </ResponsiveContainer>+ </>+ )}+ </div>+ );+}diff --git a/client/src/components/meatspace/tabs/HealthTab.jsx b/client/src/components/meatspace/tabs/HealthTab.jsxnew file mode 100644index 0000000000..ddd1243425--- /dev/null+++ b/client/src/components/meatspace/tabs/HealthTab.jsx@@ -0,0 +1,87 @@+import { useState, useEffect, useCallback } from 'react';+import * as api from '../../../services/api';+import StepsCard from '../StepsCard';+import HeartRateCard from '../HeartRateCard';+import SleepCard from '../SleepCard';+import HrvCard from '../HrvCard';++const RANGES = [+ { id: '7d', label: '7d', days: 7 },+ { id: '30d', label: '30d', days: 30 },+ { id: '90d', label: '90d', days: 90 },+ { id: '1y', label: '1y', days: 365 }+];++function getFromDate(days) {+ const d = new Date();+ d.setDate(d.getDate() - days);+ return d.toISOString().split('T')[0];+}++export default function HealthTab() {+ const [range, setRange] = useState('7d');+ const [stepsData, setStepsData] = useState([]);+ const [hrData, setHrData] = useState([]);+ const [sleepData, setSleepData] = useState([]);+ const [hrvData, setHrvData] = useState([]);+ const [correlationData, setCorrelationData] = useState(null);+ const [loading, setLoading] = useState(true);++ const fetchData = useCallback(async () => {+ setLoading(true);+ const days = RANGES.find(r => r.id === range)?.days ?? 7;+ const from = getFromDate(days);+ const to = new Date().toISOString().split('T')[0];++ const [steps, hr, sleep, hrv, correlation] = await Promise.all([+ api.getAppleHealthMetrics('step_count', from, to).catch(() => []),+ api.getAppleHealthMetrics('heart_rate', from, to).catch(() => []),+ api.getAppleHealthMetrics('sleep_analysis', from, to).catch(() => []),+ api.getAppleHealthMetrics('heart_rate_variability_sdnn', from, to).catch(() => []),+ api.getAppleHealthCorrelation(from, to).catch(() => null)+ ]);++ setStepsData(Array.isArray(steps) ? steps : []);+ setHrData(Array.isArray(hr) ? hr : []);+ setSleepData(Array.isArray(sleep) ? sleep : []);+ setHrvData(Array.isArray(hrv) ? hrv : []);+ setCorrelationData(correlation);+ setLoading(false);+ }, [range]);++ useEffect(() => {+ fetchData();+ }, [fetchData]);++ return (+ <div className="space-y-6">+ {/* Range selector */}+ <div className="flex items-center gap-1">+ {RANGES.map(r => (+ <button+ key={r.id}+ onClick={() => setRange(r.id)}+ className={`px-3 py-1.5 text-sm rounded-lg transition-colors font-medium ${+ range === r.id+ ? 'bg-port-accent/10 text-port-accent'+ : 'text-gray-400 hover:text-white hover:bg-port-border/50'+ }`}+ >+ {r.label}+ </button>+ ))}+ </div>++ {/* Metric cards — 2-column grid */}+ <div className="grid grid-cols-1 lg:grid-cols-2 gap-6">+ <StepsCard data={stepsData} loading={loading} />+ <HeartRateCard data={hrData} loading={loading} />+ <SleepCard data={sleepData} loading={loading} />+ <HrvCard data={hrvData} loading={loading} />+ </div>++ {/* Correlation charts — wired in Task 2 */}+ <div />+ </div>+ );+}