From 2cb2c10482662aa65244d124f388442a386ee867 Mon Sep 17 00:00:00 2001 From: Greg Date: Sat, 31 May 2025 08:29:35 +0200 Subject: [PATCH] feat: implement UI module with tab navigation, form handling, and data table rendering --- js/ui.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/js/ui.js b/js/ui.js index 28fc687..19e1438 100644 --- a/js/ui.js +++ b/js/ui.js @@ -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)) {