massive frontend refactoring (works good)
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import { state, saveState, genId } from '../state.js';
|
||||
import { renderMainScreen } from '../render/main-screen.js';
|
||||
import { showEditWorkoutDateDialog } from '../modals/edit-workout-date-modal.js';
|
||||
|
||||
export function startWorkout() {
|
||||
const w = {
|
||||
id: genId(),
|
||||
startTime: new Date().toISOString(),
|
||||
endTime: null,
|
||||
type: '',
|
||||
exercises: [],
|
||||
cardio: [],
|
||||
notes: '',
|
||||
synced: false,
|
||||
};
|
||||
state.workouts.unshift(w);
|
||||
state.expandedWorkoutId = w.id;
|
||||
saveState();
|
||||
renderMainScreen();
|
||||
}
|
||||
|
||||
export function finishWorkout(workoutId) {
|
||||
if (!confirm('Завершить тренировку?')) return;
|
||||
const w = getWorkout(workoutId);
|
||||
w.endTime = new Date().toISOString();
|
||||
saveState();
|
||||
renderMainScreen();
|
||||
}
|
||||
|
||||
export function deleteWorkout(workoutId) {
|
||||
if (!confirm('Удалить тренировку полностью?')) return;
|
||||
state.workouts = state.workouts.filter(w => w.id !== workoutId);
|
||||
saveState();
|
||||
renderMainScreen();
|
||||
}
|
||||
|
||||
export function toggleWorkout(workoutId) {
|
||||
state.expandedWorkoutId =
|
||||
state.expandedWorkoutId === workoutId ? null : workoutId;
|
||||
renderMainScreen();
|
||||
}
|
||||
|
||||
export function getWorkout(id) {
|
||||
return state.workouts.find(w => w.id === id);
|
||||
}
|
||||
|
||||
export function getActiveWorkout() {
|
||||
return state.workouts.find(w => !w.endTime);
|
||||
}
|
||||
|
||||
export function editWorkoutDate(workoutId) {
|
||||
const w = getWorkout(workoutId);
|
||||
if (!w) return;
|
||||
showEditWorkoutDateDialog(w, (newDates) => {
|
||||
if (!newDates) return;
|
||||
w.startTime = newDates.startTime;
|
||||
w.endTime = newDates.endTime;
|
||||
saveState();
|
||||
renderMainScreen();
|
||||
});
|
||||
}
|
||||
|
||||
window.WL = {
|
||||
startWorkout, finishWorkout, deleteWorkout,
|
||||
toggleWorkout, editWorkoutDate,
|
||||
};
|
||||
Reference in New Issue
Block a user