From 62cdd7740fc3cd80ad53d8f613b29dbf80451d19 Mon Sep 17 00:00:00 2001 From: 4aiman Date: Sat, 23 May 2026 18:39:28 +0300 Subject: [PATCH] Fix back navigation after modal fullscreen, fix SQL operator precedence Navigation: - Stale {modal:true}/{chartFull:true} history entries after app restart caused back gesture to do nothing (no screen to render, no modal open). Now global popstate handler skips these stale entries with history.back(). Rust seed import: - Fixed SQL operator precedence in nutrients_guessed UPDATE: WHERE (guessed IS NULL OR guessed = 0) AND name_lower IN (...) was previously parsed as: guessed IS NULL OR (guessed = 0 AND ...) which matched ALL products with NULL guessed regardless of name. --- frontend/js/main.js | 7 ++++++- src-tauri/src/lib.rs | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/frontend/js/main.js b/frontend/js/main.js index 9e3659a..1223bcb 100644 --- a/frontend/js/main.js +++ b/frontend/js/main.js @@ -3008,9 +3008,14 @@ function esc(str) { window.addEventListener("popstate", (e) => { // If a modal is open, don't handle here (modal has its own handler) if (document.querySelector(".modal-overlay")) return; + // Stale modal/chart entries left after app restart — skip them + if (e.state && (e.state.modal || e.state.chartFull)) { + history.back(); + return; + } // Pop our nav stack and navigate to previous screen if (navStack.length > 1) { - navStack.pop(); // remove current + navStack.pop(); const prev = navStack[navStack.length - 1]; renderScreen(prev, true); } else if (e.state && e.state.screen) { diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 2290399..4e71f13 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -242,7 +242,7 @@ fn import_seed_products(app: tauri::AppHandle) -> Result { // Sync nutrients_guessed flag let _ = main_db.execute_batch( "UPDATE main.products SET nutrients_guessed = 1 - WHERE nutrients_guessed IS NULL OR nutrients_guessed = 0 + WHERE (nutrients_guessed IS NULL OR nutrients_guessed = 0) AND name_lower IN (SELECT s.name_lower FROM seed.products s WHERE s.nutrients_guessed = 1)" ); // Sync micronutrients for products that have them in seed but not in main