front-back integrated

This commit is contained in:
2026-09-30 02:25:03 +03:00
parent 93ca76c6e1
commit 1f81632083
13 changed files with 298 additions and 27 deletions
+21 -1
View File
@@ -1,6 +1,7 @@
import { state, saveState, genId } from '../state.js';
import { renderMainScreen } from '../render/main-screen.js';
import { showExerciseDialog } from '../modals/exercise-modal.js';
import { fetchExerciseHistory } from '../api.js';
export function addExercise(workoutId) {
const w = state.workouts.find(x => x.id === workoutId);
@@ -45,7 +46,26 @@ export function deleteExercise(workoutId, exerciseId) {
renderMainScreen();
}
export function getExerciseHistory(exerciseName) {
export async function getExerciseHistory(exerciseName) {
// Пытаемся получить с бэкенда
try {
const history = await fetchExerciseHistory(exerciseName, state.currentClientId);
if (history && history.length > 0) {
return history.map(h => ({
date: h.date,
sets: [{ // Адаптируем формат бэкенда под формат фронта
isDropset: h.is_dropset,
weight: h.weight,
reps: h.reps,
subSets: h.is_dropset ? [{weight: h.weight, reps: h.reps}] : undefined // Упрощение для отображения
}]
}));
}
} catch (e) {
console.warn('Не удалось загрузить историю с бэкенда, используем локальную', e);
}
// Fallback на локальные данные
const normalizedName = exerciseName.trim().toLowerCase();
const history = [];
for (const w of state.workouts) {