diff --git a/frontend/src/views/ShoppingListView.vue b/frontend/src/views/ShoppingListView.vue index 03f5b04..3d8d08d 100644 --- a/frontend/src/views/ShoppingListView.vue +++ b/frontend/src/views/ShoppingListView.vue @@ -96,10 +96,11 @@ import { ref, computed, onMounted } from 'vue' import { useRoute } from 'vue-router' import ShoppingItem from '../components/ShoppingItem.vue' -import { useShoppingStore } from '../stores/mealPlan' +import { useShoppingStore, useMealPlanStore } from '../stores/mealPlan' const route = useRoute() const store = useShoppingStore() +const mealPlanStore = useMealPlanStore() const collapsed = ref>(new Set()) @@ -140,8 +141,19 @@ const checked = computed(() => store.items.filter(i => i.isChecked).length) const unchecked = computed(() => store.items.filter(i => !i.isChecked).length) const progress = computed(() => store.items.length ? Math.round((checked.value / store.items.length) * 100) : 0) -onMounted(() => { +onMounted(async () => { const id = route.params['mealPlanId'] - store.fetchItems(Array.isArray(id) ? id[0] : id) + const mealPlanId = Array.isArray(id) ? id[0] : id + if (mealPlanId) { + store.fetchItems(mealPlanId) + } else { + // No mealPlanId in URL — fetch current plan and use its ID + if (!mealPlanStore.currentPlan) { + await mealPlanStore.fetchCurrentPlan() + } + if (mealPlanStore.currentPlan?.id) { + store.fetchItems(mealPlanStore.currentPlan.id) + } + } })