diff --git a/crates/ascend/src/app.rs b/crates/ascend/src/app.rs index b5d0f2f..6d170e4 100644 --- a/crates/ascend/src/app.rs +++ b/crates/ascend/src/app.rs @@ -25,7 +25,7 @@ pub fn shell(options: LeptosOptions) -> impl IntoView { } #[component] -pub fn App() -> impl leptos::IntoView { +pub fn App() -> impl IntoView { use leptos_meta::Stylesheet; use leptos_meta::Title; @@ -51,7 +51,7 @@ pub fn App() -> impl leptos::IntoView { } #[component] -pub fn Home() -> impl leptos::IntoView { +pub fn Home() -> impl IntoView { // TODO: show cards with walls, and a "new wall" button tracing::debug!("Rendering home component"); diff --git a/crates/ascend/src/lib.rs b/crates/ascend/src/lib.rs index 367b51e..857e4ea 100644 --- a/crates/ascend/src/lib.rs +++ b/crates/ascend/src/lib.rs @@ -67,6 +67,11 @@ pub fn hydrate() { console_error_panic_hook::set_once(); tracing_subscriber::fmt() + .with_env_filter( + tracing_subscriber::EnvFilter::builder() + .with_default_directive(tracing::level_filters::LevelFilter::DEBUG.into()) + .from_env_lossy(), + ) .with_writer( // To avoide trace events in the browser from showing their JS backtrace tracing_subscriber_wasm::MakeConsoleWriter::default().map_trace_level_to(tracing::Level::DEBUG), diff --git a/crates/ascend/src/pages/edit_wall.rs b/crates/ascend/src/pages/edit_wall.rs index 0459c78..eed742a 100644 --- a/crates/ascend/src/pages/edit_wall.rs +++ b/crates/ascend/src/pages/edit_wall.rs @@ -21,7 +21,7 @@ struct RouteParams { } #[component] -pub fn EditWall() -> impl leptos::IntoView { +pub fn EditWall() -> impl IntoView { let params = leptos_router::hooks::use_params::(); let wall_uid = Signal::derive(move || { params @@ -73,7 +73,7 @@ pub fn EditWall() -> impl leptos::IntoView { } #[component] -fn Ready(wall: models::Wall) -> impl leptos::IntoView { +fn Ready(wall: models::Wall) -> impl IntoView { tracing::debug!("ready"); let mut holds = vec![]; @@ -92,7 +92,7 @@ fn Ready(wall: models::Wall) -> impl leptos::IntoView { } #[component] -fn Hold(hold: models::Hold) -> impl leptos::IntoView { +fn Hold(hold: models::Hold) -> impl IntoView { let hold_position = hold.position; let file_input_ref = NodeRef::::new(); diff --git a/crates/ascend/src/pages/routes.rs b/crates/ascend/src/pages/routes.rs index 4e6e68a..4d8b4e7 100644 --- a/crates/ascend/src/pages/routes.rs +++ b/crates/ascend/src/pages/routes.rs @@ -16,7 +16,7 @@ struct RouteParams { #[component] #[tracing::instrument(skip_all)] -pub fn Routes() -> impl leptos::IntoView { +pub fn Routes() -> impl IntoView { tracing::debug!("Enter"); let params = leptos_router::hooks::use_params::(); diff --git a/crates/ascend/src/pages/wall.rs b/crates/ascend/src/pages/wall.rs index b72d47b..a9e5ca3 100644 --- a/crates/ascend/src/pages/wall.rs +++ b/crates/ascend/src/pages/wall.rs @@ -1,4 +1,3 @@ -use crate::codec::ron::Ron; use crate::codec::ron::RonEncoded; use crate::components::button::Button; use crate::components::header::HeaderItem; @@ -31,34 +30,31 @@ pub fn Wall() -> impl IntoView { let wall = crate::resources::wall_by_uid(wall_uid); - let (problem_uid, set_problem_uid) = signal(None); - - let mut init_problem = false; - Effect::new(move || { - if !init_problem { - if let Some(Ok(wall)) = &*wall.read() { - set_problem_uid.set(wall.random_problem()); - init_problem = true; - } - } + 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(); + tracing::debug!("val: {:?}", v); + v.and_then(Result::ok) }); - let problem: Resource, Ron> = Resource::new_with_options( - move || (wall_uid.get(), problem_uid.get()), - move |(wall_uid, problem_uid)| async move { - let Some(problem_uid) = problem_uid else { - return None; - }; - crate::server_functions::get_problem(wall_uid, problem_uid) - .await - .map(RonEncoded::into_inner) - .inspect_err(|err| { - tracing::error!("{err}"); - }) - .ok() - }, - false, - ); + Effect::new(move |_prev_value| { + problem_action.value().write_only().set(None); + match wall.get() { + Some(Ok(wall)) => { + if let Some(problem_uid) = wall.random_problem() { + tracing::debug!("dispatching from effect"); + problem_action.dispatch((wall.uid, problem_uid)); + } + } + Some(Err(_err)) => {} + None => {} + } + }); let header_items = move || HeaderItems { left: vec![], @@ -83,59 +79,34 @@ pub fn Wall() -> impl IntoView {
- "Loading..."

} - }> + "Loading..."

} > {move || Suspend::new(async move { - let wall = wall.await; - let problem = problem.await; + tracing::info!("executing Suspend future"); + let wall = wall.await?; - wall.map(move |wall| { - let mut cells = vec![]; - for (&hold_position, hold) in &wall.holds { - let problem = problem.clone(); - let role = move || { - problem - .clone() - .and_then(|problem| { - problem.holds.get(&hold_position).copied() - }) - }; - let role = Signal::derive(role); - let cell = view! { }; - cells.push(cell); - } - let grid_classes = format!( - "grid grid-rows-{} grid-cols-{} gap-3", - wall.rows, - wall.cols, - ); - view! { -
- // Render the wall -
- {cells} -
+ let v = view! { +
+ +
- // TODO: - //

{current_problem.read().as_ref().map(|p| p.name.clone())}

- //

{current_problem.read().as_ref().map(|p| p.set_by.clone())}

-
- -
+ +
- } - }) +
+ }; + Ok::<_, ServerFnError>(v) })}
@@ -145,7 +116,30 @@ pub fn Wall() -> impl IntoView { #[component] #[tracing::instrument(skip_all)] -fn Hold(hold: models::Hold, #[prop(into)] role: Signal>) -> impl leptos::IntoView { +fn Grid(wall: models::Wall, problem: Signal>) -> impl IntoView { + tracing::debug!("Enter"); + + let mut cells = vec![]; + for (&hold_position, hold) in &wall.holds { + let role = move || problem.get().and_then(|p| p.holds.get(&hold_position).copied()); + let role = Signal::derive(role); + let cell = view! { }; + cells.push(cell); + } + let grid_classes = format!("grid grid-rows-{} grid-cols-{} gap-3", wall.rows, wall.cols,); + + view! { +
+
+ {cells} +
+
+ } +} + +#[component] +#[tracing::instrument(skip_all)] +fn Hold(hold: models::Hold, role: Signal>) -> impl IntoView { tracing::trace!("Enter"); let class = move || { let role_classes = match role.get() { diff --git a/crates/ascend/src/server.rs b/crates/ascend/src/server.rs index 81d4bae..a870fab 100644 --- a/crates/ascend/src/server.rs +++ b/crates/ascend/src/server.rs @@ -63,7 +63,6 @@ async fn serve(cli: Cli) -> Result<(), Error> { let leptos_options = leptos_conf_file.leptos_options; let addr = leptos_options.site_addr; let routes = generate_route_list(App); - dbg!(&routes); let config = load_config(cli)?; diff --git a/justfile b/justfile index c386f3c..023d662 100644 --- a/justfile +++ b/justfile @@ -9,7 +9,7 @@ fmt: bc-fmt serve: - RUST_LOG=debug RUST_BACKTRACE=1 cargo leptos watch -- serve + RUST_BACKTRACE=1 cargo leptos watch -- serve build-release: rm -rf dist