massive frontend refactoring (works good)
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { state, saveState, genId } from '../state.js';
|
||||
import { renderMainScreen } from '../render/main-screen.js';
|
||||
import { showCardioDialog } from '../modals/cardio-modal.js';
|
||||
|
||||
export function addCardio(workoutId) {
|
||||
showCardioDialog(null, (cardio) => {
|
||||
if (!cardio) return;
|
||||
const w = state.workouts.find(x => x.id === workoutId);
|
||||
cardio.id = genId();
|
||||
w.cardio.push(cardio);
|
||||
saveState();
|
||||
renderMainScreen();
|
||||
});
|
||||
}
|
||||
|
||||
export function editCardio(workoutId, cardioId) {
|
||||
const w = state.workouts.find(x => x.id === workoutId);
|
||||
const cardio = w.cardio.find(c => c.id === cardioId);
|
||||
showCardioDialog(cardio, (newData) => {
|
||||
if (!newData) return;
|
||||
Object.assign(cardio, newData);
|
||||
saveState();
|
||||
renderMainScreen();
|
||||
});
|
||||
}
|
||||
|
||||
export function deleteCardio(workoutId, cardioId) {
|
||||
if (!confirm('Удалить кардио?')) return;
|
||||
const w = state.workouts.find(x => x.id === workoutId);
|
||||
w.cardio = w.cardio.filter(c => c.id !== cardioId);
|
||||
saveState();
|
||||
renderMainScreen();
|
||||
}
|
||||
|
||||
window.CL = { addCardio, editCardio, deleteCardio };
|
||||
Reference in New Issue
Block a user