mirror of
https://github.com/nitnelave/lldap.git
synced 2023-04-12 14:25:13 +00:00
new query for avatar
This commit is contained in:
parent
07aa010d10
commit
ed91e19b3e
5
app/queries/get_user_avatar.graphql
Normal file
5
app/queries/get_user_avatar.graphql
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
query GetUserAvatar($id: String!) {
|
||||||
|
user(userId: $id) {
|
||||||
|
avatar
|
||||||
|
}
|
||||||
|
}
|
@ -6,14 +6,13 @@ use yew::prelude::*;
|
|||||||
#[derive(GraphQLQuery)]
|
#[derive(GraphQLQuery)]
|
||||||
#[graphql(
|
#[graphql(
|
||||||
schema_path = "../schema.graphql",
|
schema_path = "../schema.graphql",
|
||||||
query_path = "queries/get_user_details.graphql",
|
query_path = "queries/get_user_avatar.graphql",
|
||||||
response_derives = "Debug, Hash, PartialEq, Eq, Clone",
|
response_derives = "Debug, Hash, PartialEq, Eq, Clone",
|
||||||
custom_scalars_module = "crate::infra::graphql"
|
custom_scalars_module = "crate::infra::graphql"
|
||||||
)]
|
)]
|
||||||
pub struct GetUserDetails;
|
pub struct GetUserAvatar;
|
||||||
|
|
||||||
pub type User = get_user_details::GetUserDetailsUser;
|
pub type User = get_user_avatar::GetUserAvatarUser;
|
||||||
pub type Group = get_user_details::GetUserDetailsUserGroups;
|
|
||||||
|
|
||||||
pub struct Avatar {
|
pub struct Avatar {
|
||||||
common: CommonComponentParts<Self>,
|
common: CommonComponentParts<Self>,
|
||||||
@ -26,7 +25,7 @@ pub struct Avatar {
|
|||||||
/// It starts out by fetching the user's details from the backend when loading.
|
/// It starts out by fetching the user's details from the backend when loading.
|
||||||
pub enum Msg {
|
pub enum Msg {
|
||||||
/// Received the user details response, either the user data or an error.
|
/// Received the user details response, either the user data or an error.
|
||||||
UserDetailsResponse(Result<get_user_details::ResponseData>),
|
UserAvatarResponse(Result<get_user_avatar::ResponseData>),
|
||||||
Update
|
Update
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,14 +39,14 @@ pub struct Props {
|
|||||||
impl CommonComponent<Avatar> for Avatar {
|
impl CommonComponent<Avatar> for Avatar {
|
||||||
fn handle_msg(&mut self, msg: <Self as Component>::Message) -> Result<bool> {
|
fn handle_msg(&mut self, msg: <Self as Component>::Message) -> Result<bool> {
|
||||||
match msg {
|
match msg {
|
||||||
Msg::UserDetailsResponse(response) => match response {
|
Msg::UserAvatarResponse(response) => match response {
|
||||||
Ok(user) => self.avatar = user.user.avatar,
|
Ok(user) => self.avatar = user.user.avatar,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
self.avatar = None;
|
self.avatar = None;
|
||||||
bail!("Error getting user details: {}", e);
|
bail!("Error getting user details: {}", e);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Msg::Update => self.get_user_details(),
|
Msg::Update => self.get_user_avatar(),
|
||||||
}
|
}
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
@ -58,14 +57,14 @@ impl CommonComponent<Avatar> for Avatar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Avatar {
|
impl Avatar {
|
||||||
fn get_user_details(&mut self) {
|
fn get_user_avatar(&mut self) {
|
||||||
if self.common.username.len() > 0 {
|
if self.common.username.len() > 0 {
|
||||||
self.common.call_graphql::<GetUserDetails, _>(
|
self.common.call_graphql::<GetUserAvatar, _>(
|
||||||
get_user_details::Variables {
|
get_user_avatar::Variables {
|
||||||
id: self.common.username.clone(),
|
id: self.common.username.clone(),
|
||||||
},
|
},
|
||||||
Msg::UserDetailsResponse,
|
Msg::UserAvatarResponse,
|
||||||
"Error trying to fetch user details",
|
"Error trying to fetch user avatar",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -80,7 +79,7 @@ impl Component for Avatar {
|
|||||||
common: CommonComponentParts::<Self>::create(props, link),
|
common: CommonComponentParts::<Self>::create(props, link),
|
||||||
avatar: None,
|
avatar: None,
|
||||||
};
|
};
|
||||||
avatar.get_user_details();
|
avatar.get_user_avatar();
|
||||||
avatar
|
avatar
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user