integrated front and back
This commit is contained in:
@@ -5,15 +5,31 @@ import { getExerciseHistory } from './exercise.js';
|
||||
|
||||
export function addSet(workoutId, exerciseId) {
|
||||
const w = state.workouts.find(x => x.id === workoutId);
|
||||
if (!w) return;
|
||||
|
||||
const ex = w.exercises.find(e => e.id === exerciseId);
|
||||
if (!ex) return;
|
||||
|
||||
if (!Array.isArray(ex.sets)) {
|
||||
ex.sets = [];
|
||||
}
|
||||
|
||||
const lastSet = ex.sets[ex.sets.length - 1];
|
||||
const history = getExerciseHistory(ex.name);
|
||||
|
||||
const history = getExerciseHistory(
|
||||
ex.name,
|
||||
w.client_id ?? null,
|
||||
w.id
|
||||
);
|
||||
|
||||
showSetDialog(lastSet, history, (setData) => {
|
||||
if (!setData) return;
|
||||
|
||||
setData.id = genId();
|
||||
setData.timestamp = new Date().toISOString();
|
||||
|
||||
ex.sets.push(setData);
|
||||
|
||||
saveState();
|
||||
renderMainScreen();
|
||||
});
|
||||
@@ -21,13 +37,29 @@ export function addSet(workoutId, exerciseId) {
|
||||
|
||||
export function editSet(workoutId, exerciseId, setId) {
|
||||
const w = state.workouts.find(x => x.id === workoutId);
|
||||
if (!w) return;
|
||||
|
||||
const ex = w.exercises.find(e => e.id === exerciseId);
|
||||
if (!ex) return;
|
||||
|
||||
if (!Array.isArray(ex.sets)) {
|
||||
ex.sets = [];
|
||||
}
|
||||
|
||||
const set = ex.sets.find(s => s.id === setId);
|
||||
const history = getExerciseHistory(ex.name);
|
||||
if (!set) return;
|
||||
|
||||
const history = getExerciseHistory(
|
||||
ex.name,
|
||||
w.client_id ?? null,
|
||||
w.id
|
||||
);
|
||||
|
||||
showSetDialog(set, history, (setData) => {
|
||||
if (!setData) return;
|
||||
|
||||
Object.assign(set, setData);
|
||||
|
||||
saveState();
|
||||
renderMainScreen();
|
||||
});
|
||||
@@ -35,11 +67,25 @@ export function editSet(workoutId, exerciseId, setId) {
|
||||
|
||||
export function deleteSet(workoutId, exerciseId, setId) {
|
||||
if (!confirm('Удалить подход?')) return;
|
||||
|
||||
const w = state.workouts.find(x => x.id === workoutId);
|
||||
if (!w) return;
|
||||
|
||||
const ex = w.exercises.find(e => e.id === exerciseId);
|
||||
if (!ex) return;
|
||||
|
||||
if (!Array.isArray(ex.sets)) {
|
||||
ex.sets = [];
|
||||
}
|
||||
|
||||
ex.sets = ex.sets.filter(s => s.id !== setId);
|
||||
|
||||
saveState();
|
||||
renderMainScreen();
|
||||
}
|
||||
|
||||
window.SL = { addSet, editSet, deleteSet };
|
||||
window.SL = {
|
||||
addSet,
|
||||
editSet,
|
||||
deleteSet,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user