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

137 lines
3.5 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" />
</div>
2024-01-14 06:20:21 +00:00
<div class="recipes">
<h2>Recipes</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 using the search box</p>
</div>
<div class="fields">
<recipe-search-box @select-recipe="selectRecipe" />
</div>
</div>
<div class="ingredients">
2024-01-17 06:03:11 +00:00
<h2>Additional Ingredients</h2>
2024-01-14 06:20:21 +00:00
<ul v-if="meal.ingredients && meal.ingredients.length">
<li v-for="ingredient in meal.ingredients" :key="ingredient" class="saved-ingredient">
<p>
2024-01-17 06:03:11 +00:00
<compact-parsed-ingredient :ingredient="ingredient" />
2024-01-14 06:20:21 +00:00
</p>
<button @click="deleteIngredient(ingredient)">Delete</button>
</li>
</ul>
<div v-else>
<p>Add some ingredients using the search box</p>
</div>
<ingredient-add-box @add-ingredient="addIngredient" />
2024-01-14 01:46:45 +00:00
</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-14 02:12:19 +00:00
import IngredientAddBox from './IngredientAddBox.vue';
2024-01-17 06:03:11 +00:00
import CompactParsedIngredient from './CompactParsedIngredient.vue';
2024-01-13 23:09:15 +00:00
2024-01-13 02:00:15 +00:00
export default {
props: ['id'],
2024-01-17 06:03:11 +00:00
components: { RecipeSearchBox, DatePicker, RecipeCard, IngredientAddBox, CompactParsedIngredient },
2024-01-13 02:00:15 +00:00
data() {
return {
meal: {
date: new Date(),
2024-01-14 06:20:21 +00:00
recipes: [],
ingredients: [],
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 06:20:21 +00:00
this.meal.recipes.push(recipe);
2024-01-14 01:46:45 +00:00
},
selectDate(date) {
2024-01-17 06:03:11 +00:00
console.log("selectDate", date);
2024-01-14 01:46:45 +00:00
this.meal.date = date;
},
removeRecipe(recipe) {
this.meal.recipes = this.meal.recipes.filter(r => r.id !== recipe.id);
2024-01-14 06:20:21 +00:00
},
addIngredient(ingredient) {
this.meal.ingredients.push(ingredient);
},
deleteIngredient(ingredient) {
this.meal.ingredients = this.meal.ingredients.filter(i => i != ingredient);
},
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;
}
2024-01-14 06:20:21 +00:00
.saved-ingredient {
display: flex;
justify-content: space-between;
align-items: center;
margin: 1vh 1em;
}
2024-01-14 01:46:45 +00:00
.saved-recipe {
display: flex;
justify-content: space-between;
align-items: center;
margin: 1vh 1em;
}
2024-01-14 06:20:21 +00:00
.saved-ingredient p {
flex: 1;
margin: 0;
margin-right: 1em;
2024-01-14 01:46:45 +00:00
}
2024-01-14 06:20:21 +00:00
2024-01-14 01:46:45 +00:00
.saved-recipe button:hover {
background: #eee;
}
.saved-recipe .recipe-card {
flex: 1;
margin: 0 1em;
}
</style>