Separated weight tracking

This commit is contained in:
AG
2025-11-29 12:13:12 +02:00
parent 78930f6b80
commit d86abd6b1b
11 changed files with 300 additions and 22 deletions

View File

@@ -75,6 +75,7 @@ const translations = {
create_btn: 'Create',
completed_session_sets: 'Completed in this session',
add_weight: 'Add. Weight',
no_exercises_found: 'No exercises found',
// Types
type_strength: 'Free Weights & Machines',
@@ -225,6 +226,7 @@ const translations = {
create_btn: 'Создать',
completed_session_sets: 'Выполнено в этой тренировке',
add_weight: 'Доп. вес',
no_exercises_found: 'Упражнения не найдены',
// Types
type_strength: 'Свободные веса и тренажеры',

53
services/weight.ts Normal file
View File

@@ -0,0 +1,53 @@
import { BodyWeightRecord } from '../types';
const API_URL = '/api';
export const getWeightHistory = async (): Promise<BodyWeightRecord[]> => {
const token = localStorage.getItem('token');
if (!token) return [];
try {
const response = await fetch(`${API_URL}/weight`, {
headers: {
'Authorization': `Bearer ${token}`
}
});
if (!response.ok) {
throw new Error('Failed to fetch weight history');
}
return await response.json();
} catch (error) {
console.error('Error fetching weight history:', error);
return [];
}
};
export const logWeight = async (weight: number, dateStr?: string): Promise<BodyWeightRecord | null> => {
const token = localStorage.getItem('token');
if (!token) return null;
try {
// Default to today if no date provided
const date = dateStr || new Date().toISOString().split('T')[0];
const response = await fetch(`${API_URL}/weight`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
body: JSON.stringify({ weight, dateStr: date })
});
if (!response.ok) {
throw new Error('Failed to log weight');
}
return await response.json();
} catch (error) {
console.error('Error logging weight:', error);
return null;
}
};