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

103 lines
2.2 KiB
Vue
Raw Normal View History

2024-01-13 02:00:15 +00:00
<template>
2024-01-14 01:46:45 +00:00
<div class="container">
<div class="fields">
<date-picker @date-selected="selectDate" :date="meal.date" />
<recipe-search-box @select-recipe="selectRecipe" />
</div>
<h2>Foods</h2>
<ul v-if="meal.recipes && meal.recipes.length">
<li v-for="recipe in meal.recipes" :key="recipe.id" class="saved-recipe">
<p class="recipe-card">
<recipe-card :recipe="recipe" />
</p>
<button @click="removeRecipe(recipe)">Remove</button>
</li>
</ul>
<div v-else>
<p>Add some recipes</p>
</div>
2024-01-13 23:09:15 +00:00
</div>
2024-01-13 02:00:15 +00:00
</template>
<script>
2024-01-13 23:09:15 +00:00
import data from '@/data.js'
import RecipeSearchBox from './RecipeSearchBox.vue';
2024-01-14 01:46:45 +00:00
import RecipeCard from './RecipeCard.vue';
import DatePicker from './DatePicker.vue';
2024-01-13 23:09:15 +00:00
2024-01-13 02:00:15 +00:00
export default {
props: ['id'],
2024-01-14 01:46:45 +00:00
components: { RecipeSearchBox, DatePicker, RecipeCard },
2024-01-13 02:00:15 +00:00
data() {
return {
meal: {
date: new Date(),
2024-01-13 23:09:15 +00:00
recipes: [{ name: 'Sar Tay' }],
2024-01-13 02:00:15 +00:00
chefs: [{ name: 'Ryan' }],
consumers: [{ name: 'Ryan' }, { name: 'Jacob' }],
}
2024-01-13 23:09:15 +00:00
};
},
beforeMount() {
if (this.id) {
this.meal = data.getMeal(this.id);
2024-01-13 02:00:15 +00:00
}
},
2024-01-13 23:09:15 +00:00
methods: {
selectRecipe(recipe) {
2024-01-14 01:46:45 +00:00
this.meal.recipes.push(recipe);
},
selectDate(date) {
this.meal.date = date;
},
removeRecipe(recipe) {
this.meal.recipes = this.meal.recipes.filter(r => r.id !== recipe.id);
2024-01-13 23:09:15 +00:00
}
}
2024-01-13 02:00:15 +00:00
}
</script>
2024-01-14 01:46:45 +00:00
<style scoped>
.container {
margin: 1em auto;
max-width: 1200px;
}
.fields {
width: 80%;
margin: 0 auto;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
.saved-recipe {
display: flex;
justify-content: space-between;
align-items: center;
margin: 1vh 1em;
}
.saved-recipe button {
background: #fff;
border: 1px solid #ccc;
border-radius: 4px;
padding: 0.5em;
cursor: pointer;
margin: 1em
}
.saved-recipe button:hover {
background: #eee;
}
.saved-recipe .recipe-card {
flex: 1;
margin: 0 1em;
}
</style>