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

53 lines
1.5 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>
2025-10-18 02:01:18 +00:00
<script setup>
import { ref, computed, onBeforeMount } from 'vue'
import { useRoute } from 'vue-router'
2024-10-15 08:40:06 +00:00
import { ago } from '@/dateformats.js'
2025-10-18 01:36:55 +00:00
import { getShoppingList } from '@/api/shopping'
2025-07-30 08:10:22 +00:00
import { itemsToGroups, uniqueMeals } from './shopping.js'
2024-05-20 12:16:39 +00:00
import MealSelectionList from './MealSelectionList.vue'
import ShoppingListItem from './ShoppingListItem.vue'
2025-10-18 02:01:18 +00:00
const route = useRoute()
const shoppingList = ref(null)
const includedMeals = computed(() => (shoppingList.value ? uniqueMeals(shoppingList.value.items) : []))
const listByProduct = computed(() => (shoppingList.value ? itemsToGroups(shoppingList.value.items) : []))
onBeforeMount(async () => {
const idParam = route.params.id
const id = typeof idParam === 'string' ? parseInt(idParam) : idParam
shoppingList.value = await getShoppingList(id)
})
2024-05-20 12:16:39 +00:00
</script>