Created
February 2, 2022 21:20
-
-
Save autarch/f11d65da6cd63714a2cad2c0ba542673 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pub(crate) fn Artist(cx: Scope) -> Element { | |
| log::info!("Artist"); | |
| let route = use_route(&cx); | |
| // route.debug(); | |
| let artist_id = route | |
| .segment::<String>("artist_id") | |
| .expect("artist_id parameter was not found in path somehow") | |
| .expect("artist_id parameter could not be parsed as a String"); | |
| cx.render(rsx! { | |
| ArtistFromRoute { | |
| artist_id: artist_id, | |
| } | |
| }) | |
| } | |
| #[inline_props] | |
| fn ArtistFromRoute(cx: Scope, artist_id: String) -> Element { | |
| let artist = use_future(&cx, || { | |
| to_owned![artist_id]; | |
| let mut client = new_client( | |
| *cx.consume_context::<storage::Store>() | |
| .expect("Could not get Store from context"), | |
| ); | |
| log::info!("loading artist by id = {}", artist_id); | |
| async move { client.get_artist(&artist_id).await } | |
| }); | |
| cx.render(rsx! { | |
| match artist.value() { | |
| Some(Ok(response)) => { | |
| match &response.response_either { | |
| Some(get_artist_response::ResponseEither::Artist(artist)) => { | |
| let core = artist.core.as_ref().unwrap(); | |
| log::info!("loaded artist {}", core.display_name); | |
| rsx! { | |
| div { | |
| class: "text-center", | |
| PageTitle { | |
| "{core.display_name}" | |
| }, | |
| }, | |
| div { | |
| class: "flex flex-row flex-wrap place-content-center", | |
| artist.releases.iter().map(|r| rsx!{ | |
| OneRelease { | |
| key: "{r.release_id}", | |
| release: r, | |
| } | |
| }), | |
| }, | |
| } | |
| }, | |
| Some(get_artist_response::ResponseEither::Error(e)) => rsx! { | |
| UserFacingError { | |
| error: e | |
| } | |
| }, | |
| None => { | |
| log::error!("Empty response for GetArtist request!"); | |
| rsx! { | |
| "Error loading artist" | |
| } | |
| } | |
| } | |
| }, | |
| Some(Err(e)) => { | |
| log::error!("Error loading artist: {}", e); | |
| rsx! { | |
| "Error loading artist" | |
| } | |
| }, | |
| None => { | |
| rsx! { | |
| "Loading artist", | |
| } | |
| }, | |
| } | |
| }) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment