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

62 lines
1.5 KiB
Vue
Raw Normal View History

2024-05-20 12:16:39 +00:00
<template>
2025-10-18 02:08:22 +00:00
<h3>Purchased {{ shoppingList ? ago(shoppingList.created_date) : '' }}</h3>
<div v-if="includedMeals.length > 0">
<h4>Included Meals</h4>
2025-10-18 03:16:34 +00:00
<meal-selection-list
:checked="includedMeals"
:meals="includedMeals"
:disabled="true"
/>
2025-10-18 02:08:22 +00:00
</div>
<ul class="full-shopping-list">
2025-10-18 03:16:34 +00:00
<li
v-for="item in listByProduct"
:key="item.id"
>
2025-10-18 02:08:22 +00:00
<shopping-list-item :shopping-list-item-group="item" />
</li>
</ul>
2024-05-20 12:16:39 +00:00
</template>
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)
2025-10-18 02:08:22 +00:00
const includedMeals = computed(() =>
shoppingList.value ? uniqueMeals(shoppingList.value.items) : []
)
const listByProduct = computed(() =>
shoppingList.value ? itemsToGroups(shoppingList.value.items) : []
)
2025-10-18 02:01:18 +00:00
onBeforeMount(async () => {
const idParam = route.params.id
const id = typeof idParam === 'string' ? parseInt(idParam) : idParam
shoppingList.value = await getShoppingList(id)
})
2025-10-18 02:08:22 +00:00
</script>
2025-10-18 03:16:34 +00:00
<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>