massive frontend refactoring (works good)

This commit is contained in:
2026-09-30 01:54:17 +03:00
parent 9203884f53
commit 93ca76c6e1
36 changed files with 1608 additions and 2069 deletions
+66
View File
@@ -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,
};