From d778817fd88b3bc0ced56aad8bf0ac57fcf932ef Mon Sep 17 00:00:00 2001 From: dadaloop82 Date: Sun, 19 Apr 2026 06:52:16 +0000 Subject: [PATCH] fix: auto-add to Bring! items running out within 7 days MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - autoAddCriticalItems now adds: - critical: always (unchanged) - high: always (removed sub-conditions — PHP already gates high urgency strictly) - medium + days_left <= 7 + uses_per_month >= 3 (NEW: weekly depletion rule) - Reduce auto-add guard from 10 min to 5 min for faster detection - Covers: Latte di Montagna (high, 3gg), items running out mid-week (medium, 4-7gg) --- assets/js/app.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/assets/js/app.js b/assets/js/app.js index 35ae9da..c1348b9 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -6721,19 +6721,19 @@ function _isBringPurchased(name, urgency) { } async function autoAddCriticalItems() { - // Time-based guard: run at most once every 10 minutes (not session-based, so new critical items get added promptly) + // Time-based guard: run at most once every 5 minutes const lastRun = parseInt(localStorage.getItem('_autoAddedCriticalTs') || '0'); - if (Date.now() - lastRun < 10 * 60 * 1000) return; + if (Date.now() - lastRun < 5 * 60 * 1000) return; localStorage.setItem('_autoAddedCriticalTs', String(Date.now())); // Auto-add rules: // - critical: always - // - high: when qty=0 OR pct_left<20 (almost gone) OR days_left<=3 (imminent) - // - any urgency with days_left<=2 and uses_per_month>=5 (running out tomorrow for heavy user) + // - high: always (PHP already applies strict criteria for high urgency) + // - medium: when running out within 7 days (<1 week) for items used ≥3x/month const toAdd = smartShoppingItems.filter(i => { if (i.on_bring || _isBringPurchased(i.name, i.urgency)) return false; if (i.urgency === 'critical') return true; - if (i.urgency === 'high' && (i.current_qty === 0 || i.pct_left < 20 || i.days_left <= 3)) return true; - if (i.days_left <= 2 && (i.uses_per_month || 0) >= 5) return true; + if (i.urgency === 'high') return true; + if (i.urgency === 'medium' && (i.days_left ?? 999) <= 7 && (i.uses_per_month || 0) >= 3) return true; return false; }); if (toAdd.length === 0) return;