munch-ease-frontend/src/components/shopping/PurchasedShoppingListPage.vue

79 lines
1.8 KiB
Vue
Raw Normal View History

2024-05-20 12:16:39 +00:00
<template>
2024-10-15 08:40:06 +00:00
<h3>Purchased {{ shoppingList ? ago(shoppingList.created_date) : '' }}</h3>
2024-05-20 12:16:39 +00:00
<div v-if="includedMeals.length > 0">
<h4>Included Meals</h4>
<meal-selection-list :checked="includedMeals" :meals="includedMeals" :disabled="true" />
</div>
2024-05-20 12:16:39 +00:00
<ul class="full-shopping-list">
<li v-for="item in listByProduct" :key="item.id">
<shopping-list-item :shopping-list-item-group="item" />
2024-05-20 12:16:39 +00:00
</li>
</ul>
</template>
<style scoped>
.full-shopping-list li {
list-style-type: none;
border: 1px solid #ccc;
border-radius: 0.5em;
margin-bottom: 1em;
}
.full-shopping-list {
padding: 0;
}
</style>
<script>
2024-10-15 08:40:06 +00:00
import { ago } from '@/dateformats.js'
2024-05-20 12:16:39 +00:00
import data from '@/data.js'
import { itemsToGroups } from './shopping.js'
2024-05-20 12:16:39 +00:00
import MealSelectionList from './MealSelectionList.vue'
import ShoppingListItem from './ShoppingListItem.vue'
export default {
name: 'FullShoppingListPage',
components: { MealSelectionList, ShoppingListItem },
props: {
id: [String, Number]
},
computed: {
includedMeals() {
if (!this.shoppingList) return [];
const seenMeals = new Set();
return this.shoppingList.items
.map(item => item.meal)
.filter(meal => {
if (!meal) return false;
if (seenMeals.has(meal.id)) return false;
seenMeals.add(meal.id);
return true;
});
},
listByProduct() {
return this.shoppingList ? itemsToGroups(this.shoppingList.items) : [];
}
},
2024-05-20 12:16:39 +00:00
data() {
return {
shoppingList: null,
}
},
async beforeMount() {
this.shoppingList = await data.getShoppingList(this.id);
},
2024-10-15 08:40:06 +00:00
methods: {
ago
}
2024-05-20 12:16:39 +00:00
}
</script>