diff --git a/crates/ascend/src/pages/wall.rs b/crates/ascend/src/pages/wall.rs index f2677b9..10543b7 100644 --- a/crates/ascend/src/pages/wall.rs +++ b/crates/ascend/src/pages/wall.rs @@ -1,13 +1,13 @@ -// +------------------------+ +// +----------- -----------+ // | Name: ... | // | Method: ... | // | Set by: ... | // | | // | | Flash | Top | Attempt | | // | | -// +-----------------------------+ +// +--------------- History --------------+ // | Today: | -// | | +// | 14 days ago: | // +--------------------------------------+ use crate::codec::ron::RonEncoded; @@ -47,56 +47,34 @@ pub fn Wall() -> impl IntoView { }); let wall = crate::resources::wall_by_uid(wall_uid); + let problem = crate::resources::problem_by_uid(wall_uid, problem_uid.into()); + let user_interaction = crate::resources::user_interaction(wall_uid, problem_uid.into()); - let problem_action = Action::new(move |&(wall_uid, problem_uid): &(models::WallUid, models::ProblemUid)| async move { - tracing::info!("fetching"); - crate::server_functions::get_problem(wall_uid, problem_uid) - .await - .map(RonEncoded::into_inner) - }); - let problem_signal = Signal::derive(move || { - let v = problem_action.value().read_only().get(); - v.and_then(Result::ok) - }); + // merge outer option (resource hasn't resolved yet) with inner option (there is no problem for the wall) + let problem_sig2 = Signal::derive(move || problem.get().transpose().map(Option::flatten)); let fn_next_problem = move |wall: &models::Wall| { set_problem_uid.set(wall.random_problem()); }; // Set a problem when wall is set (loaded) - Effect::new(move |_prev_value| { - problem_action.value().write_only().set(None); - - match &*wall.read() { - Some(Ok(wall)) => { - if problem_uid.get().is_none() { - tracing::debug!("Setting next problem"); - fn_next_problem(wall); - } + Effect::new(move |_prev_value| match &*wall.read() { + Some(Ok(wall)) => { + if problem_uid.get().is_none() { + tracing::debug!("Setting next problem"); + fn_next_problem(wall); } - Some(Err(err)) => { - tracing::error!("Error getting wall: {err}"); - } - None => {} } - }); - - // On change of problem UID, dispatch an action to fetch the problem - Effect::new(move |_prev_value| match problem_uid.get() { - Some(problem_uid) => { - problem_action.dispatch((wall_uid.get(), problem_uid)); - } - None => { - problem_action.value().write_only().set(None); + Some(Err(err)) => { + tracing::error!("Error getting wall: {err}"); } + None => {} }); let ui_is_flash = RwSignal::new(false); let ui_is_climbed = RwSignal::new(false); let ui_is_favorite = RwSignal::new(false); - let user_interaction = crate::resources::user_interaction(wall_uid, problem_uid.into()); - // On reception of user interaction state, set UI signals Effect::new(move |_prev_value| { if let Some(user_interaction) = user_interaction.get() { @@ -110,17 +88,6 @@ pub fn Wall() -> impl IntoView { } }); - let attempt_suspend = Suspend::new(async move { - let user_interaction = user_interaction.await; - let user_interaction = user_interaction.ok().flatten(); - let best_attempt = user_interaction.and_then(|x| x.best_attempt()); - - let best_attempt_date = move || best_attempt.map(|pair| pair.0); - let best_attempt_attempt = move || best_attempt.map(|pair| pair.1); - - view! { } - }); - let header_items = move || HeaderItems { left: vec![], middle: vec![HeaderItem { @@ -144,17 +111,34 @@ pub fn Wall() -> impl IntoView {
- "Loading..."

} - }> + {move || Suspend::new(async move { - tracing::info!("executing Suspend future"); + tracing::info!("executing main suspend"); let wall = wall.await?; + let grid = { + let wall = wall.clone(); + view! { + + { + let wall = wall.clone(); + move || { + let wall = wall.clone(); + Suspend::new(async move { + let wall = wall.clone(); + tracing::info!("executing grid suspend"); + let view = view! { + + }; + Ok::<_, ServerFnError>(view) + }) + } + } + + } + }; let v = view! {
-
- -
+
{grid}