2024-01-13 02:00:15 +00:00
|
|
|
<template>
|
|
|
|
|
<div>
|
2024-05-02 12:07:55 +00:00
|
|
|
<ul class="meals-list" v-if="meals.length">
|
2024-01-13 02:00:15 +00:00
|
|
|
<li v-for="meal in meals" :key="meal.id">
|
2024-05-02 12:07:55 +00:00
|
|
|
<meal-card :meal="meal"/>
|
|
|
|
|
<button class="toggle-actions" @click="selectedMeal = ((meal == selectedMeal) ? null : meal)">
|
|
|
|
|
<img :src="meal == selectedMeal ? require('@/assets/chevron-down.svg') : require('@/assets/chevron-up.svg')" />
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
<ul class="actions" v-if="selectedMeal == meal">
|
|
|
|
|
<li><router-link class="nav-link" :to="`/meals/${selectedMeal.id}`" active-class="active">Edit Meal</router-link></li>
|
2024-05-27 11:56:58 +00:00
|
|
|
<li><a @click="markConsumed">Mark Consumed</a></li>
|
2024-05-02 12:07:55 +00:00
|
|
|
<li><a @click="deleteSelectedMeal" class="button">Remove</a></li>
|
|
|
|
|
</ul>
|
2024-01-13 02:00:15 +00:00
|
|
|
</li>
|
|
|
|
|
</ul>
|
2024-05-27 12:14:58 +00:00
|
|
|
<div v-if="!meals.length">
|
|
|
|
|
<em>No meals planned</em>
|
|
|
|
|
</div>
|
2024-05-04 02:39:30 +00:00
|
|
|
<action-item title="Plan Meal" :image="require('@/assets/plan-meal.svg')" @click="() => this.$router.push('/meals/add')" />
|
2024-01-13 02:00:15 +00:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
li {
|
|
|
|
|
list-style-type: none;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-04 01:52:31 +00:00
|
|
|
ul.meals-list {
|
|
|
|
|
padding: 0;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-02 12:07:55 +00:00
|
|
|
.toggle-actions {
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
background-color: #fff;
|
|
|
|
|
border: none;
|
|
|
|
|
border-bottom: solid 1px #ccc;
|
|
|
|
|
padding: 0 2em;
|
|
|
|
|
margin: 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.toggle-actions img {
|
|
|
|
|
width: 2em;
|
|
|
|
|
height: 2em;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.meals-list > li {
|
|
|
|
|
margin-bottom: 1em;
|
|
|
|
|
padding: 0;
|
|
|
|
|
border: 1px solid #ccc;
|
|
|
|
|
border-radius: 5px;
|
|
|
|
|
padding: 10px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ul.actions {
|
2024-01-13 02:00:15 +00:00
|
|
|
margin: 0;
|
|
|
|
|
padding: 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.actions li {
|
|
|
|
|
display: block;
|
|
|
|
|
border: 1px solid #ccc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.actions li:hover {
|
|
|
|
|
background-color: #ccc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.actions li a {
|
|
|
|
|
display: block;
|
|
|
|
|
text-decoration: none;
|
|
|
|
|
color: #000;
|
|
|
|
|
width: 100%;
|
2024-05-02 12:07:55 +00:00
|
|
|
cursor: pointer;
|
2024-05-27 12:11:57 +00:00
|
|
|
padding-top: 2ex;
|
|
|
|
|
padding-bottom: 2ex;
|
2024-01-13 02:00:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
<script>
|
2024-05-04 02:49:32 +00:00
|
|
|
import ActionItem from '@/components/ActionItem.vue'
|
|
|
|
|
import MealCard from '@/components/meals/MealCard.vue'
|
2025-10-18 01:30:30 +00:00
|
|
|
import { getUpcomingMeals, markMealConsumed, deleteMeal } from '@/api/meals'
|
2024-01-13 02:00:15 +00:00
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
name: 'MealPlanPage',
|
2024-05-04 02:39:30 +00:00
|
|
|
components: { MealCard, ActionItem },
|
2024-01-13 02:00:15 +00:00
|
|
|
data() {
|
2024-01-13 23:09:15 +00:00
|
|
|
const from = new Date();
|
2024-01-17 11:57:44 +00:00
|
|
|
from.setTime(0);
|
|
|
|
|
|
2024-01-17 11:31:45 +00:00
|
|
|
const to = new Date();
|
|
|
|
|
to.setDate(to.getDate() + 7);
|
2024-01-13 23:09:15 +00:00
|
|
|
|
2024-01-13 02:00:15 +00:00
|
|
|
return {
|
2024-01-13 23:09:15 +00:00
|
|
|
from, to,
|
2024-01-17 11:31:45 +00:00
|
|
|
meals: [],
|
2024-01-13 02:00:15 +00:00
|
|
|
selectedMeal: null
|
|
|
|
|
}
|
|
|
|
|
},
|
2024-01-17 09:17:22 +00:00
|
|
|
async beforeMount() {
|
2025-10-18 01:30:30 +00:00
|
|
|
const meals = await getUpcomingMeals(this.from, this.to)
|
|
|
|
|
this.meals = meals
|
2024-01-13 23:09:15 +00:00
|
|
|
},
|
2024-01-13 02:00:15 +00:00
|
|
|
methods: {
|
2024-01-17 11:57:44 +00:00
|
|
|
async deleteSelectedMeal() {
|
2025-10-18 01:30:30 +00:00
|
|
|
await deleteMeal(this.selectedMeal.id)
|
|
|
|
|
this.meals = this.meals.filter(m => m.id !== this.selectedMeal.id)
|
|
|
|
|
this.selectedMeal = null
|
2024-05-27 11:56:58 +00:00
|
|
|
},
|
|
|
|
|
async markConsumed() {
|
2025-10-18 01:30:30 +00:00
|
|
|
await markMealConsumed(this.selectedMeal.id)
|
|
|
|
|
this.meals = this.meals.filter(m => m.id !== this.selectedMeal.id)
|
2024-01-13 02:00:15 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|