use super::error_provider::ErrorContext; use yew::prelude::*; pub enum Msg { ErrorContextUpdated(ErrorContext), HideError, } pub struct ErrorComponent { error: Option, _context_listener: ContextHandle, } impl Component for ErrorComponent { type Message = Msg; type Properties = (); fn create(ctx: &Context) -> Self { let (error_context, context_listener) = ctx .link() .context(ctx.link().callback(Msg::ErrorContextUpdated)) .expect("No Error Context Provided"); Self { error: error_context.value.clone(), _context_listener: context_listener, } } fn update(&mut self, _ctx: &Context, msg: Self::Message) -> bool { match msg { Msg::ErrorContextUpdated(error_context) => { self.error = error_context.value.clone(); true } Msg::HideError => { self.error = None; true } } } fn view(&self, ctx: &Context) -> Html { let onclick_hide = ctx.link().callback(|_| Msg::HideError); html! {
{ self.view_error(onclick_hide) }
} } } impl ErrorComponent { fn view_error(&self, onclick_hide: Callback) -> Html { match &self.error { Some(error_msg) => { html! { <>
{"Error"}

{ error_msg }


} } None => html! {}, } } }