snapped async fn

This commit is contained in:
LinlyBoi
2022-12-25 10:10:50 +02:00
parent f1aeeed085
commit 523bae94f2
2 changed files with 29 additions and 9 deletions

View File

@@ -121,14 +121,15 @@ impl Component for RandomCommit {
}
//Generate Struct and implement component for driver using CommonDriver
struct Driver {
driver: FetchState<CommonDriver>,
driver: FetchState<String>,
}
//implement the component for Driver using a string
impl Component for Driver {
type Message = Msg<CommonDriver>;
type Message = Msg<String>;
type Properties = ();
fn create(_ctx: &Context<Self>) -> Self {
Self {
driver: FetchState::NotFetching, //Default state is not fetching anything
driver: FetchState::NotFetching,
}
}
@@ -164,12 +165,11 @@ impl Component for Driver {
}
fn view(&self, ctx: &Context<Self>) -> Html {
//render the component into HTML
match &self.driver {
FetchState::NotFetching => html! {
<>
<button onclick={ctx.link().callback(|_| Msg::GetData)}>
{ "Get driver info" }
{ "Get driver" }
</button>
<button onclick={ctx.link().callback(|_| Msg::GetError)}>
{ "Get using incorrect URL" }
@@ -177,10 +177,7 @@ impl Component for Driver {
</>
},
FetchState::Fetching => html! { "Fetching" },
FetchState::Success(data) => match data.clone().use_it() {
Ok(html) => html,
Err(err) => html! { err },
},
FetchState::Success(data) => html! { <p> {data} </p> },
FetchState::Failed(err) => html! { err },
}
}