From bcd7580729e3d4e19b6c203f81119de1c7e81546 Mon Sep 17 00:00:00 2001 From: dadaloop82 Date: Thu, 7 May 2026 17:48:18 +0000 Subject: [PATCH] fix: show price total on dashboard via sessionStorage fallback --- assets/js/app.js | 38 +++++++++++++++++++++++++++----------- index.html | 2 +- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/assets/js/app.js b/assets/js/app.js index abf2cdf..1666940 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -3206,6 +3206,8 @@ async function loadDashboard() { }); // Load shopping list count from Bring! loadShoppingCount(); + // Show last known price total immediately from sessionStorage (before next background fetch) + _updateDashboardPriceTotal(); // Quick recipe button - show when there are expiring products const recipeBar = document.getElementById('quick-recipe-bar'); @@ -9233,19 +9235,33 @@ function _updateDashboardPriceTotal() { const el = document.getElementById('stat-price-total'); if (!el) return; const s = getSettings(); - if (!s.price_enabled || !shoppingItems.length) { el.style.display = 'none'; return; } - const sym = _currencySymbol(s.price_currency || 'EUR'); - const items = _buildPricePayload(); - let total = 0, count = 0; - for (const item of items) { - const e = _cachedPrices[item.name]; - if (e && e._qty === item.quantity && e._unit === item.unit && e.estimated_total != null) { - total += e.estimated_total; - count++; + if (!s.price_enabled) { el.style.display = 'none'; return; } + + // If shoppingItems are loaded, compute fresh total and persist it + if (shoppingItems.length > 0) { + const sym = _currencySymbol(s.price_currency || 'EUR'); + const items = _buildPricePayload(); + let total = 0, count = 0; + for (const item of items) { + const e = _cachedPrices[item.name]; + if (e && e._qty === item.quantity && e._unit === item.unit && e.estimated_total != null) { + total += e.estimated_total; + count++; + } + } + if (count > 0) { + const text = `ca. ${sym}${total.toFixed(2)}`; + el.textContent = text; + el.style.display = ''; + try { sessionStorage.setItem('_pricetotal', text); } catch { /* quota */ } + return; } } - if (count > 0) { - el.textContent = `ca. ${sym}${total.toFixed(2)}`; + + // Fallback: restore last known total saved in sessionStorage (dashboard before visiting shopping tab) + const saved = sessionStorage.getItem('_pricetotal'); + if (saved) { + el.textContent = saved; el.style.display = ''; } else { el.style.display = 'none'; diff --git a/index.html b/index.html index 2de4335..107d34e 100644 --- a/index.html +++ b/index.html @@ -1461,6 +1461,6 @@ - +