feat: improve food list
This commit is contained in:
@@ -207,6 +207,9 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="food-cards-container" id="foodCardsContainer">
|
||||||
|
<!-- Food cards will be added here -->
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="calendar-section">
|
<div class="calendar-section">
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
VITE_APPWRITE_ENDPOINT=here
|
||||||
|
VITE_APPWRITE_DBID=here
|
||||||
|
VITE_APPWRITE_FOODENTRIESID=here
|
||||||
|
VITE_APPWRITE_USERSETTINGSID=here
|
||||||
+76
-2
@@ -545,7 +545,7 @@ const addDeleteEvents = () => {
|
|||||||
const row = target.closest('tr');
|
const row = target.closest('tr');
|
||||||
const entryId = row?.querySelector('.hidden-column')?.textContent;
|
const entryId = row?.querySelector('.hidden-column')?.textContent;
|
||||||
if (entryId && row) {
|
if (entryId && row) {
|
||||||
handleDeleteFood(entryId, row);
|
handleDeleteFood(entryId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -656,6 +656,7 @@ async function loadFoodEntries(date: Date) {
|
|||||||
|
|
||||||
// Clear current table
|
// Clear current table
|
||||||
getDivById('foodTableBody').innerHTML = '';
|
getDivById('foodTableBody').innerHTML = '';
|
||||||
|
getDivById('foodCardsContainer').innerHTML = '';
|
||||||
|
|
||||||
// Add each entry to table
|
// Add each entry to table
|
||||||
entries.forEach(entry => {
|
entries.forEach(entry => {
|
||||||
@@ -676,6 +677,16 @@ async function loadFoodEntries(date: Date) {
|
|||||||
addFoodToTable(foodData, entry.$id);
|
addFoodToTable(foodData, entry.$id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (entries.length === 0) {
|
||||||
|
getDivById('foodCardsContainer').innerHTML = `
|
||||||
|
<div class="empty-state">
|
||||||
|
<div class="empty-state-icon">🍽️</div>
|
||||||
|
<div>No food items logged yet.</div>
|
||||||
|
<div style="margin-top: 8px; font-size: 14px; opacity: 0.7;">Add your first item to get started!</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
// Setup Delete events
|
// Setup Delete events
|
||||||
addDeleteEvents();
|
addDeleteEvents();
|
||||||
|
|
||||||
@@ -751,7 +762,7 @@ async function loadFoodEntries(date: Date) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle food deletion
|
// Handle food deletion
|
||||||
async function handleDeleteFood(documentId: string, row: HTMLTableRowElement) {
|
async function handleDeleteFood(documentId: string) {
|
||||||
if (!documentId) return;
|
if (!documentId) return;
|
||||||
|
|
||||||
const willDelete = await swal({
|
const willDelete = await swal({
|
||||||
@@ -804,6 +815,53 @@ function addFoodToTable(foodData: FoodStorage, documentId: string) {
|
|||||||
|
|
||||||
// Setup Delete events
|
// Setup Delete events
|
||||||
addDeleteEvents();
|
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 = `
|
||||||
|
<div class="card-header" onclick="toggleCard(${documentId})">
|
||||||
|
<div class="card-main-info">
|
||||||
|
<div class="food-name-time">
|
||||||
|
<div class="food-name">${foodData.name}</div>
|
||||||
|
<div class="food-time">${foodData.time || new Date().toLocaleTimeString()} • ${foodData.grams}g</div>
|
||||||
|
</div>
|
||||||
|
<div class="calories-display">${foodData.calories} cal</div>
|
||||||
|
</div>
|
||||||
|
<div class="expand-icon">▼</div>
|
||||||
|
</div>
|
||||||
|
<div class="card-details">
|
||||||
|
<div class="details-content">
|
||||||
|
<div class="nutrition-grid">
|
||||||
|
<div class="nutrition-item">
|
||||||
|
<div class="nutrition-label">Protein</div>
|
||||||
|
<div class="nutrition-value">${foodData.protein}g</div>
|
||||||
|
</div>
|
||||||
|
<div class="nutrition-item">
|
||||||
|
<div class="nutrition-label">Fat</div>
|
||||||
|
<div class="nutrition-value">${foodData.fat}g</div>
|
||||||
|
</div>
|
||||||
|
<div class="nutrition-item">
|
||||||
|
<div class="nutrition-label">Carbs</div>
|
||||||
|
<div class="nutrition-value">${foodData.carbs}g</div>
|
||||||
|
</div>
|
||||||
|
<div class="nutrition-item">
|
||||||
|
<div class="nutrition-label">Fiber</div>
|
||||||
|
<div class="nutrition-value">${foodData.fiber}g</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card-actions">
|
||||||
|
<button class="btn btn-edit" onclick="editFood(${documentId})">Edit</button>
|
||||||
|
<button class="btn btn-delete" onclick="deleteFood(${documentId})">Delete</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
container?.appendChild(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update total calories
|
// Update total calories
|
||||||
@@ -970,4 +1028,20 @@ function createDayElement(day: number, isOtherMonth: boolean, year: number, mont
|
|||||||
return dayElement;
|
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).selectFood = selectFood;
|
||||||
|
(window as any).toggleCard = toggleCard;
|
||||||
|
(window as any).editFood = editFood;
|
||||||
|
(window as any).deleteFood = deleteFood;
|
||||||
|
|||||||
@@ -167,11 +167,200 @@ h1 {
|
|||||||
background-color: #f8f9ff;
|
background-color: #f8f9ff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.food-log-section {
|
||||||
|
max-width: 800px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
.food-name {
|
.section-title {
|
||||||
|
font-size: 24px;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
color: #333;
|
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 {
|
.food-details {
|
||||||
@@ -522,4 +711,25 @@ label {
|
|||||||
h1 {
|
h1 {
|
||||||
font-size: 2rem;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user