From 864d004cbd85c0eb78c0166f30798e0c6c3c930e Mon Sep 17 00:00:00 2001 From: Davide Grilli Date: Thu, 26 Mar 2026 23:35:14 +0100 Subject: [PATCH] aggiungi generazione lista spesa dal piano pasti MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bottone "Genera lista della spesa" in fondo alla pagina Piano Pasti: - raccoglie tutti gli item da tutti i giorni e pasti - deduplica (case-insensitive) e salta item già presenti in lista - aggiunge come non spuntati alla lista esistente - naviga automaticamente alla tab Lista della spesa Co-Authored-By: Claude Sonnet 4.6 --- src/App.vue | 2 +- src/pages/MealPlanner.vue | 50 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) 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') +} + +