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) <noreply@anthropic.com>
This commit is contained in:
2026-04-16 07:26:01 +00:00
parent 165acc9d22
commit a5471276e8

View File

@@ -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<Set<string>>(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)
}
}
})
</script>