use crate::infra::functional::{use_graphql_call, LoadableResult}; use graphql_client::GraphQLQuery; use yew::{function_component, html, virtual_dom::AttrValue, Properties}; #[derive(GraphQLQuery)] #[graphql( schema_path = "../schema.graphql", query_path = "queries/get_user_details.graphql", variables_derives = "Clone,PartialEq,Eq", response_derives = "Debug, Hash, PartialEq, Eq, Clone", custom_scalars_module = "crate::infra::graphql" )] pub struct GetUserDetails; #[derive(Properties, PartialEq)] pub struct Props { pub user: AttrValue, #[prop_or(32)] pub width: i32, #[prop_or(32)] pub height: i32, } #[function_component(Avatar)] pub fn avatar(props: &Props) -> Html { let user_details = use_graphql_call::(get_user_details::Variables { id: props.user.to_string(), }); match &(*user_details) { LoadableResult::Loaded(Ok(response)) => { let avatar = response.user.avatar.clone(); match &avatar { Some(data) => html! { Avatar }, None => html! { }, } } LoadableResult::Loaded(Err(error)) => html! { }, LoadableResult::Loading => html! { }, } } #[derive(Properties, PartialEq)] struct BlankAvatarDisplayProps { #[prop_or(None)] pub error: Option, pub width: i32, pub height: i32, } #[function_component(BlankAvatarDisplay)] fn blank_avatar_display(props: &BlankAvatarDisplayProps) -> Html { let fill = match &props.error { Some(_) => "red", None => "currentColor", }; html! { {props.error.clone().unwrap_or(AttrValue::Static("Avatar"))} } }