fix: prices cached on tab switch; background price fetch every 2min; stat-price-total bigger
This commit is contained in:
@@ -2611,8 +2611,8 @@ body {
|
|||||||
}
|
}
|
||||||
.stat-price-total {
|
.stat-price-total {
|
||||||
display: block;
|
display: block;
|
||||||
font-size: 0.62rem;
|
font-size: 0.75rem;
|
||||||
font-weight: 600;
|
font-weight: 700;
|
||||||
color: #15803d;
|
color: #15803d;
|
||||||
margin-top: 2px;
|
margin-top: 2px;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
|||||||
+29
-5
@@ -9977,10 +9977,29 @@ async function renderShoppingItems() {
|
|||||||
document.getElementById('btn-fetch-prices').style.display = 'inline-flex';
|
document.getElementById('btn-fetch-prices').style.display = 'inline-flex';
|
||||||
// Allow a new fetch (re-render may have happened while old fetch was running)
|
// Allow a new fetch (re-render may have happened while old fetch was running)
|
||||||
_pricesFetching = false;
|
_pricesFetching = false;
|
||||||
// Immediately apply any prices already fetched this session — no flicker, no loading bar
|
// Check if ALL items are already cached with matching qty/unit
|
||||||
_applyPriceBadgesFromCache();
|
const _pItems = _buildPricePayload();
|
||||||
// Fetch only items not yet priced (or all if none are cached yet)
|
const _allCached = _pItems.length > 0 && _pItems.every(item => {
|
||||||
fetchAllPrices(false);
|
const e = _cachedPrices[item.name];
|
||||||
|
return e && e._qty === item.quantity && e._unit === item.unit && e.estimated_total != null;
|
||||||
|
});
|
||||||
|
if (_allCached) {
|
||||||
|
// Prices are fully fresh — apply instantly, no loading state
|
||||||
|
const { total: ct, count: cc } = _applyPriceBadgesFromCache();
|
||||||
|
const sym = _currencySymbol(s2.price_currency || 'EUR');
|
||||||
|
const totalEl = document.getElementById('price-total-value');
|
||||||
|
if (totalEl && cc > 0) totalEl.textContent = `ca. ${sym}${ct.toFixed(2)}`;
|
||||||
|
const fetchBtn2 = document.getElementById('btn-fetch-prices');
|
||||||
|
const refreshBtn2 = document.getElementById('btn-price-refresh');
|
||||||
|
if (fetchBtn2) fetchBtn2.disabled = false;
|
||||||
|
if (refreshBtn2) { refreshBtn2.disabled = false; refreshBtn2.textContent = '🔄'; }
|
||||||
|
_updateDashboardPriceTotal();
|
||||||
|
} else {
|
||||||
|
// Immediately apply any prices already fetched this session — no flicker for cached items
|
||||||
|
_applyPriceBadgesFromCache();
|
||||||
|
// Fetch only items not yet priced (or stale)
|
||||||
|
fetchAllPrices(false);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
document.getElementById('shopping-price-bar').style.display = 'none';
|
document.getElementById('shopping-price-bar').style.display = 'none';
|
||||||
document.getElementById('btn-fetch-prices').style.display = 'none';
|
document.getElementById('btn-fetch-prices').style.display = 'none';
|
||||||
@@ -13400,7 +13419,7 @@ async function _initApp() {
|
|||||||
if (!_screensaverActive) refreshCurrentPage();
|
if (!_screensaverActive) refreshCurrentPage();
|
||||||
}, 5 * 60 * 1000);
|
}, 5 * 60 * 1000);
|
||||||
|
|
||||||
// 2) Ogni 2 min: aggiorna contatore lista spesa nel badge dashboard
|
// 2) Ogni 2 min: aggiorna contatore lista spesa nel badge dashboard e prezzi in background
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
if (_screensaverActive) return;
|
if (_screensaverActive) return;
|
||||||
if (_currentPageId === 'shopping') {
|
if (_currentPageId === 'shopping') {
|
||||||
@@ -13408,6 +13427,11 @@ async function _initApp() {
|
|||||||
loadShoppingList();
|
loadShoppingList();
|
||||||
} else {
|
} else {
|
||||||
loadShoppingCount();
|
loadShoppingCount();
|
||||||
|
// Fetch prices silently in background so dashboard stat stays fresh
|
||||||
|
const _s = getSettings();
|
||||||
|
if (_s.price_enabled && shoppingItems.length > 0 && !_pricesFetching) {
|
||||||
|
fetchAllPrices(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, 2 * 60 * 1000);
|
}, 2 * 60 * 1000);
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -11,7 +11,7 @@
|
|||||||
<title>EverShelf</title>
|
<title>EverShelf</title>
|
||||||
<link rel="manifest" href="manifest.json">
|
<link rel="manifest" href="manifest.json">
|
||||||
<link rel="icon" type="image/png" href="assets/img/logo/logo_icon.png">
|
<link rel="icon" type="image/png" href="assets/img/logo/logo_icon.png">
|
||||||
<link rel="stylesheet" href="assets/css/style.css?v=20260507b">
|
<link rel="stylesheet" href="assets/css/style.css?v=20260507c">
|
||||||
<!-- QuaggaJS for barcode scanning -->
|
<!-- QuaggaJS for barcode scanning -->
|
||||||
<script src="https://cdn.jsdelivr.net/npm/@ericblade/quagga2@1.8.4/dist/quagga.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/@ericblade/quagga2@1.8.4/dist/quagga.min.js"></script>
|
||||||
<!-- @xenova/transformers: ES-module bootstrap that exposes a lazy category-classifier as window._categoryPipelinePromise -->
|
<!-- @xenova/transformers: ES-module bootstrap that exposes a lazy category-classifier as window._categoryPipelinePromise -->
|
||||||
@@ -1462,6 +1462,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="assets/js/app.js?v=20260507b"></script>
|
<script src="assets/js/app.js?v=20260507c"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user