diff --git a/src/App.vue b/src/App.vue index ae6d73f..896b51d 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,6 +1,6 @@ @@ -21,6 +29,8 @@ import { reactive, watch } from 'vue' import MealCard from '../components/MealCard.vue' import { save, load } from '../utils/storage.js' +const emit = defineEmits(['go-shop']) + const days = [ { id: 'lunedi', label: 'Lunedì' }, { id: 'martedi', label: 'Martedì' }, @@ -50,4 +60,44 @@ function addItem(day, slot, text) { function removeItem(day, slot, idx) { meals[day][slot].splice(idx, 1) } + +function generateShopping() { + const allItems = days.flatMap(d => + ['colazione', 'pranzo', 'cena'].flatMap(slot => meals[d.id][slot]) + ) + const existing = load('shopping', []) + const existingNames = new Set(existing.map(i => i.name.toLowerCase())) + const seen = new Set() + const toAdd = [] + for (const name of allItems) { + const key = name.toLowerCase() + if (!existingNames.has(key) && !seen.has(key)) { + seen.add(key) + toAdd.push({ id: Date.now() + Math.random(), name, checked: false }) + } + } + save('shopping', [...existing, ...toAdd]) + emit('go-shop') +} + +