From ebde744290144773e1c90cfd876fe23987fc6874 Mon Sep 17 00:00:00 2001 From: jane400 Date: Tue, 17 Sep 2024 19:22:48 +0200 Subject: [PATCH] fix: paket: actually deactive views --- paket/Cargo.toml | 11 +++--- paket/src/ready.rs | 96 ++++++++++++++++++++++++++++------------------ 2 files changed, 65 insertions(+), 42 deletions(-) diff --git a/paket/Cargo.toml b/paket/Cargo.toml index 9d25785..e608b1c 100644 --- a/paket/Cargo.toml +++ b/paket/Cargo.toml @@ -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"]} \ No newline at end of file +gtk = { package = "gtk4", version = "0.9", features = ["v4_16"]} diff --git a/paket/src/ready.rs b/paket/src/ready.rs index 17127f1..db424fb 100644 --- a/paket/src/ready.rs +++ b/paket/src/ready.rs @@ -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, @@ -51,12 +50,18 @@ pub enum ReadyCmds { GotTracking(LibraryResult>), } +#[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() -> >k::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 = >k::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,29 +225,36 @@ impl Component for Ready { ReadyInput::Deactivate => { self.set_activate(false); } - ReadyInput::HavePaketankuendigungService => { - let token = self.login.clone(); - sender.oneshot_command(async move { - // fetching advices - let dhli_token = crate::login::get_id_token(&token).await.unwrap(); - let client = libpaket::WebClient::new(); - ReadyCmds::GotTracking( - client - .tracking_search( - TrackingParams { - language: Some("de".to_string()), - }, - Vec::new(), - Some(&dhli_token), - ) - .await, - ) - }); - } - ReadyInput::HaveAdvicesService => { - self.have_service_advices = true; - self.advices_component.emit(AdvicesViewInput::Fetch); - } + 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 + let dhli_token = crate::login::get_id_token(&token).await.unwrap(); + let client = libpaket::WebClient::new(); + ReadyCmds::GotTracking( + client + .tracking_search( + TrackingParams { + language: Some("de".to_string()), + }, + Vec::new(), + Some(&dhli_token), + ) + .await, + ) + }); + } + }, + 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)) } } }