| 1 | import { useEffect, useState } from 'react'
|
|---|
| 2 | import { api } from '../lib/api.js'
|
|---|
| 3 |
|
|---|
| 4 | export default function Trainer() {
|
|---|
| 5 | const [email, setEmail] = useState('marija.trajkovska@gmail.com')
|
|---|
| 6 | const [from, setFrom] = useState('2026-01-20')
|
|---|
| 7 | const [to, setTo] = useState('2026-02-01')
|
|---|
| 8 | const [intake, setIntake] = useState([])
|
|---|
| 9 | const [macros, setMacros] = useState([])
|
|---|
| 10 | const [progress, setProgress] = useState([])
|
|---|
| 11 | const [density, setDensity] = useState([])
|
|---|
| 12 | const [nutrient, setNutrient] = useState('Protein')
|
|---|
| 13 | const [error, setError] = useState(null)
|
|---|
| 14 |
|
|---|
| 15 | const loadClient = async () => {
|
|---|
| 16 | setError(null)
|
|---|
| 17 | try {
|
|---|
| 18 | setIntake(await api.get(`/trainer/clients/${email}/intake?from=${from}&to=${to}`))
|
|---|
| 19 | setMacros(await api.get(`/trainer/clients/${email}/macros?from=${from}&to=${to}`))
|
|---|
| 20 | setProgress(await api.get(`/trainer/clients/${email}/progress`))
|
|---|
| 21 | } catch (e) { setError(e.message) }
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | const loadDensity = () =>
|
|---|
| 25 | api.get(`/trainer/analysis/nutrient-density?nutrient=${nutrient}&limit=8`)
|
|---|
| 26 | .then(setDensity).catch(e => setError(e.message))
|
|---|
| 27 |
|
|---|
| 28 | useEffect(() => { loadDensity() }, [])
|
|---|
| 29 |
|
|---|
| 30 | return (
|
|---|
| 31 | <div>
|
|---|
| 32 | {error && <div className="error">{error}</div>}
|
|---|
| 33 |
|
|---|
| 34 | <div className="card">
|
|---|
| 35 | <h3>Client report</h3>
|
|---|
| 36 | <div className="row">
|
|---|
| 37 | <input style={{ flex: 1, minWidth: 240 }} value={email}
|
|---|
| 38 | onChange={e => setEmail(e.target.value)} placeholder="client email" />
|
|---|
| 39 | <input type="date" value={from} onChange={e => setFrom(e.target.value)} />
|
|---|
| 40 | <input type="date" value={to} onChange={e => setTo(e.target.value)} />
|
|---|
| 41 | <button className="primary" onClick={loadClient}>Load</button>
|
|---|
| 42 | </div>
|
|---|
| 43 | </div>
|
|---|
| 44 |
|
|---|
| 45 | {intake.length > 0 && (
|
|---|
| 46 | <div className="card">
|
|---|
| 47 | <h3>Daily intake</h3>
|
|---|
| 48 | <table>
|
|---|
| 49 | <thead><tr><th>day</th><th>kcal</th><th>meals</th></tr></thead>
|
|---|
| 50 | <tbody>
|
|---|
| 51 | {intake.map(d => (
|
|---|
| 52 | <tr key={d.day}><td>{d.day}</td>
|
|---|
| 53 | <td className="kcal">{d.kcalConsumed}</td><td>{d.mealsLogged}</td></tr>
|
|---|
| 54 | ))}
|
|---|
| 55 | </tbody>
|
|---|
| 56 | </table>
|
|---|
| 57 | </div>
|
|---|
| 58 | )}
|
|---|
| 59 |
|
|---|
| 60 | {macros.length > 0 && (
|
|---|
| 61 | <div className="card">
|
|---|
| 62 | <h3>Macronutrients over the period</h3>
|
|---|
| 63 | <table>
|
|---|
| 64 | <tbody>
|
|---|
| 65 | {macros.map(m => (
|
|---|
| 66 | <tr key={m.nutrient}><td>{m.nutrient}</td><td>{m.total} {m.unit}</td></tr>
|
|---|
| 67 | ))}
|
|---|
| 68 | </tbody>
|
|---|
| 69 | </table>
|
|---|
| 70 | </div>
|
|---|
| 71 | )}
|
|---|
| 72 |
|
|---|
| 73 | {progress.length > 0 && (
|
|---|
| 74 | <div className="card">
|
|---|
| 75 | <h3>Biometric progress</h3>
|
|---|
| 76 | <table>
|
|---|
| 77 | <thead><tr><th>date</th><th>weight</th><th>change</th><th>BMI</th></tr></thead>
|
|---|
| 78 | <tbody>
|
|---|
| 79 | {progress.map(p => (
|
|---|
| 80 | <tr key={p.id}><td>{p.date}</td><td>{p.weight}</td>
|
|---|
| 81 | <td>{p.changeSincePrevious ?? '—'}</td><td>{p.bmi ?? '—'}</td></tr>
|
|---|
| 82 | ))}
|
|---|
| 83 | </tbody>
|
|---|
| 84 | </table>
|
|---|
| 85 | </div>
|
|---|
| 86 | )}
|
|---|
| 87 |
|
|---|
| 88 | <div className="card">
|
|---|
| 89 | <h3>Recipe analysis</h3>
|
|---|
| 90 | <div className="row" style={{ marginBottom: 8 }}>
|
|---|
| 91 | <input value={nutrient} onChange={e => setNutrient(e.target.value)}
|
|---|
| 92 | placeholder="nutrient, e.g. Protein" />
|
|---|
| 93 | <button className="primary" onClick={loadDensity}>Rank</button>
|
|---|
| 94 | </div>
|
|---|
| 95 | <table>
|
|---|
| 96 | <thead>
|
|---|
| 97 | <tr><th>recipe</th><th>kcal/portion</th><th>per portion</th><th>per 100 kcal</th></tr>
|
|---|
| 98 | </thead>
|
|---|
| 99 | <tbody>
|
|---|
| 100 | {density.map(d => (
|
|---|
| 101 | <tr key={d.recipe}>
|
|---|
| 102 | <td>{d.recipe}</td><td>{d.kcalPerServing}</td>
|
|---|
| 103 | <td>{d.amountPerServing}</td><td className="kcal">{d.amountPer100Kcal}</td>
|
|---|
| 104 | </tr>
|
|---|
| 105 | ))}
|
|---|
| 106 | </tbody>
|
|---|
| 107 | </table>
|
|---|
| 108 | </div>
|
|---|
| 109 | </div>
|
|---|
| 110 | )
|
|---|
| 111 | }
|
|---|