Separated weight tracking
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
|
||||
import React, { useMemo } from 'react';
|
||||
import { WorkoutSession, ExerciseType, Language } from '../types';
|
||||
import React, { useMemo, useState, useEffect } from 'react';
|
||||
import { WorkoutSession, ExerciseType, Language, BodyWeightRecord } from '../types';
|
||||
import { getWeightHistory } from '../services/weight';
|
||||
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, BarChart, Bar } from 'recharts';
|
||||
import { t } from '../services/i18n';
|
||||
|
||||
@@ -10,6 +11,15 @@ interface StatsProps {
|
||||
}
|
||||
|
||||
const Stats: React.FC<StatsProps> = ({ sessions, lang }) => {
|
||||
const [weightRecords, setWeightRecords] = useState<BodyWeightRecord[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchWeights = async () => {
|
||||
const records = await getWeightHistory();
|
||||
setWeightRecords(records);
|
||||
};
|
||||
fetchWeights();
|
||||
}, []);
|
||||
|
||||
const volumeData = useMemo(() => {
|
||||
const data = [...sessions].reverse().map(session => {
|
||||
@@ -46,13 +56,11 @@ const Stats: React.FC<StatsProps> = ({ sessions, lang }) => {
|
||||
}, [sessions, lang]);
|
||||
|
||||
const weightData = useMemo(() => {
|
||||
return [...sessions].reverse()
|
||||
.filter(s => s.userBodyWeight)
|
||||
.map(session => ({
|
||||
date: new Date(session.startTime).toLocaleDateString(lang === 'ru' ? 'ru-RU' : 'en-US', { day: 'numeric', month: 'short' }),
|
||||
weight: session.userBodyWeight
|
||||
}));
|
||||
}, [sessions, lang]);
|
||||
return [...weightRecords].reverse().map(record => ({
|
||||
date: new Date(record.date).toLocaleDateString(lang === 'ru' ? 'ru-RU' : 'en-US', { day: 'numeric', month: 'short' }),
|
||||
weight: record.weight
|
||||
}));
|
||||
}, [weightRecords, lang]);
|
||||
|
||||
if (sessions.length < 2) {
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user