Membership-System und Bug Fixing (inkl. Nutrition) #8
|
|
@ -322,9 +322,10 @@ function CalorieBalance({ data, profile }) {
|
||||||
|
|
||||||
// ── Main Page ─────────────────────────────────────────────────────────────────
|
// ── Main Page ─────────────────────────────────────────────────────────────────
|
||||||
export default function NutritionPage() {
|
export default function NutritionPage() {
|
||||||
const [tab, setTab] = useState('overview')
|
const [tab, setTab] = useState('data') // BUG-002 fix: show data first
|
||||||
const [corrData, setCorr] = useState([])
|
const [corrData, setCorr] = useState([])
|
||||||
const [weekly, setWeekly] = useState([])
|
const [weekly, setWeekly] = useState([])
|
||||||
|
const [entries, setEntries]= useState([]) // BUG-002 fix: raw data
|
||||||
const [profile, setProf] = useState(null)
|
const [profile, setProf] = useState(null)
|
||||||
const [loading, setLoad] = useState(true)
|
const [loading, setLoad] = useState(true)
|
||||||
const [hasData, setHasData]= useState(false)
|
const [hasData, setHasData]= useState(false)
|
||||||
|
|
@ -332,13 +333,15 @@ export default function NutritionPage() {
|
||||||
const load = async () => {
|
const load = async () => {
|
||||||
setLoad(true)
|
setLoad(true)
|
||||||
try {
|
try {
|
||||||
const [corr, wkly, prof] = await Promise.all([
|
const [corr, wkly, ent, prof] = await Promise.all([
|
||||||
nutritionApi.nutritionCorrelations(),
|
nutritionApi.nutritionCorrelations(),
|
||||||
nutritionApi.nutritionWeekly(16),
|
nutritionApi.nutritionWeekly(16),
|
||||||
|
nutritionApi.listNutrition(365), // BUG-002 fix: load raw entries
|
||||||
api.getActiveProfile(),
|
api.getActiveProfile(),
|
||||||
])
|
])
|
||||||
setCorr(Array.isArray(corr)?corr:[])
|
setCorr(Array.isArray(corr)?corr:[])
|
||||||
setWeekly(Array.isArray(wkly)?wkly:[])
|
setWeekly(Array.isArray(wkly)?wkly:[])
|
||||||
|
setEntries(Array.isArray(ent)?ent:[]) // BUG-002 fix
|
||||||
setProf(prof)
|
setProf(prof)
|
||||||
setHasData(Array.isArray(corr) && corr.some(d=>d.kcal))
|
setHasData(Array.isArray(corr) && corr.some(d=>d.kcal))
|
||||||
} catch(e) { console.error('load error:', e) }
|
} catch(e) { console.error('load error:', e) }
|
||||||
|
|
@ -367,12 +370,45 @@ export default function NutritionPage() {
|
||||||
<OverviewCards data={corrData}/>
|
<OverviewCards data={corrData}/>
|
||||||
|
|
||||||
<div className="tabs section-gap" style={{overflowX:'auto',flexWrap:'nowrap'}}>
|
<div className="tabs section-gap" style={{overflowX:'auto',flexWrap:'nowrap'}}>
|
||||||
|
<button className={'tab'+(tab==='data'?' active':'')} onClick={()=>setTab('data')}>Daten</button>
|
||||||
<button className={'tab'+(tab==='overview'?' active':'')} onClick={()=>setTab('overview')}>Übersicht</button>
|
<button className={'tab'+(tab==='overview'?' active':'')} onClick={()=>setTab('overview')}>Übersicht</button>
|
||||||
<button className={'tab'+(tab==='weight'?' active':'')} onClick={()=>setTab('weight')}>Kcal vs. Gewicht</button>
|
<button className={'tab'+(tab==='weight'?' active':'')} onClick={()=>setTab('weight')}>Kcal vs. Gewicht</button>
|
||||||
<button className={'tab'+(tab==='protein'?' active':'')} onClick={()=>setTab('protein')}>Protein vs. Mager</button>
|
<button className={'tab'+(tab==='protein'?' active':'')} onClick={()=>setTab('protein')}>Protein vs. Mager</button>
|
||||||
<button className={'tab'+(tab==='balance'?' active':'')} onClick={()=>setTab('balance')}>Bilanz</button>
|
<button className={'tab'+(tab==='balance'?' active':'')} onClick={()=>setTab('balance')}>Bilanz</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{tab==='data' && (
|
||||||
|
<div className="card section-gap">
|
||||||
|
<div className="card-title">Alle Einträge ({entries.length})</div>
|
||||||
|
{entries.length === 0 && (
|
||||||
|
<p className="muted">Noch keine Ernährungsdaten. Importiere FDDB CSV oben.</p>
|
||||||
|
)}
|
||||||
|
{entries.map((e, i) => (
|
||||||
|
<div key={e.id || i} style={{
|
||||||
|
borderBottom: i < entries.length - 1 ? '1px solid var(--border)' : 'none',
|
||||||
|
padding: '10px 0'
|
||||||
|
}}>
|
||||||
|
<div style={{display:'flex', justifyContent:'space-between', alignItems:'center', marginBottom:4}}>
|
||||||
|
<strong style={{fontSize:14}}>{dayjs(e.date).format('dd, DD. MMMM YYYY')}</strong>
|
||||||
|
<div style={{fontSize:13, fontWeight:600, color:'#EF9F27'}}>
|
||||||
|
{Math.round(e.kcal || 0)} kcal
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div style={{display:'flex', gap:12, fontSize:12, color:'var(--text2)'}}>
|
||||||
|
<span>🥩 Protein: <strong>{Math.round(e.protein_g || 0)}g</strong></span>
|
||||||
|
<span>🫙 Fett: <strong>{Math.round(e.fat_g || 0)}g</strong></span>
|
||||||
|
<span>🍞 Kohlenhydrate: <strong>{Math.round(e.carbs_g || 0)}g</strong></span>
|
||||||
|
</div>
|
||||||
|
{e.source && (
|
||||||
|
<div style={{fontSize:10, color:'var(--text3)', marginTop:2}}>
|
||||||
|
Quelle: {e.source}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{tab==='overview' && (
|
{tab==='overview' && (
|
||||||
<div className="card section-gap">
|
<div className="card section-gap">
|
||||||
<div className="card-title">Makro-Verteilung pro Woche (Ø g/Tag)</div>
|
<div className="card-title">Makro-Verteilung pro Woche (Ø g/Tag)</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user