feat: implement UI module with tab navigation, form handling, and data table rendering

This commit is contained in:
Greg 2025-05-31 08:29:35 +02:00
parent fe48ff340d
commit 2cb2c10482

View File

@ -26,8 +26,8 @@ const UI = (() => {
// Initialize the UI
const init = () => {
// Set today's date as default for forms
document.getElementById('weight-date').value = Utils.getTodayDate();
document.getElementById('meal-date').value = Utils.getTodayDate();
document.getElementById('weight-date').value = Utils.toUIDate(Utils.getTodayDate());
document.getElementById('meal-date').value = Utils.toUIDate(Utils.getTodayDate());
// Initialize tab navigation
initTabs();
@ -85,7 +85,7 @@ const UI = (() => {
* @param {string} dateString - The date (YYYY-MM-DD) to load data for.
*/
const populateMealFormForDate = (dateStringFromInput) => {
const isoDateString = Utils.uiDateToISO(dateStringFromInput);
const isoDateString = Utils.toISODate(dateStringFromInput);
const mealData = DataManager.getMealByDate(isoDateString);
document.getElementById('breakfast').value = mealData?.breakfast || '';
document.getElementById('lunch').value = mealData?.lunch || '';
@ -93,6 +93,7 @@ const UI = (() => {
document.getElementById('other-meals').value = mealData?.otherMeals || '';
};
const initForms = () => {
// Weight form submission
forms.weight.addEventListener('submit', (e) => {
@ -141,12 +142,13 @@ const UI = (() => {
e.preventDefault();
const mealEntry = {
date: Utils.uiDateToISO(document.getElementById('meal-date').value),
date: Utils.toISODate(document.getElementById('meal-date').value),
breakfast: document.getElementById('breakfast').value,
lunch: document.getElementById('lunch').value,
dinner: document.getElementById('dinner').value,
otherMeals: document.getElementById('other-meals').value
};
// Add/update entry
if (DataManager.addMeal(mealEntry)) {