use std::rc::Rc; use yew::prelude::*; pub fn loading(title: &str) -> Html where COMP: Component, { html!{
{ "Loading " } { title } { "..." }
} } pub fn load_error(title: &str, refresh: M, error: &str) -> Html where COMP: Component + Renderable, M: Fn() -> COMP::Message + 'static, { html!{
{ crate::uitools::icons::icon_refresh() } { "Loading " } { title } { " failed: " }{ error }
} } pub fn show(title: &str, data: Option>>, refresh: M, display: D) -> Html where COMP: Component + Renderable, M: Fn() -> COMP::Message + 'static, D: FnOnce(&T) -> Html, { if let Some(data) = data { match &*data { Ok(v) => display(v), Err(e) => load_error(title, refresh, e.as_str()), } } else { loading(title) } } pub fn show_with(title: &str, data: Option>>, refresh: M, display: D, display_fail: F) -> Html where COMP: Component + Renderable, M: Fn() -> COMP::Message + 'static, D: FnOnce(&T) -> Html, F: FnOnce(Html) -> Html, { if let Some(data) = data { match &*data { Ok(v) => display(v), Err(e) => display_fail(load_error(title, refresh, e.as_str())), } } else { display_fail(loading(title)) } }