-
+
+
-
- "Loading..."}>
- {move || Suspend::new(async move{
- let wall: Option
-
+
+ "Loading..." }
+ }>
+ {move || Suspend::new(async move {
+ let wall: Option = wall.get().flatten();
+ wall.map(|wall| {
+ view! { }
+ })
+ })}
+
- }
+
+ }
}
#[component]
@@ -93,14 +80,33 @@ fn Ready(wall: models::Wall) -> impl leptos::IntoView {
tracing::debug!("ready");
let (current_problem, current_problem_writer) = signal(None::
);
- let problem_fetcher = LocalResource::new(move || async move {
- tracing::info!("Loading random problem");
- let problem = get_random_problem().await.expect("cannot get random problem");
- if problem.is_none() {
- tracing::info!("No problem returned by server in response to request for random problem");
- }
- current_problem_writer.set(problem.into_inner());
- });
+ let problem_fetcher = {
+ LocalResource::new(move || {
+ let wall_uid = wall.uid;
+ let problems = wall.problems.clone();
+
+ async move {
+ tracing::info!("Loading random problem");
+
+ // TODO: seed properly
+ use rand::seq::IteratorRandom;
+ let rng = &mut rand::rngs::StdRng::seed_from_u64(0);
+ let random_problem = problems.iter().choose(rng);
+
+ let problem = if let Some(random_problem) = random_problem {
+ crate::server_functions::get_problem(wall_uid, *random_problem)
+ .await
+ .expect("cannot get random problem")
+ .into_inner()
+ } else {
+ tracing::info!("Wall has no problems");
+ None
+ };
+
+ current_problem_writer.set(problem);
+ }
+ })
+ };
let mut cells = vec![];
for (&hold_position, hold) in &wall.holds {
@@ -117,17 +123,18 @@ fn Ready(wall: models::Wall) -> impl leptos::IntoView {
view! {
// Render the wall
-
{cells}
+
+ {cells}
+
-
- // TODO:
- //
{current_problem.read().as_ref().map(|p| p.name.clone())}
- //
{current_problem.read().as_ref().map(|p| p.set_by.clone())}
+
// TODO:
+ //
{current_problem.read().as_ref().map(|p| p.name.clone())}
+ //
{current_problem.read().as_ref().map(|p| p.set_by.clone())}
- div>
+
}
}
@@ -161,74 +168,3 @@ fn Hold(hold: models::Hold, #[prop(into)] role: Signal