From a5471276e80fb0cae2993c9af714649289b988f9 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 16 Apr 2026 07:26:01 +0000 Subject: [PATCH] fix: auto-load shopping list from current meal plan When navigating to /shopping without a mealPlanId, fetch the current meal plan first and use its ID to load the shopping list. Co-Authored-By: Claude Opus 4.6 (1M context) --- frontend/src/views/ShoppingListView.vue | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) 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) + } + } })