diff options
author | Joris | 2022-02-27 09:36:14 +0100 |
---|---|---|
committer | Joris | 2022-02-27 09:36:14 +0100 |
commit | f58c120bcc0a84156e5e253be57c1f958ea8576e (patch) | |
tree | 664951a5b791469fea036a0552946f1bfc995116 /src/gui/form/mod.rs | |
parent | 5f1f9065476a46ccced3f1b0e31a90d3a00eccef (diff) |
Don’t create an event if repetition is not valid
Diffstat (limited to 'src/gui/form/mod.rs')
-rw-r--r-- | src/gui/form/mod.rs | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/gui/form/mod.rs b/src/gui/form/mod.rs index 4bf6f90..57ccac7 100644 --- a/src/gui/form/mod.rs +++ b/src/gui/form/mod.rs @@ -81,19 +81,23 @@ pub async fn show(app: &App, event: Event, is_new: bool) { let conn = app.conn.clone(); let tx = app.tx.clone(); button.connect_clicked(glib::clone!(@weak dialog, @strong event => move |_| { - let repetition = repetition::validate(&repetition_model); - match event::validate(event.id, date.buffer().text(), name.buffer().text(), start.buffer().text(), end.buffer().text(), repetition) { - Some(new) => { - match if is_new { db::insert(&conn, &new) } else { db::update(&conn, &new) } { - Ok(_) => { - let msg = if is_new { Msg::AddEvent { new } } else { Msg::UpdateEvent { old: event.clone(), new } }; - update::send(tx.clone(), msg); - dialog.close() - }, - Err(err) => eprintln!("Error when upserting event: {err}") + match repetition::validate(&repetition_model) { + Ok(repetition) => { + match event::validate(event.id, date.buffer().text(), name.buffer().text(), start.buffer().text(), end.buffer().text(), repetition) { + Some(new) => { + match if is_new { db::insert(&conn, &new) } else { db::update(&conn, &new) } { + Ok(_) => { + let msg = if is_new { Msg::AddEvent { new } } else { Msg::UpdateEvent { old: event.clone(), new } }; + update::send(tx.clone(), msg); + dialog.close() + }, + Err(err) => eprintln!("Error when upserting event: {err}") + } + } + None => eprintln!("Event is not valid: {event:?}") } }, - None => eprintln!("Event is not valid: {event:?}") + Err(message) => eprintln!("{message}") } })); |