fix: paket: actually deactive views

This commit is contained in:
jane400 2024-09-17 19:22:48 +02:00 committed by jane400
parent ef63f18a77
commit ebde744290
2 changed files with 65 additions and 42 deletions

View file

@ -6,9 +6,11 @@ license.workspace = true
version.workspace = true
[dependencies]
relm4 = { version = "0.9" , features = [ "libadwaita", "macros" ] }
relm4-components = { version = "0.9" }
relm4-macros = { version = "0.9" }
# using git version, for https://github.com/Relm4/Relm4/pull/677
relm4 = { version = "0.9", features = [ "libadwaita", "macros" ], git = "https://github.com/Relm4/Relm4.git" }
relm4-components = { version = "0.9", git = "https://github.com/Relm4/Relm4.git" }
relm4-macros = { version = "0.9", git = "https://github.com/Relm4/Relm4.git" }
relm4-icons = { version = "0.9", git = "https://github.com/Relm4/icons.git" }
tracker = "0.2"
adw = {package = "libadwaita", version = "0.7", features = [ "v1_5" ]}
webkit = { package = "webkit6", version = "0.4" }
@ -16,6 +18,5 @@ reqwest = "0.12"
libpaket = { path = "../libpaket" }
glycin = { version = "2.0.0-beta", features = ["gdk4"] }
oo7 = { version = "0.3" }
relm4-icons = { version = "0.9" }
futures = "0.3"
gtk = { package = "gtk4", version = "0.9", features = ["v4_16"]}

View file

@ -17,9 +17,7 @@ use relm4::{
prelude::*,
};
use crate::advices::{AdvicesViewInput, AdvicesView};
use crate::advices::{AdvicesView, AdvicesViewInput};
#[tracker::track]
pub struct Ready {
@ -27,6 +25,7 @@ pub struct Ready {
login: crate::LoginSharedState,
activate: bool,
have_service_advices: bool,
have_service_tracking: bool,
#[do_not_track]
advices_component: AsyncController<AdvicesView>,
@ -51,12 +50,18 @@ pub enum ReadyCmds {
GotTracking(LibraryResult<Vec<Shipment>>),
}
#[derive(Debug)]
pub enum Services {
Advices,
SendungVerfolgung,
}
#[derive(Debug)]
pub enum ReadyInput {
Activate,
Deactivate,
HaveAdvicesService,
HavePaketankuendigungService,
HaveService(Services),
ServiceBorked(Services),
SearchTracking(String),
}
@ -70,18 +75,23 @@ impl Component for Ready {
view! {
#[root]
adw::ViewStack {
add = model.advices_component.widget() -> &gtk::ScrolledWindow {
/*#[track(model.changed_have_service_advices())]
set_visible: model.have_service_advices,*/
add = &model.advices_component.widget().clone() -> gtk::ScrolledWindow {
#[track(model.changed_have_service_advices())]
set_visible: model.have_service_advices,
} -> /*page_advices: adw::ViewStackPage*/ {
} -> page_advices: adw::ViewStackPage {
set_title: Some("Mail notification"),
set_name: Some("page_advices"),
/*#[track(model.changed_have_service_advices())]
set_visible: model.have_service_advices,*/
set_icon_name: Some(relm4_icons::icon_names::MAIL),
#[track(model.changed_have_service_advices())]
set_visible: model.have_service_advices,
},
add = &adw::Bin {
#[track(model.changed_have_service_tracking())]
set_visible: model.have_service_tracking,
#[wrap(Some)]
set_child = &gtk::ScrolledWindow {
#[wrap(Some)]
@ -110,9 +120,13 @@ impl Component for Ready {
},
}
}
} -> {
} -> page_tracking: adw::ViewStackPage {
set_title: Some("Shipment tracking"),
set_name: Some("page_tracking"),
set_icon_name: Some(relm4_icons::icon_names::PACKAGE_X_GENERIC),
#[track(model.changed_have_service_tracking())]
set_visible: model.have_service_tracking,
},
}
}
@ -127,6 +141,7 @@ impl Component for Ready {
let model = Ready {
have_service_advices: false,
have_service_tracking: true,
login: init.clone(),
activate: false,
tracking_factory,
@ -210,7 +225,13 @@ impl Component for Ready {
ReadyInput::Deactivate => {
self.set_activate(false);
}
ReadyInput::HavePaketankuendigungService => {
ReadyInput::HaveService(service) => match service {
Services::Advices => {
self.set_have_service_advices(true);
self.advices_component.emit(AdvicesViewInput::Fetch);
}
Services::SendungVerfolgung => {
self.set_have_service_tracking(true);
let token = self.login.clone();
sender.oneshot_command(async move {
// fetching advices
@ -229,10 +250,11 @@ impl Component for Ready {
)
});
}
ReadyInput::HaveAdvicesService => {
self.have_service_advices = true;
self.advices_component.emit(AdvicesViewInput::Fetch);
}
},
ReadyInput::ServiceBorked(service) => match service {
Services::Advices => self.set_have_service_advices(false),
Services::SendungVerfolgung => self.set_have_service_tracking(false),
},
}
}
@ -251,13 +273,13 @@ impl Component for Ready {
match service {
libpaket::stammdaten::CustomerDataService::Packstation => (),
libpaket::stammdaten::CustomerDataService::Paketankuendigung => {
sender.input(ReadyInput::HavePaketankuendigungService);
sender.input(ReadyInput::HaveService(Services::SendungVerfolgung))
}
libpaket::stammdaten::CustomerDataService::PostfilialeDirekt => (),
libpaket::stammdaten::CustomerDataService::Digiben => (),
libpaket::stammdaten::CustomerDataService::GeraetAktiviert => (),
libpaket::stammdaten::CustomerDataService::Briefankuendigung => {
sender.input(ReadyInput::HaveAdvicesService);
sender.input(ReadyInput::HaveService(Services::Advices))
}
}
}