Add alert dialog when cancel with empty fields

This commit is contained in:
Julian Mutter 2024-05-26 10:49:38 +02:00
parent 0e34138a6a
commit 011dab8d99

View File

@ -2,10 +2,11 @@ use std::{borrow::BorrowMut, sync::Arc};
use gtk::prelude::*;
use relm4::{
component::{AsyncComponent, AsyncComponentParts},
component::{AsyncComponent, AsyncComponentParts, Connector},
prelude::*,
AsyncComponentSender,
};
use relm4_components::alert::{Alert, AlertMsg, AlertSettings};
use crate::{database::Database, sheet::Sheet, sheet_dao};
@ -17,6 +18,7 @@ pub struct SheetEditDialogModel {
sheet_composer: String,
is_book: bool,
book_sheets: Vec<(String, String, i64)>,
alert_empty_fields: Connector<Alert>,
}
pub struct SheetEditDialogInit {
@ -155,6 +157,15 @@ impl AsyncComponent for SheetEditDialogModel {
sheet_composer,
is_book,
book_sheets: Vec::new(),
alert_empty_fields: Alert::builder().transient_for(&root).launch(AlertSettings {
text: String::from("Missing input"),
secondary_text: Some(String::from("Please make sure all fields are filled")),
is_modal: true,
destructive_accept: false,
confirm_label: String::from("Ok"),
cancel_label: String::from("Cancel"),
option_label: None,
}),
};
let widgets = view_output!();
@ -167,13 +178,15 @@ impl AsyncComponent for SheetEditDialogModel {
&mut self,
msg: Self::Input,
sender: AsyncComponentSender<Self>,
_root: &Self::Root,
root: &Self::Root,
) {
match msg {
SheetEditDialogInput::Accept => {
self.hidden = true;
if let Some(mut sheet) = self.sheet.take() {
if let Some(sheet) = self.sheet.take() {
if self.sheet_name.is_empty() || self.sheet_composer.is_empty() {
self.alert_empty_fields.emit(AlertMsg::Show);
return;
}
// match sheet.kind.borrow_mut() {
// crate::sheet::SheetKind::Sheet {
// name,
@ -199,6 +212,7 @@ impl AsyncComponent for SheetEditDialogModel {
.output(SheetEditDialogOutput::SheetEdited(sheet))
.unwrap();
}
self.hidden = true;
}
SheetEditDialogInput::Cancel => {
self.hidden = true;