From 3912d62623449742ef14ba1147b1351022cb1798 Mon Sep 17 00:00:00 2001 From: Valentin Tolmer Date: Tue, 12 Oct 2021 05:18:20 +0200 Subject: [PATCH] app: Disable buttons while the task is running --- app/src/components/add_group_member.rs | 13 +++++++----- app/src/components/add_user_to_group.rs | 13 +++++++----- app/src/components/create_group.rs | 21 ++++++++++---------- app/src/components/create_user.rs | 12 ++++++----- app/src/components/delete_group.rs | 14 +++++++------ app/src/components/delete_user.rs | 14 +++++++------ app/src/components/remove_user_from_group.rs | 9 ++++++--- app/src/components/user_details_form.rs | 11 ++++++---- 8 files changed, 62 insertions(+), 45 deletions(-) diff --git a/app/src/components/add_group_member.rs b/app/src/components/add_group_member.rs index 1d17e40..db8a2c0 100644 --- a/app/src/components/add_group_member.rs +++ b/app/src/components/add_group_member.rs @@ -40,7 +40,7 @@ pub struct AddGroupMemberComponent { /// The currently selected user. selected_user: Option, // Used to keep the request alive long enough. - _task: Option, + task: Option, } pub enum Msg { @@ -60,7 +60,7 @@ pub struct Props { impl AddGroupMemberComponent { fn get_user_list(&mut self) { - self._task = HostService::graphql_query::( + self.task = HostService::graphql_query::( list_user_names::Variables { filters: None }, self.link.callback(Msg::UserListResponse), "Error trying to fetch user list", @@ -77,7 +77,7 @@ impl AddGroupMemberComponent { None => return Ok(false), Some(user) => user.id, }; - self._task = HostService::graphql_query::( + self.task = HostService::graphql_query::( add_user_to_group::Variables { user: user_id, group: self.props.group_id, @@ -97,10 +97,12 @@ impl AddGroupMemberComponent { match msg { Msg::UserListResponse(response) => { self.user_list = Some(response?.users); + self.task = None; } Msg::SubmitAddMember => return self.submit_add_member(), Msg::AddMemberResponse(response) => { response?; + self.task = None; let user = self .selected_user .as_ref() @@ -140,7 +142,7 @@ impl Component for AddGroupMemberComponent { props, user_list: None, selected_user: None, - _task: None, + task: None, }; res.get_user_list(); res @@ -151,6 +153,7 @@ impl Component for AddGroupMemberComponent { Err(e) => { ConsoleService::error(&e.to_string()); self.props.on_error.emit(e); + self.task = None; true } Ok(b) => b, @@ -185,7 +188,7 @@ impl Component for AddGroupMemberComponent {
diff --git a/app/src/components/add_user_to_group.rs b/app/src/components/add_user_to_group.rs index ff77cf3..24ef85c 100644 --- a/app/src/components/add_user_to_group.rs +++ b/app/src/components/add_user_to_group.rs @@ -52,7 +52,7 @@ pub struct AddUserToGroupComponent { /// The currently selected group. selected_group: Option, // Used to keep the request alive long enough. - _task: Option, + task: Option, } pub enum Msg { @@ -72,7 +72,7 @@ pub struct Props { impl AddUserToGroupComponent { fn get_group_list(&mut self) { - self._task = HostService::graphql_query::( + self.task = HostService::graphql_query::( get_group_list::Variables, self.link.callback(Msg::GroupListResponse), "Error trying to fetch group list", @@ -89,7 +89,7 @@ impl AddUserToGroupComponent { None => return Ok(false), Some(group) => group.id, }; - self._task = HostService::graphql_query::( + self.task = HostService::graphql_query::( add_user_to_group::Variables { user: self.props.username.clone(), group: group_id, @@ -109,10 +109,12 @@ impl AddUserToGroupComponent { match msg { Msg::GroupListResponse(response) => { self.group_list = Some(response?.groups.into_iter().map(Into::into).collect()); + self.task = None; } Msg::SubmitAddGroup => return self.submit_add_group(), Msg::AddGroupResponse(response) => { response?; + self.task = None; // Adding the user to the group succeeded, we're not in the process of adding a // group anymore. let group = self @@ -154,7 +156,7 @@ impl Component for AddUserToGroupComponent { props, group_list: None, selected_group: None, - _task: None, + task: None, }; res.get_group_list(); res @@ -164,6 +166,7 @@ impl Component for AddUserToGroupComponent { Err(e) => { ConsoleService::error(&e.to_string()); self.props.on_error.emit(e); + self.task = None; true } Ok(b) => b, @@ -198,7 +201,7 @@ impl Component for AddUserToGroupComponent {
diff --git a/app/src/components/create_group.rs b/app/src/components/create_group.rs index cbcf561..1e898ac 100644 --- a/app/src/components/create_group.rs +++ b/app/src/components/create_group.rs @@ -25,7 +25,7 @@ pub struct CreateGroupForm { form: yew_form::Form, error: Option, // Used to keep the request alive long enough. - _task: Option, + task: Option, } #[derive(Model, Validate, PartialEq, Clone, Default)] @@ -52,21 +52,18 @@ impl CreateGroupForm { let req = create_group::Variables { name: model.groupname, }; - self._task = Some(HostService::graphql_query::( + self.task = Some(HostService::graphql_query::( req, self.link.callback(Msg::CreateGroupResponse), "Error trying to create group", )?); Ok(true) } - Msg::CreateGroupResponse(r) => { - match r { - Err(e) => return Err(e), - Ok(r) => ConsoleService::log(&format!( - "Created group '{}'", - &r.create_group.display_name - )), - }; + Msg::CreateGroupResponse(response) => { + ConsoleService::log(&format!( + "Created group '{}'", + &response?.create_group.display_name + )); self.route_dispatcher .send(RouteRequest::ChangeRoute(Route::from(AppRoute::ListGroups))); Ok(true) @@ -85,7 +82,7 @@ impl Component for CreateGroupForm { route_dispatcher: RouteAgentDispatcher::new(), form: yew_form::Form::::new(CreateGroupModel::default()), error: None, - _task: None, + task: None, } } @@ -95,6 +92,7 @@ impl Component for CreateGroupForm { Err(e) => { ConsoleService::error(&e.to_string()); self.error = Some(e); + self.task = None; true } Ok(b) => b, @@ -134,6 +132,7 @@ impl Component for CreateGroupForm { diff --git a/app/src/components/create_user.rs b/app/src/components/create_user.rs index 0540f5f..4db5fb1 100644 --- a/app/src/components/create_user.rs +++ b/app/src/components/create_user.rs @@ -26,7 +26,7 @@ pub struct CreateUserForm { form: yew_form::Form, error: Option, // Used to keep the request alive long enough. - _task: Option, + task: Option, } #[derive(Model, Validate, PartialEq, Clone, Default)] @@ -89,7 +89,7 @@ impl CreateUserForm { lastName: to_option(model.last_name), }, }; - self._task = Some(HostService::graphql_query::( + self.task = Some(HostService::graphql_query::( req, self.link.callback(Msg::CreateUserResponse), "Error trying to create user", @@ -118,7 +118,7 @@ impl CreateUserForm { username: user_id, registration_start_request: message, }; - self._task = Some( + self.task = Some( HostService::register_start( req, self.link @@ -143,7 +143,7 @@ impl CreateUserForm { server_data: response.server_data, registration_upload: registration_upload.message, }; - self._task = Some( + self.task = Some( HostService::register_finish( req, self.link.callback(Msg::RegistrationFinishResponse), @@ -175,7 +175,7 @@ impl Component for CreateUserForm { route_dispatcher: RouteAgentDispatcher::new(), form: yew_form::Form::::new(CreateUserModel::default()), error: None, - _task: None, + task: None, } } @@ -185,6 +185,7 @@ impl Component for CreateUserForm { Err(e) => { ConsoleService::error(&e.to_string()); self.error = Some(e); + self.task = None; true } Ok(b) => b, @@ -340,6 +341,7 @@ impl Component for CreateUserForm {
@@ -117,15 +119,15 @@ impl DeleteGroup { html! {