massive frontend refactoring (works good)
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import { state, saveState, genId } from '../state.js';
|
||||
import { renderMainScreen } from '../render/main-screen.js';
|
||||
import { showBodyMetricsDialog } from '../modals/metrics-modal.js';
|
||||
|
||||
export function showBodyMetrics() {
|
||||
showBodyMetricsDialog(state.bodyMetrics, (newMetric) => {
|
||||
if (!newMetric) return;
|
||||
newMetric.id = genId();
|
||||
state.bodyMetrics.unshift(newMetric);
|
||||
state.bodyMetrics.sort((a, b) => new Date(b.date) - new Date(a.date));
|
||||
saveState();
|
||||
renderMainScreen();
|
||||
alert('Замеры сохранены!');
|
||||
});
|
||||
}
|
||||
|
||||
export function editBodyMetric(metricId) {
|
||||
const metric = state.bodyMetrics.find(m => m.id === metricId);
|
||||
if (!metric) return;
|
||||
showBodyMetricsDialog(state.bodyMetrics, (updatedData) => {
|
||||
if (!updatedData) return;
|
||||
Object.assign(metric, updatedData);
|
||||
state.bodyMetrics.sort((a, b) => new Date(b.date) - new Date(a.date));
|
||||
saveState();
|
||||
// Если сейчас на экране настроек — перерисуем список
|
||||
const list = document.getElementById('body-metrics-list');
|
||||
if (list && typeof window.SettingsLogic !== 'undefined') {
|
||||
window.SettingsLogic._renderBodyMetricsList();
|
||||
} else {
|
||||
renderMainScreen();
|
||||
}
|
||||
}, metric);
|
||||
}
|
||||
|
||||
export function deleteMetric(id) {
|
||||
if (!confirm('Удалить замер?')) return;
|
||||
state.bodyMetrics = state.bodyMetrics.filter(m => m.id !== id);
|
||||
saveState();
|
||||
const list = document.getElementById('body-metrics-list');
|
||||
if (list && typeof window.SettingsLogic !== 'undefined') {
|
||||
window.SettingsLogic._renderBodyMetricsList();
|
||||
} else {
|
||||
renderMainScreen();
|
||||
}
|
||||
}
|
||||
|
||||
window.ML = { showBodyMetrics, editBodyMetric, deleteMetric };
|
||||
Reference in New Issue
Block a user