diff --git a/index.html b/index.html index 47c9c53..5dafd76 100644 --- a/index.html +++ b/index.html @@ -207,6 +207,9 @@ +
+ +
diff --git a/src/.env.example b/src/.env.example new file mode 100644 index 0000000..0493e4a --- /dev/null +++ b/src/.env.example @@ -0,0 +1,4 @@ +VITE_APPWRITE_ENDPOINT=here +VITE_APPWRITE_DBID=here +VITE_APPWRITE_FOODENTRIESID=here +VITE_APPWRITE_USERSETTINGSID=here \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 9a1efc6..a677558 100644 --- a/src/index.ts +++ b/src/index.ts @@ -545,7 +545,7 @@ const addDeleteEvents = () => { const row = target.closest('tr'); const entryId = row?.querySelector('.hidden-column')?.textContent; if (entryId && row) { - handleDeleteFood(entryId, row); + handleDeleteFood(entryId); } }); }); @@ -656,6 +656,7 @@ async function loadFoodEntries(date: Date) { // Clear current table getDivById('foodTableBody').innerHTML = ''; + getDivById('foodCardsContainer').innerHTML = ''; // Add each entry to table entries.forEach(entry => { @@ -676,6 +677,16 @@ async function loadFoodEntries(date: Date) { addFoodToTable(foodData, entry.$id); }); + if (entries.length === 0) { + getDivById('foodCardsContainer').innerHTML = ` +
+
🍽️
+
No food items logged yet.
+
Add your first item to get started!
+
+ `; + } + // Setup Delete events addDeleteEvents(); @@ -751,7 +762,7 @@ async function loadFoodEntries(date: Date) { } // Handle food deletion -async function handleDeleteFood(documentId: string, row: HTMLTableRowElement) { +async function handleDeleteFood(documentId: string) { if (!documentId) return; const willDelete = await swal({ @@ -804,6 +815,53 @@ function addFoodToTable(foodData: FoodStorage, documentId: string) { // Setup Delete events addDeleteEvents(); + + // New Food card + const container = document.getElementById('foodCardsContainer'); + const card = document.createElement('div'); + card.className = 'food-card'; + card.setAttribute('data-id', documentId); + + card.innerHTML = ` +
+
+
+
${foodData.name}
+
${foodData.time || new Date().toLocaleTimeString()} • ${foodData.grams}g
+
+
${foodData.calories} cal
+
+
+
+
+
+
+
+
Protein
+
${foodData.protein}g
+
+
+
Fat
+
${foodData.fat}g
+
+
+
Carbs
+
${foodData.carbs}g
+
+
+
Fiber
+
${foodData.fiber}g
+
+
+
+ + +
+
+
+ `; + + container?.appendChild(card); } // Update total calories @@ -970,4 +1028,20 @@ function createDayElement(day: number, isOtherMonth: boolean, year: number, mont return dayElement; } +function toggleCard(id) { + const card = document.querySelector(`[data-id="${id}"]`); + card.classList.toggle('expanded'); +} + +function deleteFood(id) { + handleDeleteFood(id); +} + +function editFood(id) { + alert(`Edit functionality for food item ${id} would be implemented here`); +} + (window as any).selectFood = selectFood; +(window as any).toggleCard = toggleCard; +(window as any).editFood = editFood; +(window as any).deleteFood = deleteFood; diff --git a/style.css b/style.css index 0c69910..19af16c 100644 --- a/style.css +++ b/style.css @@ -167,11 +167,200 @@ h1 { background-color: #f8f9ff; } +.food-log-section { + max-width: 800px; + margin: 0 auto; +} -.food-name { +.section-title { + font-size: 24px; font-weight: 600; color: #333; - margin-bottom: 2px; + margin-bottom: 20px; + text-align: center; +} + +.food-cards-container { + display: flex; + flex-direction: column; + gap: 12px; +} + +.food-card { + background: white; + border-radius: 12px; + box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); + overflow: hidden; + transition: all 0.3s ease; +} + +.food-card:hover { + box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); +} + +.card-header { + padding: 16px; + cursor: pointer; + display: flex; + justify-content: between; + align-items: center; + background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); + color: white; + position: relative; +} + +.card-header:hover { + background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%); +} + +.card-main-info { + flex: 1; + display: flex; + justify-content: space-between; + align-items: center; + gap: 16px; +} + +.food-name-time { + flex: 1; +} + +.food-name { + font-size: 16px; + font-weight: 600; + color: #333; + margin-bottom: 4px; +} + +.food-time { + font-size: 13px; + opacity: 0.9; +} + +.calories-display { + font-size: 18px; + font-weight: 700; + color: #fff; + text-align: right; +} + +.expand-icon { + margin-left: 12px; + font-size: 14px; + transition: transform 0.3s ease; + opacity: 0.8; +} + +.food-card.expanded .expand-icon { + transform: rotate(180deg); +} + +.card-details { + max-height: 0; + overflow: hidden; + transition: max-height 0.3s ease; + background: #fafafa; +} + +.food-card.expanded .card-details { + max-height: 300px; +} + +.details-content { + padding: 20px; +} + +.nutrition-grid { + display: grid; + grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); + gap: 16px; + margin-bottom: 20px; +} + +.nutrition-item { + text-align: center; + padding: 12px; + background: white; + border-radius: 8px; + box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); +} + +.nutrition-label { + font-size: 12px; + color: #666; + text-transform: uppercase; + letter-spacing: 0.5px; + margin-bottom: 4px; +} + +.nutrition-value { + font-size: 16px; + font-weight: 600; + color: #333; +} + +.card-actions { + display: flex; + justify-content: flex-end; + gap: 8px; + padding-top: 16px; + border-top: 1px solid #e0e0e0; +} + +.btn { + padding: 8px 16px; + border: none; + border-radius: 6px; + font-size: 14px; + cursor: pointer; + transition: all 0.2s ease; +} + +.btn-delete { + background: #ff4757; + color: white; +} + +.btn-delete:hover { + background: #ff3838; +} + +.btn-edit { + background: #5352ed; + color: white; +} + +.btn-edit:hover { + background: #4834d4; +} + +.empty-state { + text-align: center; + padding: 60px 20px; + color: #666; +} + +.empty-state-icon { + font-size: 48px; + margin-bottom: 16px; + opacity: 0.5; +} + +.add-food-btn { + background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); + color: white; + border: none; + padding: 12px 24px; + border-radius: 8px; + font-size: 16px; + cursor: pointer; + margin-bottom: 20px; + transition: all 0.2s ease; +} + +.add-food-btn:hover { + background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%); + transform: translateY(-1px); } .food-details { @@ -522,4 +711,25 @@ label { h1 { font-size: 2rem; } + + .card-header { + padding: 14px; + } + + .food-name { + font-size: 15px; + } + + .calories-display { + font-size: 16px; + } + + .nutrition-grid { + grid-template-columns: repeat(2, 1fr); + gap: 12px; + } + + .details-content { + padding: 16px; + } }