LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Fix #341: By Date and Keywords rows show their photos from All Photos
Claude1b4518c20267
diff --git a/crates/ui-egui/src/panels/left.rs b/crates/ui-egui/src/panels/left.rsindex f69b487f3..c0fece7f6 100644--- a/crates/ui-egui/src/panels/left.rs+++ b/crates/ui-egui/src/panels/left.rs@@ -560,11 +560,21 @@ fn date_row(app: &mut LightcraftApp, ui: &mut egui::Ui, key: &str, label: &str,}if resp.clicked() {let v = if sel { serde_json::Value::Null } else { json!(key) };+ browse_all_photos(app, !sel);let _ = app.run("library.filter", json!({"date": v}));}open}+/// By Date and Keywords count every photo in the library, so choosing a row shows those photos+/// from All Photos, not from whatever album or folder happened to be open, where they could be+/// missing (issue #341). Only when choosing (`on`), not when clearing the row again.+fn browse_all_photos(app: &mut LightcraftApp, on: bool) {+ if on && app.session.source != LibrarySource::All {+ let _ = app.run("library.source", json!({"kind": "all"}));+ }+}+fn albums_tree(app: &mut LightcraftApp, ui: &mut egui::Ui, all: &[Album], parent: Option<AlbumId>, indent: f32) {let mut kids: Vec<&Album> = all.iter().filter(|a| a.parent == parent).collect();kids.sort_by_key(|a| (!a.folder, a.name.to_lowercase()));@@ -757,6 +767,7 @@ fn keyword_rows(app: &mut LightcraftApp, ui: &mut egui::Ui, nodes: &[KeywordNodelet resp = resp.on_hover_text(if n.children.is_empty() { n.path.clone() } else { format!("{} (includes the keywords below it)", n.path) });if resp.clicked() {let v = if sel { serde_json::Value::Null } else { json!(n.path) };+ browse_all_photos(app, !sel);let _ = app.run("library.filter", json!({"keyword": v}));}resp.context_menu(|ui| {diff --git a/crates/ui-egui/src/tests_panels.rs b/crates/ui-egui/src/tests_panels.rsindex a289e2ee2..a4d924b8a 100644--- a/crates/ui-egui/src/tests_panels.rs+++ b/crates/ui-egui/src/tests_panels.rs@@ -199,3 +199,29 @@ fn sidebar_sections_collapse_and_remember_it() {click(&mut h, "icon:albumNew");assert!(!h.app.ui.sidebar_section_collapsed("albums"), "the plus does not fold Albums");}++/// By Date and Keywords count the whole library, so choosing a row shows its photos from All+/// Photos even when another source (here Picks, which is empty) was open (issue #341).+#[test]+fn date_and_keyword_rows_show_their_photos_from_any_source() {+ let mut h = demo([1400.0, 900.0], json!({"view": "photoGrid", "leftPanel": true}));+ let first = h.app.session.visible_cloned()[0];+ let year = h.app.session.catalog.photo(first).and_then(|p| p.captured.clone()).expect("demo photo date")[..4].to_string();+ // (Keywords rows go through the same helper, `browse_all_photos`)+ for (row, key) in [(format!("date:{year}"), "date")] {+ let r = h.request("engine.execute", json!({"command": "library.source", "params": {"kind": "picks"}}), T);+ assert_eq!(r["ok"], true, "{r}");+ h.settle(SETTLE);+ assert!(h.app.session.visible().is_empty(), "no picks in the demo");+ let r = h.request("ui.clickWidget", json!({"id": row}), T);+ assert_eq!(r["ok"], true, "{r}");+ h.step();+ assert_eq!(h.app.session.source, lightcraft_engine::LibrarySource::All, "{key}");+ assert!(!h.app.session.visible().is_empty(), "{key}: its photos are shown");+ // choosing the row again clears it, and stays in All Photos+ let r = h.request("ui.clickWidget", json!({"id": row}), T);+ assert_eq!(r["ok"], true, "{r}");+ h.step();+ assert_eq!(h.app.session.filter, lightcraft_catalog::Filter::default(), "{key}");+ }+}