feat: implement UI module with tab navigation, form handling, and data table rendering
This commit is contained in:
parent
fe48ff340d
commit
2cb2c10482
10
js/ui.js
10
js/ui.js
@ -26,8 +26,8 @@ const UI = (() => {
|
|||||||
// Initialize the UI
|
// Initialize the UI
|
||||||
const init = () => {
|
const init = () => {
|
||||||
// Set today's date as default for forms
|
// Set today's date as default for forms
|
||||||
document.getElementById('weight-date').value = Utils.getTodayDate();
|
document.getElementById('weight-date').value = Utils.toUIDate(Utils.getTodayDate());
|
||||||
document.getElementById('meal-date').value = Utils.getTodayDate();
|
document.getElementById('meal-date').value = Utils.toUIDate(Utils.getTodayDate());
|
||||||
|
|
||||||
// Initialize tab navigation
|
// Initialize tab navigation
|
||||||
initTabs();
|
initTabs();
|
||||||
@ -85,7 +85,7 @@ const UI = (() => {
|
|||||||
* @param {string} dateString - The date (YYYY-MM-DD) to load data for.
|
* @param {string} dateString - The date (YYYY-MM-DD) to load data for.
|
||||||
*/
|
*/
|
||||||
const populateMealFormForDate = (dateStringFromInput) => {
|
const populateMealFormForDate = (dateStringFromInput) => {
|
||||||
const isoDateString = Utils.uiDateToISO(dateStringFromInput);
|
const isoDateString = Utils.toISODate(dateStringFromInput);
|
||||||
const mealData = DataManager.getMealByDate(isoDateString);
|
const mealData = DataManager.getMealByDate(isoDateString);
|
||||||
document.getElementById('breakfast').value = mealData?.breakfast || '';
|
document.getElementById('breakfast').value = mealData?.breakfast || '';
|
||||||
document.getElementById('lunch').value = mealData?.lunch || '';
|
document.getElementById('lunch').value = mealData?.lunch || '';
|
||||||
@ -93,6 +93,7 @@ const UI = (() => {
|
|||||||
document.getElementById('other-meals').value = mealData?.otherMeals || '';
|
document.getElementById('other-meals').value = mealData?.otherMeals || '';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const initForms = () => {
|
const initForms = () => {
|
||||||
// Weight form submission
|
// Weight form submission
|
||||||
forms.weight.addEventListener('submit', (e) => {
|
forms.weight.addEventListener('submit', (e) => {
|
||||||
@ -141,13 +142,14 @@ const UI = (() => {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
const mealEntry = {
|
const mealEntry = {
|
||||||
date: Utils.uiDateToISO(document.getElementById('meal-date').value),
|
date: Utils.toISODate(document.getElementById('meal-date').value),
|
||||||
breakfast: document.getElementById('breakfast').value,
|
breakfast: document.getElementById('breakfast').value,
|
||||||
lunch: document.getElementById('lunch').value,
|
lunch: document.getElementById('lunch').value,
|
||||||
dinner: document.getElementById('dinner').value,
|
dinner: document.getElementById('dinner').value,
|
||||||
otherMeals: document.getElementById('other-meals').value
|
otherMeals: document.getElementById('other-meals').value
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Add/update entry
|
// Add/update entry
|
||||||
if (DataManager.addMeal(mealEntry)) {
|
if (DataManager.addMeal(mealEntry)) {
|
||||||
Utils.showNotification('Meal entries saved successfully', 'success');
|
Utils.showNotification('Meal entries saved successfully', 'success');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user