Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extract view of spinner and error to share between pages #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions src/pages/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,9 @@ impl Component for Home {
.collect();

if !self.state.get_products_loaded {
html! {
<div class="loading_spinner_container">
<div class="loading_spinner"></div>
<div class="loading_spinner_text">{"Loading ..."}</div>
</div>
}
super::spinner()
} else if let Some(_) = self.state.get_products_error {
html! {
<div>
<span>{"Error loading products! :("}</span>
</div>
}
super::error("Error loading products! :(")
} else {
html! {
<div class="product_card_list">{products}</div>
Expand Down
19 changes: 19 additions & 0 deletions src/pages/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
use yew::prelude::*;

mod home;
mod product_detail;

pub use home::Home;
pub use product_detail::ProductDetail;

fn spinner() -> Html {
html! {
<div class="loading_spinner_container">
<div class="loading_spinner"></div>
<div class="loading_spinner_text">{"Loading ..."}</div>
</div>
}
}

fn error(error: &str) -> Html {
html! {
<div>
<span>{error}</span>
</div>
}
}
13 changes: 2 additions & 11 deletions src/pages/product_detail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,9 @@ impl Component for ProductDetail {
</div>
}
} else if !self.state.get_product_loaded {
html! {
<div class="loading_spinner_container">
<div class="loading_spinner"></div>
<div class="loading_spinner_text">{"Loading ..."}</div>
</div>
}
super::spinner()
} else {
html! {
<div>
<span>{"Error loading product! :("}</span>
</div>
}
super::error("Error loading product! :(")
}
}
}