[pdm-devel] [PATCH proxmox-yew-comp 2/2] confirm_button: use confirm dialog and always spawn a dialog
Shannon Sterz
s.sterz at proxmox.com
Thu Dec 19 12:00:58 CET 2024
this uses the new `ConfirmDialog` component from pwt and now always
spawns a dialog, even if no explicit confirm message was set.
Signed-off-by: Shannon Sterz <s.sterz at proxmox.com>
---
src/confirm_button.rs | 30 ++++++++++--------------------
1 file changed, 10 insertions(+), 20 deletions(-)
diff --git a/src/confirm_button.rs b/src/confirm_button.rs
index 95b2b6d..9406d4b 100644
--- a/src/confirm_button.rs
+++ b/src/confirm_button.rs
@@ -1,8 +1,8 @@
use yew::html::{IntoEventCallback, IntoPropValue};
+use pwt::prelude::*;
use pwt::props::IntoOptionalInlineHtml;
-use pwt::widget::{Button, Column, MessageBoxButtons};
-use pwt::{prelude::*, widget::MessageBox};
+use pwt::widget::{Button, Column, ConfirmDialog};
use pwt_macros::{builder, widget};
@@ -122,25 +122,15 @@ impl Component for ProxmoxConfirmButton {
let props = ctx.props();
match msg {
Msg::Request => {
- if let Some(message) = &props.confirm_message {
- if self.dialog.is_some() {
- return false;
- }
-
- let dialog = MessageBox::new(tr!("Confirm"), message.clone())
- .buttons(MessageBoxButtons::YesNo)
- .on_close(ctx.link().callback(|confirm| {
- if confirm {
- Msg::Activate
- } else {
- Msg::CloseDialog
- }
- }));
-
- self.dialog = Some(dialog.into());
- } else {
- ctx.link().send_message(Msg::Activate);
+ let mut dialog = ConfirmDialog::default()
+ .on_confirm(ctx.link().callback(|_| Msg::Activate))
+ .on_close(ctx.link().callback(|_| Msg::CloseDialog));
+
+ if let Some(confirm_message) = &props.confirm_message {
+ dialog.set_confirm_message(confirm_message.clone())
}
+
+ self.dialog = Some(dialog.into());
true
}
Msg::Activate => {
--
2.39.5
More information about the pdm-devel
mailing list