feat: better error handling
errors during the upload are now shown in a separate user-friendly alert dialog, and you can also choose to upload the file to no folder
This commit is contained in:
parent
601ee85b5f
commit
94562b995a
4 changed files with 174 additions and 36 deletions
82
src/relm.rs
Normal file
82
src/relm.rs
Normal file
|
@ -0,0 +1,82 @@
|
|||
use relm4::{
|
||||
SimpleComponent,
|
||||
adw::{self, prelude::*},
|
||||
gtk::glib::clone,
|
||||
};
|
||||
|
||||
pub struct Dialog {
|
||||
window: adw::ApplicationWindow,
|
||||
visible: bool,
|
||||
heading: String,
|
||||
body: String,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum DialogInput {
|
||||
Show { heading: String, body: String },
|
||||
Dismiss,
|
||||
}
|
||||
|
||||
pub struct DialogWidgets {
|
||||
dialog: adw::AlertDialog,
|
||||
}
|
||||
|
||||
impl SimpleComponent for Dialog {
|
||||
type Init = adw::ApplicationWindow;
|
||||
type Root = adw::AlertDialog;
|
||||
type Widgets = DialogWidgets;
|
||||
type Input = DialogInput;
|
||||
type Output = ();
|
||||
|
||||
fn init_root() -> Self::Root {
|
||||
let dialog = adw::AlertDialog::builder().close_response("ok").build();
|
||||
dialog.add_response("ok", "OK");
|
||||
dialog
|
||||
}
|
||||
|
||||
fn init(
|
||||
window: Self::Init,
|
||||
root: Self::Root,
|
||||
sender: relm4::ComponentSender<Self>,
|
||||
) -> relm4::ComponentParts<Self> {
|
||||
let model = Self {
|
||||
window,
|
||||
visible: false,
|
||||
heading: String::new(),
|
||||
body: String::new(),
|
||||
};
|
||||
|
||||
root.connect_response(
|
||||
None,
|
||||
clone!(
|
||||
#[strong]
|
||||
sender,
|
||||
move |_, _| sender.input(DialogInput::Dismiss)
|
||||
),
|
||||
);
|
||||
|
||||
let widgets = DialogWidgets { dialog: root };
|
||||
|
||||
relm4::ComponentParts { model, widgets }
|
||||
}
|
||||
|
||||
fn update(&mut self, message: Self::Input, _sender: relm4::ComponentSender<Self>) {
|
||||
match message {
|
||||
DialogInput::Show { heading, body } => {
|
||||
self.heading = heading;
|
||||
self.body = body;
|
||||
self.visible = true;
|
||||
}
|
||||
DialogInput::Dismiss => self.visible = false,
|
||||
}
|
||||
}
|
||||
|
||||
fn update_view(&self, widgets: &mut Self::Widgets, _sender: relm4::ComponentSender<Self>) {
|
||||
widgets.dialog.set_heading(Some(&self.heading));
|
||||
widgets.dialog.set_body(&self.body);
|
||||
|
||||
if self.visible {
|
||||
widgets.dialog.present(Some(&self.window));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue