munch-ease-frontend/src/components/MealPlanPage.vue

108 lines
2.4 KiB
Vue
Raw Normal View History

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>
<li><a @click="deleteSelectedMeal" class="button">Remove</a></li>
</ul>
2024-01-13 02:00:15 +00:00
</li>
</ul>
<ul v-if="!meals.length">
<li>No meals planned</li>
</ul>
</div>
</template>
<style scoped>
li {
list-style-type: none;
}
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;
padding: 2ex;
}
.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-01-13 02:00:15 +00:00
}
</style>
<script>
import MealCard from './MealCard.vue'
2024-01-13 23:09:15 +00:00
import data from '@/data.js'
2024-01-13 02:00:15 +00:00
export default {
name: 'MealPlanPage',
components: {
MealCard
},
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() {
const meals = await data.getMeals(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() {
await data.deleteMeal(this.selectedMeal.id);
this.meals = this.meals.filter(m => m.id !== this.selectedMeal.id);
2024-01-13 02:00:15 +00:00
this.selectedMeal = null;
}
}
}
</script>