front-back integrated
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user