From b9f3eb3301bdfba8d8dea7d9839c1745faf618c2 Mon Sep 17 00:00:00 2001 From: dadaloop82 Date: Tue, 10 Mar 2026 17:53:17 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20ricorda=20ingredienti=20gi=C3=A0=20usati?= =?UTF-8?q?=20nella=20ricetta=20cachata?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Quando clicchi 'Usa', salva used=true nell'ingrediente nel localStorage - Al reload, ingredienti già usati mostrano '✔️ Scalato' disabilitato - Evita di scalare lo stesso ingrediente due volte per sbaglio --- assets/js/app.js | 19 +++++++++++++++++-- data/dispensa.db | Bin 73728 -> 73728 bytes 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/assets/js/app.js b/assets/js/app.js index cfd11ad..a2f89dd 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -2690,6 +2690,16 @@ async function useRecipeIngredient(idx, productId, location, qtyNumber, btn) { } btn.textContent = '✔️ Scalato'; btn.classList.add('btn-used'); + + // Persist used state in cached recipe + try { + const cached = JSON.parse(localStorage.getItem('cachedRecipe') || 'null'); + if (cached && cached.recipe && cached.recipe.ingredients && cached.recipe.ingredients[idx]) { + cached.recipe.ingredients[idx].used = true; + localStorage.setItem('cachedRecipe', JSON.stringify(cached)); + } + } catch (e) { /* ignore */ } + showToast('📦 Ingrediente scalato dalla dispensa!', 'success'); } else { btn.disabled = false; @@ -2727,7 +2737,8 @@ function renderRecipe(r) { if (ing.from_pantry && ing.product_id) { const qtyNum = ing.qty_number || 0; const loc = (ing.location || 'dispensa').replace(/'/g, "\\'"); - html += `
  • `; + const alreadyUsed = ing.used === true; + html += `
  • `; html += `${ing.name}${ing.brand ? ' (' + ing.brand + ')' : ''}: ${ing.qty} ✅`; // Detail line: location + expiry let details = []; @@ -2744,7 +2755,11 @@ function renderRecipe(r) { } if (details.length) html += `
    ${details.join(' · ')}`; html += `
    `; - html += ``; + if (alreadyUsed) { + html += ``; + } else { + html += ``; + } html += `
  • `; } else { const pantryIcon = ing.from_pantry ? ' ✅' : ' 🛒'; diff --git a/data/dispensa.db b/data/dispensa.db index 89649c4d20cd304b9494eb2b9dbfacdc578d1df4..7174fc7c2777cda42c8e20de072c00fef6347f10 100644 GIT binary patch delta 298 zcmZoTz|wGlWy42%#`w*j?1coF;~5@KW)IlS!pP6?aH6BMjZQoV1EVmzIIpp5erbvQ z1qLukE6PmIH!?6X(={;GH8fB#G`BJ_v@$f(hy$r+l;t(%0;-WwOpxK_ zVP$4ybd3j*TydMP%r#(Qj%Syg%)VeZ3%en^IRo7*&aP-|>qz-DhZS}R delta 177 zcmV;i08amazyyH61hDZx0bR55KN1iFT>&|h2T;3_fp@bxQOiCaT@BO#5AYBB5A_e~ z59ANt57-aV56ln754sP)544jckcP9YkQ@z>kPx%foiG9eT?a{%2cWyLfrkc@8K)AH zUr`0KV5byT0lkwT_!g6k{SyZ