massive frontend refactoring (works good)
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import { state, saveState, genId } from '../state.js';
|
||||
import { renderMainScreen } from '../render/main-screen.js';
|
||||
import { showSetDialog } from '../modals/set-modal.js';
|
||||
import { getExerciseHistory } from './exercise.js';
|
||||
|
||||
export function addSet(workoutId, exerciseId) {
|
||||
const w = state.workouts.find(x => x.id === workoutId);
|
||||
const ex = w.exercises.find(e => e.id === exerciseId);
|
||||
const lastSet = ex.sets[ex.sets.length - 1];
|
||||
const history = getExerciseHistory(ex.name);
|
||||
|
||||
showSetDialog(lastSet, history, (setData) => {
|
||||
if (!setData) return;
|
||||
setData.id = genId();
|
||||
setData.timestamp = new Date().toISOString();
|
||||
ex.sets.push(setData);
|
||||
saveState();
|
||||
renderMainScreen();
|
||||
});
|
||||
}
|
||||
|
||||
export function editSet(workoutId, exerciseId, setId) {
|
||||
const w = state.workouts.find(x => x.id === workoutId);
|
||||
const ex = w.exercises.find(e => e.id === exerciseId);
|
||||
const set = ex.sets.find(s => s.id === setId);
|
||||
const history = getExerciseHistory(ex.name);
|
||||
|
||||
showSetDialog(set, history, (setData) => {
|
||||
if (!setData) return;
|
||||
Object.assign(set, setData);
|
||||
saveState();
|
||||
renderMainScreen();
|
||||
});
|
||||
}
|
||||
|
||||
export function deleteSet(workoutId, exerciseId, setId) {
|
||||
if (!confirm('Удалить подход?')) return;
|
||||
const w = state.workouts.find(x => x.id === workoutId);
|
||||
const ex = w.exercises.find(e => e.id === exerciseId);
|
||||
ex.sets = ex.sets.filter(s => s.id !== setId);
|
||||
saveState();
|
||||
renderMainScreen();
|
||||
}
|
||||
|
||||
window.SL = { addSet, editSet, deleteSet };
|
||||
Reference in New Issue
Block a user