Auto-refresh UI after every data mutation
- Added refreshCurrentPage() to reload active page data - deleteInventoryItem/submitEditInventory now refresh current page (works from dashboard or inventory) - removeBringItem/addSelectedSuggestions update dashboard shopping count - Track current page ID for context-aware refresh
This commit is contained in:
+22
-2
@@ -324,7 +324,23 @@ async function api(action, params = {}, method = 'GET', body = null) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ===== PAGE NAVIGATION =====
|
// ===== PAGE NAVIGATION =====
|
||||||
|
// Track current page for auto-refresh
|
||||||
|
let _currentPageId = 'dashboard';
|
||||||
|
let _currentPageParam = null;
|
||||||
|
|
||||||
|
// Refresh current page data without full navigation
|
||||||
|
function refreshCurrentPage() {
|
||||||
|
switch(_currentPageId) {
|
||||||
|
case 'dashboard': loadDashboard(); break;
|
||||||
|
case 'inventory': loadInventory(); break;
|
||||||
|
case 'shopping': loadShoppingList(); break;
|
||||||
|
case 'products': loadAllProducts(); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function showPage(pageId, param = null) {
|
function showPage(pageId, param = null) {
|
||||||
|
_currentPageId = pageId;
|
||||||
|
_currentPageParam = param;
|
||||||
// Hide all pages
|
// Hide all pages
|
||||||
document.querySelectorAll('.page').forEach(p => p.classList.remove('active'));
|
document.querySelectorAll('.page').forEach(p => p.classList.remove('active'));
|
||||||
// Show target page
|
// Show target page
|
||||||
@@ -729,7 +745,7 @@ async function deleteInventoryItem(id) {
|
|||||||
await api('inventory_delete', {}, 'POST', { id });
|
await api('inventory_delete', {}, 'POST', { id });
|
||||||
closeModal();
|
closeModal();
|
||||||
showToast('Prodotto rimosso', 'success');
|
showToast('Prodotto rimosso', 'success');
|
||||||
loadInventory();
|
refreshCurrentPage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -785,7 +801,7 @@ async function submitEditInventory(e, id) {
|
|||||||
await api('inventory_update', {}, 'POST', { id, quantity: qty, location: loc, expiry_date: expiry });
|
await api('inventory_update', {}, 'POST', { id, quantity: qty, location: loc, expiry_date: expiry });
|
||||||
closeModal();
|
closeModal();
|
||||||
showToast('Aggiornato!', 'success');
|
showToast('Aggiornato!', 'success');
|
||||||
loadInventory();
|
refreshCurrentPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===== BARCODE SCANNER =====
|
// ===== BARCODE SCANNER =====
|
||||||
@@ -2285,6 +2301,8 @@ async function removeBringItem(idx) {
|
|||||||
shoppingItems.splice(idx, 1);
|
shoppingItems.splice(idx, 1);
|
||||||
renderShoppingItems();
|
renderShoppingItems();
|
||||||
showToast('Rimosso dalla lista', 'success');
|
showToast('Rimosso dalla lista', 'success');
|
||||||
|
// Update dashboard shopping count
|
||||||
|
loadShoppingCount();
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
showToast('Errore nella rimozione', 'error');
|
showToast('Errore nella rimozione', 'error');
|
||||||
@@ -2408,6 +2426,8 @@ async function addSelectedSuggestions() {
|
|||||||
showToast(`${data.added} prodott${data.added === 1 ? 'o aggiunto' : 'i aggiunti'} a Bring!`, 'success');
|
showToast(`${data.added} prodott${data.added === 1 ? 'o aggiunto' : 'i aggiunti'} a Bring!`, 'success');
|
||||||
// Refresh list
|
// Refresh list
|
||||||
await loadShoppingList();
|
await loadShoppingList();
|
||||||
|
// Update dashboard shopping count
|
||||||
|
loadShoppingCount();
|
||||||
// Clear suggestions
|
// Clear suggestions
|
||||||
document.getElementById('shopping-suggestions').style.display = 'none';
|
document.getElementById('shopping-suggestions').style.display = 'none';
|
||||||
suggestionItems = [];
|
suggestionItems = [];
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user