feat: Enhance dashboard widget configuration and introduce new widgets
- Updated the dashboard layout schema to include new widgets: DashboardGreeting, QuickWeightToday, BodyStatStrip, StatusPills, ProfileGoalsProgress, TrendKcalWeight, NutritionActivitySummary, RecoverySleepRest, and TrainingTypeDistribution. - Improved widget configuration validation to support new features, including chart days for trend and distribution widgets. - Refactored the default lab layout to align with the updated widget catalog and ensure proper default activation. - Bumped app_dashboard version to 1.6.0 to reflect the addition of new widgets and configuration enhancements.
This commit is contained in:
1 parent
c0c512e942
commit
3d498d03c1
28 files changed
+1487
-243
No files matched your search
@@ -0,0 +1,107 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { Brain } from 'lucide-react'
|
||||
import dayjs from 'dayjs'
|
||||
import 'dayjs/locale/de'
|
||||
import { api } from '../../utils/api'
|
||||
import Markdown from '../../utils/Markdown'
|
||||
|
||||
dayjs.locale('de')
|
||||
|
||||
export default function AiPipelineInsightWidget({ refreshTick = 0 }) {
|
||||
const nav = useNavigate()
|
||||
const [insights, setInsights] = useState([])
|
||||
const [showInsight, setShowInsight] = useState(false)
|
||||
const [pipelineLoading, setPipelineLoading] = useState(false)
|
||||
const [pipelineError, setPipelineError] = useState(null)
|
||||
|
||||
const load = () =>
|
||||
api.latestInsights().then((ins) => setInsights(Array.isArray(ins) ? ins : [])).catch(() => setInsights([]))
|
||||
|
||||
useEffect(() => {
|
||||
load()
|
||||
}, [refreshTick])
|
||||
|
||||
const runPipeline = async () => {
|
||||
setPipelineLoading(true)
|
||||
setPipelineError(null)
|
||||
try {
|
||||
await api.insightPipeline()
|
||||
await load()
|
||||
} catch (e) {
|
||||
setPipelineError(`Fehler: ${e.message}`)
|
||||
} finally {
|
||||
setPipelineLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
const latestInsight = insights.find((i) => i.scope === 'gesamt') || insights[0]
|
||||
|
||||
return (
|
||||
<div className="card section-gap" style={{ marginBottom: 16 }}>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 10 }}>
|
||||
<div style={{ fontSize: 14, fontWeight: 700, color: 'var(--text1)' }}>KI-Auswertung</div>
|
||||
<button type="button" className="btn btn-secondary" style={{ fontSize: 11, padding: '4px 10px' }} onClick={() => nav('/analysis')}>
|
||||
<Brain size={11} /> Analysen →
|
||||
</button>
|
||||
</div>
|
||||
<button type="button" className="btn btn-primary btn-full" style={{ marginBottom: 10 }} onClick={runPipeline} disabled={pipelineLoading}>
|
||||
{pipelineLoading ? (
|
||||
<>
|
||||
<div className="spinner" style={{ width: 13, height: 13 }} /> Analyse läuft… (3 Stufen)
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Brain size={13} /> 🔬 Mehrstufige Analyse starten
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
{pipelineError && <div style={{ fontSize: 12, color: '#D85A30', marginBottom: 8 }}>{pipelineError}</div>}
|
||||
|
||||
{latestInsight ? (
|
||||
<>
|
||||
<div style={{ fontSize: 11, color: 'var(--text3)', marginBottom: 6 }}>
|
||||
Letzte Analyse: {dayjs(latestInsight.created).format('DD. MMMM YYYY, HH:mm')}
|
||||
</div>
|
||||
<div style={{ maxHeight: showInsight ? 'none' : 120, overflow: 'hidden', position: 'relative' }}>
|
||||
<Markdown text={latestInsight.content} />
|
||||
{!showInsight && (
|
||||
<div
|
||||
style={{
|
||||
position: 'absolute',
|
||||
bottom: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
height: 40,
|
||||
background: 'linear-gradient(transparent,var(--surface))',
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
style={{
|
||||
background: 'none',
|
||||
border: 'none',
|
||||
cursor: 'pointer',
|
||||
fontSize: 12,
|
||||
color: 'var(--accent)',
|
||||
marginTop: 6,
|
||||
padding: 0,
|
||||
}}
|
||||
onClick={() => setShowInsight((s) => !s)}
|
||||
>
|
||||
{showInsight ? '▲ Weniger anzeigen' : '▼ Vollständig anzeigen'}
|
||||
</button>
|
||||
</>
|
||||
) : (
|
||||
<div style={{ fontSize: 13, color: 'var(--text3)', padding: '8px 0' }}>
|
||||
Noch keine KI-Auswertung vorhanden.
|
||||
<button type="button" className="btn btn-primary" style={{ marginTop: 8, display: 'block', fontSize: 12 }} onClick={() => nav('/analysis')}>
|
||||
Erste Analyse erstellen
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import dayjs from 'dayjs'
|
||||
import { api } from '../../utils/api'
|
||||
import { useProfile } from '../../context/ProfileContext'
|
||||
import { getBfCategory } from '../../utils/calc'
|
||||
import { StatCard } from '../DashboardStatKit'
|
||||
import { dashboardStatGridClassName, DASHBOARD_TILE_GRID_COLS } from '../../utils/dashboardLayout'
|
||||
|
||||
export default function BodyStatStripWidget({ refreshTick = 0 }) {
|
||||
const nav = useNavigate()
|
||||
const { activeProfile } = useProfile()
|
||||
const sex = activeProfile?.sex || 'm'
|
||||
const [weights, setWeights] = useState([])
|
||||
const [calipers, setCalipers] = useState([])
|
||||
const [nutrition, setNutrition] = useState([])
|
||||
|
||||
useEffect(() => {
|
||||
Promise.all([api.listWeight(60), api.listCaliper(3), api.listNutrition(30)])
|
||||
.then(([w, ca, n]) => {
|
||||
setWeights(w)
|
||||
setCalipers(ca)
|
||||
setNutrition(n)
|
||||
})
|
||||
.catch(() => {
|
||||
setWeights([])
|
||||
setCalipers([])
|
||||
setNutrition([])
|
||||
})
|
||||
}, [refreshTick])
|
||||
|
||||
const latestW = weights[0]
|
||||
const prevW = weights[1]
|
||||
const latestCal = calipers[0]
|
||||
const wDelta = latestW && prevW ? Math.round((latestW.weight - prevW.weight) * 10) / 10 : null
|
||||
const bfCat = latestCal?.body_fat_pct ? getBfCategory(latestCal.body_fat_pct, sex) : null
|
||||
const bfPrev = calipers[1]?.body_fat_pct
|
||||
const bfDelta =
|
||||
latestCal?.body_fat_pct && bfPrev ? Math.round((latestCal.body_fat_pct - bfPrev) * 10) / 10 : null
|
||||
|
||||
const recentNutr = nutrition.filter((n) => n.date >= dayjs().subtract(7, 'day').format('YYYY-MM-DD'))
|
||||
const avgKcal = recentNutr.length
|
||||
? Math.round(recentNutr.reduce((s, n) => s + (n.kcal || 0), 0) / recentNutr.length)
|
||||
: null
|
||||
|
||||
if (!latestW && !latestCal?.body_fat_pct && !avgKcal) {
|
||||
return (
|
||||
<div className="card section-gap" style={{ marginBottom: 16, fontSize: 13, color: 'var(--text3)' }}>
|
||||
Noch keine Kennzahlen – erfasse Gewicht oder Körperdaten.
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="card section-gap" style={{ marginBottom: 16 }}>
|
||||
<div style={{ fontSize: 14, fontWeight: 700, marginBottom: 10, color: 'var(--text1)' }}>Kennzahlen</div>
|
||||
<div className={dashboardStatGridClassName(DASHBOARD_TILE_GRID_COLS.mobile)}>
|
||||
{latestW && (
|
||||
<StatCard
|
||||
icon="⚖️"
|
||||
label="Gewicht"
|
||||
value={latestW.weight}
|
||||
unit="kg"
|
||||
delta={wDelta}
|
||||
deltaGoodWhenNeg
|
||||
sub={dayjs(latestW.date).format('DD.MM.')}
|
||||
onClick={() => nav('/history')}
|
||||
color="#378ADD"
|
||||
/>
|
||||
)}
|
||||
{latestCal?.body_fat_pct != null && (
|
||||
<StatCard
|
||||
icon="🫧"
|
||||
label="Körperfett"
|
||||
value={latestCal.body_fat_pct}
|
||||
unit="%"
|
||||
delta={bfDelta}
|
||||
deltaGoodWhenNeg
|
||||
sub={bfCat?.label}
|
||||
onClick={() => nav('/history', { state: { tab: 'body' } })}
|
||||
color={bfCat?.color}
|
||||
/>
|
||||
)}
|
||||
{latestCal?.lean_mass != null && (
|
||||
<StatCard
|
||||
icon="💪"
|
||||
label="Magermasse"
|
||||
value={latestCal.lean_mass}
|
||||
unit="kg"
|
||||
sub={latestCal.date ? dayjs(latestCal.date).format('DD.MM.') : '–'}
|
||||
onClick={() => nav('/history', { state: { tab: 'body' } })}
|
||||
/>
|
||||
)}
|
||||
{avgKcal != null && (
|
||||
<StatCard
|
||||
icon="🍽️"
|
||||
label="Ø Kalorien"
|
||||
value={avgKcal}
|
||||
unit="kcal"
|
||||
sub="letzte 7 Tage"
|
||||
onClick={() => nav('/history', { state: { tab: 'nutrition' } })}
|
||||
color="#EF9F27"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import dayjs from 'dayjs'
|
||||
import 'dayjs/locale/de'
|
||||
import { useProfile } from '../../context/ProfileContext'
|
||||
import { api } from '../../utils/api'
|
||||
|
||||
dayjs.locale('de')
|
||||
|
||||
/** Produkt-Dashboard: Begrüßung + Datum + letztes Gewicht-Datum */
|
||||
export default function DashboardGreetingWidget({ refreshTick = 0 }) {
|
||||
const { activeProfile } = useProfile()
|
||||
const [latestWeightDate, setLatestWeightDate] = useState(null)
|
||||
|
||||
useEffect(() => {
|
||||
api
|
||||
.listWeight(1)
|
||||
.then((rows) => {
|
||||
setLatestWeightDate(rows?.[0]?.date || null)
|
||||
})
|
||||
.catch(() => setLatestWeightDate(null))
|
||||
}, [refreshTick])
|
||||
|
||||
return (
|
||||
<div className="card section-gap" style={{ marginBottom: 16 }}>
|
||||
<h2 style={{ fontSize: 22, fontWeight: 800, margin: 0, color: 'var(--text1)' }}>
|
||||
Hallo, {activeProfile?.name || 'Nutzer'} 👋
|
||||
</h2>
|
||||
<div style={{ fontSize: 12, color: 'var(--text3)', marginTop: 2 }}>
|
||||
{dayjs().format('dddd, DD. MMMM YYYY')}
|
||||
{latestWeightDate && ` · Letztes Update ${dayjs(latestWeightDate).format('DD.MM.')}`}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useProfile } from '../../context/ProfileContext'
|
||||
import { api } from '../../utils/api'
|
||||
|
||||
export default function GoalsFocusTeaserWidget({ refreshTick = 0 }) {
|
||||
const nav = useNavigate()
|
||||
const { activeProfile } = useProfile()
|
||||
const [goalsCount, setGoalsCount] = useState(null)
|
||||
|
||||
useEffect(() => {
|
||||
if (!activeProfile?.id) return
|
||||
api
|
||||
.listGoals()
|
||||
.then((list) => setGoalsCount(Array.isArray(list) ? list.length : 0))
|
||||
.catch(() => setGoalsCount(null))
|
||||
}, [activeProfile?.id, refreshTick])
|
||||
|
||||
return (
|
||||
<div className="card section-gap" style={{ marginBottom: 16 }}>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 8 }}>
|
||||
<div style={{ fontSize: 14, fontWeight: 700, color: 'var(--text1)' }}>Ziele & Fokus</div>
|
||||
<button type="button" className="btn btn-secondary" style={{ fontSize: 12, padding: '6px 12px' }} onClick={() => nav('/goals')}>
|
||||
Bearbeiten →
|
||||
</button>
|
||||
</div>
|
||||
<div
|
||||
style={{ cursor: 'pointer' }}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onKeyDown={(e) => e.key === 'Enter' && nav('/goals')}
|
||||
onClick={() => nav('/goals')}
|
||||
>
|
||||
{goalsCount != null && (
|
||||
<div style={{ fontSize: 13, fontWeight: 600, color: 'var(--text1)', marginBottom: 8 }}>
|
||||
{goalsCount === 0
|
||||
? 'Noch keine Ziele angelegt.'
|
||||
: `${goalsCount} ${goalsCount === 1 ? 'Ziel' : 'Ziele'} im System.`}
|
||||
</div>
|
||||
)}
|
||||
<div style={{ fontSize: 12, color: 'var(--text2)' }}>
|
||||
Focus Areas und Fortschritt – tippen zum Öffnen der Ziele-Seite.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import dayjs from 'dayjs'
|
||||
import { api } from '../../utils/api'
|
||||
import {
|
||||
dashboardTileGridClassName,
|
||||
DASHBOARD_TILE_GRID_COLS,
|
||||
} from '../../utils/dashboardLayout'
|
||||
import DashboardTile from '../DashboardTile'
|
||||
|
||||
export default function NutritionActivitySummaryWidget({ refreshTick = 0 }) {
|
||||
const nav = useNavigate()
|
||||
const [nutrition, setNutrition] = useState([])
|
||||
const [activities, setActivities] = useState([])
|
||||
const [latestWeight, setLatestWeight] = useState(null)
|
||||
|
||||
useEffect(() => {
|
||||
Promise.all([api.listNutrition(30), api.listActivity(800, 30), api.listWeight(1)])
|
||||
.then(([n, a, w]) => {
|
||||
setNutrition(n)
|
||||
setActivities(a)
|
||||
setLatestWeight(w?.[0]?.weight ?? null)
|
||||
})
|
||||
.catch(() => {
|
||||
setNutrition([])
|
||||
setActivities([])
|
||||
setLatestWeight(null)
|
||||
})
|
||||
}, [refreshTick])
|
||||
|
||||
const recentNutr = nutrition.filter((n) => n.date >= dayjs().subtract(7, 'day').format('YYYY-MM-DD'))
|
||||
const avgKcal = recentNutr.length
|
||||
? Math.round(recentNutr.reduce((s, n) => s + (n.kcal || 0), 0) / recentNutr.length)
|
||||
: null
|
||||
const avgProtein = recentNutr.length
|
||||
? Math.round(recentNutr.reduce((s, n) => s + (n.protein_g || 0), 0) / recentNutr.length * 10) / 10
|
||||
: null
|
||||
const ptLow = Math.round((latestWeight || 80) * 1.6)
|
||||
const proteinOk = avgProtein && avgProtein >= ptLow
|
||||
|
||||
const recentAct = activities.filter((a) => a.date >= dayjs().subtract(7, 'day').format('YYYY-MM-DD'))
|
||||
const actKcal = recentAct.length ? Math.round(recentAct.reduce((s, a) => s + (a.kcal_active || 0), 0)) : null
|
||||
|
||||
const showNutr = !!(avgKcal || avgProtein)
|
||||
const showAct = actKcal != null
|
||||
if (!showNutr && !showAct) {
|
||||
return (
|
||||
<div className="card section-gap" style={{ marginBottom: 16, fontSize: 13, color: 'var(--text3)' }}>
|
||||
Noch keine Ernährungs- oder Aktivitätsdaten (7 Tage).
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const summaryBoth = showNutr && showAct
|
||||
const summarySpanM = summaryBoth ? 1 : 2
|
||||
const summarySpanD = summaryBoth ? 2 : 4
|
||||
|
||||
return (
|
||||
<div className="card section-gap" style={{ marginBottom: 16 }}>
|
||||
<div style={{ fontSize: 14, fontWeight: 700, marginBottom: 10, color: 'var(--text1)' }}>
|
||||
Ernährung & Aktivität
|
||||
</div>
|
||||
<div className={`dashboard-summary-row ${dashboardTileGridClassName(DASHBOARD_TILE_GRID_COLS.mobile)}`}>
|
||||
{showNutr && (
|
||||
<DashboardTile spanMobile={summarySpanM} spanDesktop={summarySpanD}>
|
||||
<div
|
||||
className="card"
|
||||
style={{ cursor: 'pointer', height: '100%' }}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onKeyDown={(e) => e.key === 'Enter' && nav('/history', { state: { tab: 'nutrition' } })}
|
||||
onClick={() => nav('/history', { state: { tab: 'nutrition' } })}
|
||||
>
|
||||
<div style={{ fontWeight: 600, fontSize: 12, marginBottom: 8, color: 'var(--text3)' }}>
|
||||
🍽️ ERNÄHRUNG (Ø 7T)
|
||||
</div>
|
||||
{avgKcal != null && <div style={{ fontSize: 16, fontWeight: 700, color: '#EF9F27' }}>{avgKcal} kcal</div>}
|
||||
{avgProtein != null && (
|
||||
<div
|
||||
style={{
|
||||
fontSize: 13,
|
||||
fontWeight: 600,
|
||||
color: proteinOk ? 'var(--accent)' : 'var(--warn)',
|
||||
}}
|
||||
>
|
||||
{avgProtein}g Protein {proteinOk ? '✓' : '⚠️'}
|
||||
</div>
|
||||
)}
|
||||
<div style={{ fontSize: 10, color: 'var(--text3)', marginTop: 4 }}>→ Verlauf Ernährung</div>
|
||||
</div>
|
||||
</DashboardTile>
|
||||
)}
|
||||
{showAct && (
|
||||
<DashboardTile spanMobile={summarySpanM} spanDesktop={summarySpanD}>
|
||||
<div
|
||||
className="card"
|
||||
style={{ cursor: 'pointer', height: '100%' }}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onKeyDown={(e) => e.key === 'Enter' && nav('/history', { state: { tab: 'activity' } })}
|
||||
onClick={() => nav('/history', { state: { tab: 'activity' } })}
|
||||
>
|
||||
<div style={{ fontWeight: 600, fontSize: 12, marginBottom: 8, color: 'var(--text3)' }}>
|
||||
🏋️ AKTIVITÄT (7T)
|
||||
</div>
|
||||
<div style={{ fontSize: 16, fontWeight: 700, color: '#EF9F27' }}>{actKcal} kcal</div>
|
||||
<div style={{ fontSize: 13, color: 'var(--text2)' }}>{recentAct.length} Trainings</div>
|
||||
<div style={{ fontSize: 10, color: 'var(--text3)', marginTop: 4 }}>→ Verlauf Aktivität</div>
|
||||
</div>
|
||||
</DashboardTile>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useProfile } from '../../context/ProfileContext'
|
||||
import { getBfCategory } from '../../utils/calc'
|
||||
import { api } from '../../utils/api'
|
||||
|
||||
/** Profil-Ziele Gewicht / Körperfett (Balken wie Dashboard) */
|
||||
export default function ProfileGoalsProgressWidget({ refreshTick = 0 }) {
|
||||
const { activeProfile } = useProfile()
|
||||
const sex = activeProfile?.sex || 'm'
|
||||
const [weights, setWeights] = useState([])
|
||||
const [calipers, setCalipers] = useState([])
|
||||
|
||||
useEffect(() => {
|
||||
Promise.all([api.listWeight(120), api.listCaliper(3)])
|
||||
.then(([w, ca]) => {
|
||||
setWeights(w)
|
||||
setCalipers(ca)
|
||||
})
|
||||
.catch(() => {
|
||||
setWeights([])
|
||||
setCalipers([])
|
||||
})
|
||||
}, [refreshTick])
|
||||
|
||||
const latestW = weights[0]
|
||||
const latestCal = calipers[0]
|
||||
const bfCat = latestCal?.body_fat_pct ? getBfCategory(latestCal.body_fat_pct, sex) : null
|
||||
|
||||
const gw = activeProfile?.goal_weight
|
||||
const gbf = activeProfile?.goal_bf_pct
|
||||
if ((!gw || !latestW) && (!gbf || latestCal?.body_fat_pct == null)) return null
|
||||
|
||||
return (
|
||||
<div className="card section-gap" style={{ marginBottom: 16 }}>
|
||||
<div style={{ fontSize: 14, fontWeight: 700, marginBottom: 10, color: 'var(--text1)' }}>Profil-Ziele</div>
|
||||
{gw && latestW && (
|
||||
<div style={{ marginBottom: 10 }}>
|
||||
{(() => {
|
||||
const start = Math.max(...weights.map((w) => w.weight))
|
||||
const curr = latestW.weight
|
||||
const goal = gw
|
||||
const total = start - goal
|
||||
const done = start - curr
|
||||
const pct = total > 0 ? Math.min(100, Math.round((done / total) * 100)) : 100
|
||||
const remain = Math.round((curr - goal) * 10) / 10
|
||||
return (
|
||||
<>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', fontSize: 12, marginBottom: 4 }}>
|
||||
<span>
|
||||
Gewicht: {curr} → {goal} kg
|
||||
</span>
|
||||
<span style={{ color: 'var(--accent)', fontWeight: 600 }}>
|
||||
{remain > 0 ? `noch ${remain}kg` : 'Ziel erreicht! 🎉'}
|
||||
</span>
|
||||
</div>
|
||||
<div style={{ height: 8, background: 'var(--border)', borderRadius: 4, overflow: 'hidden' }}>
|
||||
<div
|
||||
style={{
|
||||
height: '100%',
|
||||
width: `${pct}%`,
|
||||
background: 'var(--accent)',
|
||||
borderRadius: 4,
|
||||
transition: 'width 0.5s',
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div style={{ fontSize: 10, color: 'var(--text3)', marginTop: 2 }}>{pct}% des Weges</div>
|
||||
</>
|
||||
)
|
||||
})()}
|
||||
</div>
|
||||
)}
|
||||
{gbf && latestCal?.body_fat_pct != null && (
|
||||
<div>
|
||||
{(() => {
|
||||
const curr = latestCal.body_fat_pct
|
||||
const goal = gbf
|
||||
const remain = Math.round((curr - goal) * 10) / 10
|
||||
const pct =
|
||||
curr <= goal ? 100 : Math.min(100, Math.round((1 - (curr - goal) / Math.max(curr - goal, 5)) * 100))
|
||||
return (
|
||||
<>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', fontSize: 12, marginBottom: 4 }}>
|
||||
<span>
|
||||
Körperfett: {curr}% → {goal}%
|
||||
</span>
|
||||
<span style={{ color: 'var(--accent)', fontWeight: 600 }}>
|
||||
{remain > 0 ? `noch ${remain}%` : 'Ziel erreicht! 🎉'}
|
||||
</span>
|
||||
</div>
|
||||
<div style={{ height: 8, background: 'var(--border)', borderRadius: 4, overflow: 'hidden' }}>
|
||||
<div
|
||||
style={{
|
||||
height: '100%',
|
||||
width: `${pct}%`,
|
||||
background: bfCat?.color || 'var(--accent)',
|
||||
borderRadius: 4,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div style={{ fontSize: 10, color: 'var(--text3)', marginTop: 2 }}>Aktuell: {bfCat?.label}</div>
|
||||
</>
|
||||
)
|
||||
})()}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import QuickWeightEntry from '../QuickWeightEntry'
|
||||
|
||||
export default function QuickWeightTodayWidget({ onSaved }) {
|
||||
const nav = useNavigate()
|
||||
return (
|
||||
<div className="card section-gap" style={{ marginBottom: 16 }}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8, marginBottom: 10 }}>
|
||||
<div>
|
||||
<div style={{ fontSize: 14, fontWeight: 700, color: 'var(--text1)' }}>Gewicht heute</div>
|
||||
<div style={{ fontSize: 12, color: 'var(--text3)' }}>Tageswert erfassen</div>
|
||||
</div>
|
||||
<button type="button" className="btn btn-secondary" style={{ fontSize: 12, padding: '6px 12px' }} onClick={() => nav('/weight')}>
|
||||
Alle Einträge →
|
||||
</button>
|
||||
</div>
|
||||
<QuickWeightEntry onSaved={onSaved} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import DashboardTile from '../DashboardTile'
|
||||
import SleepWidget from '../SleepWidget'
|
||||
import RestDaysWidget from '../RestDaysWidget'
|
||||
import { dashboardTileGridClassName, DASHBOARD_TILE_GRID_COLS } from '../../utils/dashboardLayout'
|
||||
|
||||
export default function RecoverySleepRestWidget() {
|
||||
return (
|
||||
<div className="card section-gap" style={{ marginBottom: 16 }}>
|
||||
<div style={{ fontSize: 14, fontWeight: 700, marginBottom: 10, color: 'var(--text1)' }}>Erholung</div>
|
||||
<div className={`dashboard-erholung-grid ${dashboardTileGridClassName(DASHBOARD_TILE_GRID_COLS.mobile)}`}>
|
||||
<DashboardTile spanMobile={1} spanDesktop={2}>
|
||||
<SleepWidget />
|
||||
</DashboardTile>
|
||||
<DashboardTile spanMobile={1} spanDesktop={2}>
|
||||
<RestDaysWidget />
|
||||
</DashboardTile>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import dayjs from 'dayjs'
|
||||
import { api } from '../../utils/api'
|
||||
import { useProfile } from '../../context/ProfileContext'
|
||||
import { getBfCategory } from '../../utils/calc'
|
||||
import { Pill } from '../DashboardStatKit'
|
||||
|
||||
/** WHR, WHtR, Protein Ø7T, KF – wie Dashboard-Pill-Leiste */
|
||||
export default function StatusPillsWidget({ refreshTick = 0 }) {
|
||||
const { activeProfile } = useProfile()
|
||||
const sex = activeProfile?.sex || 'm'
|
||||
const height = activeProfile?.height || 178
|
||||
const [weights, setWeights] = useState([])
|
||||
const [calipers, setCalipers] = useState([])
|
||||
const [circs, setCircs] = useState([])
|
||||
const [nutrition, setNutrition] = useState([])
|
||||
|
||||
useEffect(() => {
|
||||
Promise.all([api.listWeight(2), api.listCaliper(3), api.listCirc(2), api.listNutrition(30)])
|
||||
.then(([w, ca, ci, n]) => {
|
||||
setWeights(w)
|
||||
setCalipers(ca)
|
||||
setCircs(ci)
|
||||
setNutrition(n)
|
||||
})
|
||||
.catch(() => {
|
||||
setWeights([])
|
||||
setCalipers([])
|
||||
setCircs([])
|
||||
setNutrition([])
|
||||
})
|
||||
}, [refreshTick])
|
||||
|
||||
const latestCal = calipers[0]
|
||||
const latestCir = circs[0]
|
||||
const latestW = weights[0]
|
||||
|
||||
const recentNutr = nutrition.filter((n) => n.date >= dayjs().subtract(7, 'day').format('YYYY-MM-DD'))
|
||||
const avgProtein = recentNutr.length
|
||||
? Math.round(recentNutr.reduce((s, n) => s + (n.protein_g || 0), 0) / recentNutr.length * 10) / 10
|
||||
: null
|
||||
const ptLow = Math.round((latestW?.weight || 80) * 1.6)
|
||||
const proteinOk = avgProtein && avgProtein >= ptLow
|
||||
|
||||
const whr =
|
||||
latestCir?.c_waist && latestCir?.c_hip
|
||||
? Math.round((latestCir.c_waist / latestCir.c_hip) * 100) / 100
|
||||
: null
|
||||
const whtr =
|
||||
latestCir?.c_waist && height ? Math.round((latestCir.c_waist / height) * 100) / 100 : null
|
||||
const bfCat = latestCal?.body_fat_pct ? getBfCategory(latestCal.body_fat_pct, sex) : null
|
||||
|
||||
const pills = []
|
||||
if (whr)
|
||||
pills.push({
|
||||
label: 'WHR',
|
||||
value: whr,
|
||||
status: whr < (sex === 'm' ? 0.9 : 0.85) ? 'good' : 'warn',
|
||||
sub: `<${sex === 'm' ? '0,90' : '0,85'}`,
|
||||
})
|
||||
if (whtr) pills.push({ label: 'WHtR', value: whtr, status: whtr < 0.5 ? 'good' : 'warn', sub: '<0,50' })
|
||||
if (avgProtein)
|
||||
pills.push({
|
||||
label: 'Protein Ø7T',
|
||||
value: `${avgProtein}g`,
|
||||
status: proteinOk ? 'good' : 'warn',
|
||||
sub: `Ziel ${ptLow}g`,
|
||||
})
|
||||
if (bfCat && latestCal?.body_fat_pct != null)
|
||||
pills.push({
|
||||
label: 'KF',
|
||||
value: `${latestCal.body_fat_pct}%`,
|
||||
status: latestCal.body_fat_pct < (sex === 'm' ? 18 : 25) ? 'good' : 'warn',
|
||||
sub: bfCat.label,
|
||||
})
|
||||
|
||||
if (pills.length === 0) return null
|
||||
|
||||
return (
|
||||
<div className="card section-gap" style={{ marginBottom: 16 }}>
|
||||
<div style={{ fontSize: 12, fontWeight: 600, color: 'var(--text3)', marginBottom: 8 }}>Indikatoren</div>
|
||||
<div className="dashboard-pill-row">
|
||||
{pills.map((p, i) => (
|
||||
<Pill key={i} {...p} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import TrainingTypeDistribution from '../TrainingTypeDistribution'
|
||||
|
||||
/**
|
||||
* @param {{ refreshTick?: number, distributionDays?: number }} props
|
||||
*/
|
||||
export default function TrainingTypeDistributionWidget({ refreshTick = 0, distributionDays = 28 }) {
|
||||
const nav = useNavigate()
|
||||
const days = Math.max(7, Math.min(120, Number(distributionDays) || 28))
|
||||
|
||||
return (
|
||||
<div className="card section-gap" style={{ marginBottom: 16 }}>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 8 }}>
|
||||
<div>
|
||||
<div style={{ fontSize: 14, fontWeight: 700, color: 'var(--text1)' }}>Training</div>
|
||||
<div style={{ fontSize: 12, color: 'var(--text3)' }}>Verteilung der Trainingstypen ({days} Tage)</div>
|
||||
</div>
|
||||
<button type="button" className="btn btn-secondary" style={{ fontSize: 12, padding: '6px 12px' }} onClick={() => nav('/activity')}>
|
||||
Details →
|
||||
</button>
|
||||
</div>
|
||||
<TrainingTypeDistribution key={`${refreshTick}-${days}`} days={days} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { api } from '../../utils/api'
|
||||
import TrendKcalWeightChart from '../TrendKcalWeightChart'
|
||||
import { normalizeBodyChartDays } from '../../widgetSystem/bodyChartDays'
|
||||
|
||||
/**
|
||||
* @param {{ refreshTick?: number, chartDays?: number }} props
|
||||
*/
|
||||
export default function TrendKcalWeightWidget({ refreshTick = 0, chartDays }) {
|
||||
const nav = useNavigate()
|
||||
const windowDays = chartDays != null ? normalizeBodyChartDays(chartDays) : 30
|
||||
const fetchNutritionDays = Math.max(windowDays, 30)
|
||||
const [weights, setWeights] = useState([])
|
||||
const [nutrition, setNutrition] = useState([])
|
||||
|
||||
useEffect(() => {
|
||||
Promise.all([api.listWeight(Math.max(60, windowDays + 30)), api.listNutrition(fetchNutritionDays)])
|
||||
.then(([w, n]) => {
|
||||
setWeights(w)
|
||||
setNutrition(n)
|
||||
})
|
||||
.catch(() => {
|
||||
setWeights([])
|
||||
setNutrition([])
|
||||
})
|
||||
}, [refreshTick, windowDays, fetchNutritionDays])
|
||||
|
||||
if (weights.length <= 2 && nutrition.length <= 2) {
|
||||
return (
|
||||
<div className="card section-gap" style={{ marginBottom: 16, fontSize: 13, color: 'var(--text3)' }}>
|
||||
Mehr Gewichts- und Ernährungsdaten für den Trend nötig.
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="card section-gap" style={{ marginBottom: 16 }}>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 8 }}>
|
||||
<div>
|
||||
<div style={{ fontSize: 14, fontWeight: 700, color: 'var(--text1)' }}>Trends</div>
|
||||
<div style={{ fontSize: 12, color: 'var(--text3)' }}>
|
||||
Kalorien und Gewicht ({windowDays} Tage)
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-secondary"
|
||||
style={{ fontSize: 12, padding: '6px 12px' }}
|
||||
onClick={() => nav('/history', { state: { tab: 'body' } })}
|
||||
>
|
||||
Details →
|
||||
</button>
|
||||
</div>
|
||||
<TrendKcalWeightChart weights={weights} nutrition={nutrition} windowDays={windowDays} />
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
gap: 16,
|
||||
justifyContent: 'center',
|
||||
marginTop: 6,
|
||||
fontSize: 10,
|
||||
color: 'var(--text3)',
|
||||
}}
|
||||
>
|
||||
<span>
|
||||
<span
|
||||
style={{
|
||||
display: 'inline-block',
|
||||
width: 12,
|
||||
height: 2,
|
||||
background: '#EF9F27',
|
||||
verticalAlign: 'middle',
|
||||
marginRight: 3,
|
||||
}}
|
||||
/>
|
||||
Ø Kalorien
|
||||
</span>
|
||||
<span>
|
||||
<span
|
||||
style={{
|
||||
display: 'inline-block',
|
||||
width: 12,
|
||||
height: 2,
|
||||
background: '#378ADD',
|
||||
verticalAlign: 'middle',
|
||||
marginRight: 3,
|
||||
}}
|
||||
/>
|
||||
Gewicht
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user