Photo Album: Update edits an album that has no id

The form chose between insert and edit by the album id, so Update on an
album from before albums had ids inserted a second album. The form keeps its
edit mode and leaves the id out for such an album.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Dylan M. Taylor
2026-11-30 16:54:11 +00:00
co-authored by Claude Opus 5.5
parent ae3b354e44
commit 81bd17934c
2 changed files with 40 additions and 3 deletions
+8 -3
View File
@@ -114,6 +114,7 @@ pub(crate) fn open(app: &SlideApp, ctx: &egui::Context, params: &Value) -> Hoste
let album = params.get("album").and_then(album_json_id).and_then(|id| i64::try_from(id).ok()).unwrap_or(0);
fields.set("album", album);
let editing = params.get("items").is_some();
fields.set("editing", editing);
HostedParamDialog::new(ctx, "photoAlbum", fields, move |fields| {
let list = Param::custom("items", "Pictures in album", |ui, fields, context| {
Stack::new()
@@ -263,6 +264,7 @@ pub(crate) fn open(app: &SlideApp, ctx: &egui::Context, params: &Value) -> Hoste
Param::new("grayscale", "ALL pictures black and white", ParamKind::bool(false)),
choice("theme", "Album theme", "DeckCraft", &ALBUM_THEMES.iter().map(|name| (*name, *name)).collect::<Vec<_>>()),
Param::new("album", "Album", ParamKind::int(None, None, 0)).shown(false),
Param::new("editing", "Editing an album", ParamKind::bool(false)).shown(false),
Param::new("themeWas", "Opening theme", ParamKind::text("")).shown(false),
];
ParamDialog::new("photoAlbum", "Photo Album", rows)
@@ -371,9 +373,12 @@ pub(crate) fn finish(app: &mut SlideApp, result: &ParamResult, _host: &mut Dialo
if Some(theme) != fields.text("themeWas") {
payload["theme"] = json!(theme);
}
let album = fields.int("album").filter(|id| *id > 0);
if let Some(album) = album {
if !fields.bool("editing").unwrap_or(false) {
return app.run("insert.photoAlbum", payload).map(|_| ());
}
// An album from before albums had ids has none: the engine finds the selected run of album slides.
if let Some(album) = fields.int("album").filter(|id| *id > 0) {
payload["album"] = json!(album);
}
app.run(if album.is_some() { "insert.photoAlbumEdit" } else { "insert.photoAlbum" }, payload).map(|_| ())
app.run("insert.photoAlbumEdit", payload).map(|_| ())
}
@@ -151,6 +151,38 @@ fn update_reflows_the_open_album() {
assert_eq!(slides(&h), expanded, "the last undo restores the original album");
}
/// The bug this prevents: Update on an album made before albums had ids (a run of slides named Photo Album) inserted a
/// second album and left the first in place.
#[test]
fn update_reflows_an_album_without_an_id() {
let data = deckcraft_engine::cmd::base64_encode(&png());
let pictures = json!([{"name": "hill.png", "data": data}, {"name": "lake.png", "data": data}]);
let mut h = harness_with(
Session::with_new(),
Services::default(),
Harness::builder().with_size(egui::vec2(1600.0, 1200.0)).with_step_dt(1.0 / 60.0),
|_| {},
);
h.state_mut().run("insert.photoAlbum", json!({"pictures": pictures, "layout": "1"})).expect("create");
h.state_mut()
.session
.edit(|doc, _| {
for slide in &mut doc.slides {
std::sync::Arc::make_mut(slide).raw_ext = None;
}
Ok(())
})
.unwrap();
let expanded = slides(&h);
h.state_mut().run("insert.photoAlbumEdit", json!({})).expect("edit");
h.run_steps(3);
control(&mut h, "ui.dialog.set", json!({"dialog": "top", "field": "layout", "value": "2"}));
control(&mut h, "ui.dialog.confirm", json!({"dialog": "top"}));
h.run_steps(4);
assert!(super::open_keys(&h.ctx).is_empty(), "status {:?}", h.state().status);
assert!(slides(&h) < expanded, "the album reflowed in place");
}
#[test]
fn a_pick_left_open_by_a_closed_album_does_not_reach_the_next_album() {
for queued_before_cancel in [false, true] {