From a6942156e412bdd3b1704e028db5e99688cb6d72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asger=20Juul=20Brunsh=C3=B8j?= Date: Thu, 20 Feb 2025 22:28:55 +0100 Subject: [PATCH] fix routes page --- crates/ascend/src/components/problem.rs | 11 +++- crates/ascend/src/components/problem_info.rs | 29 +++++++++ crates/ascend/src/lib.rs | 3 + crates/ascend/src/models.rs | 1 - crates/ascend/src/pages/routes.rs | 53 ++++------------ crates/ascend/src/pages/settings.rs | 63 ++++++++++++++++++++ crates/ascend/src/pages/wall.rs | 28 +-------- todo.md | 6 +- 8 files changed, 120 insertions(+), 74 deletions(-) create mode 100644 crates/ascend/src/components/problem_info.rs create mode 100644 crates/ascend/src/pages/settings.rs diff --git a/crates/ascend/src/components/problem.rs b/crates/ascend/src/components/problem.rs index dd462c6..d4236b6 100644 --- a/crates/ascend/src/components/problem.rs +++ b/crates/ascend/src/components/problem.rs @@ -2,9 +2,18 @@ use crate::models::HoldRole; use crate::models::{self}; use leptos::prelude::*; +/// Displays a grid of the problem #[component] #[tracing::instrument(skip_all)] -pub fn Problem(#[prop(into)] dim: Signal, #[prop(into)] problem: Signal) -> impl IntoView { +pub fn Problem( + /// Wall dimensions + #[prop(into)] + dim: Signal, + + /// Problem (route) + #[prop(into)] + problem: Signal, +) -> impl IntoView { let holds = move || { let mut holds = vec![]; for row in 0..dim.get().rows { diff --git a/crates/ascend/src/components/problem_info.rs b/crates/ascend/src/components/problem_info.rs new file mode 100644 index 0000000..4edb45d --- /dev/null +++ b/crates/ascend/src/components/problem_info.rs @@ -0,0 +1,29 @@ +use crate::models; +use leptos::prelude::*; + +#[component] +#[tracing::instrument(skip_all)] +pub fn ProblemInfo(problem: models::Problem) -> impl IntoView { + tracing::trace!("Enter problem info"); + + let name = problem.name; + let set_by = problem.set_by; + let method = problem.method; + + view! { +
+ + + +
+ } +} + +#[component] +#[tracing::instrument(skip_all)] +fn NameValue(#[prop(into)] name: String, #[prop(into)] value: String) -> impl IntoView { + view! { +

{name}

+

{value}

+ } +} diff --git a/crates/ascend/src/lib.rs b/crates/ascend/src/lib.rs index 857e4ea..c3763a9 100644 --- a/crates/ascend/src/lib.rs +++ b/crates/ascend/src/lib.rs @@ -2,16 +2,19 @@ pub mod app; pub mod pages { pub mod edit_wall; pub mod routes; + pub mod settings; pub mod wall; } pub mod components { pub use button::Button; pub use header::StyledHeader; pub use problem::Problem; + pub use problem_info::ProblemInfo; pub mod button; pub mod header; pub mod problem; + pub mod problem_info; } pub mod resources { use crate::codec::ron::Ron; diff --git a/crates/ascend/src/models.rs b/crates/ascend/src/models.rs index 124d855..68146bd 100644 --- a/crates/ascend/src/models.rs +++ b/crates/ascend/src/models.rs @@ -22,7 +22,6 @@ pub mod v2 { use serde::Serialize; use std::collections::BTreeMap; use std::collections::BTreeSet; - use std::fmt::Display; #[derive(Serialize, Deserialize, Debug)] pub struct Root { diff --git a/crates/ascend/src/pages/routes.rs b/crates/ascend/src/pages/routes.rs index 4d8b4e7..86a6e11 100644 --- a/crates/ascend/src/pages/routes.rs +++ b/crates/ascend/src/pages/routes.rs @@ -37,7 +37,7 @@ pub fn Routes() -> impl IntoView { link: Some("/".to_string()), }], middle: vec![HeaderItem { - text: "ROUTES".to_string(), + text: "Routes".to_string(), link: None, }], right: vec![], @@ -64,7 +64,7 @@ pub fn Routes() -> impl IntoView { each=problems_sample key=|problem| problem.uid children=move |problem: models::Problem| { - view! { } + view! {
} } /> @@ -76,11 +76,10 @@ pub fn Routes() -> impl IntoView { }; view! { -
+
-
- {move || view! { }} +
"loading"

}>{suspend}
@@ -90,44 +89,12 @@ pub fn Routes() -> impl IntoView { #[component] #[tracing::instrument(skip_all)] fn Problem(#[prop(into)] dim: Signal, #[prop(into)] problem: Signal) -> impl IntoView { - tracing::debug!("Enter"); - view! { - -

{move || problem.get().name.clone()}

+
+
+ +
+ +
} } - -#[component] -#[tracing::instrument(skip_all)] -fn Import(wall_uid: WallUid) -> impl IntoView { - tracing::debug!("ready"); - - let import_from_mini_moonboard = Action::from(ServerAction::::new()); - - let onclick = move |_mouse_event| { - import_from_mini_moonboard.dispatch(ImportFromMiniMoonboard { wall_uid }); - }; - - view! { -

"Import problems from"

- - } -} - -#[server(name = ImportFromMiniMoonboard)] -#[tracing::instrument] -async fn import_from_mini_moonboard(wall_uid: WallUid) -> Result<(), ServerFnError> { - use crate::server::config::Config; - use crate::server::db::Database; - - tracing::info!("Importing mini moonboard problems"); - - let config = expect_context::(); - let db = expect_context::(); - - crate::server::operations::import_mini_moonboard_problems(&config, db, wall_uid).await?; - - // TODO: Return information about what was done - Ok(()) -} diff --git a/crates/ascend/src/pages/settings.rs b/crates/ascend/src/pages/settings.rs new file mode 100644 index 0000000..f12bd3a --- /dev/null +++ b/crates/ascend/src/pages/settings.rs @@ -0,0 +1,63 @@ +use crate::components::StyledHeader; +use crate::components::header::HeaderItem; +use crate::components::header::HeaderItems; +use crate::models::WallUid; +use leptos::prelude::*; + +#[component] +#[tracing::instrument(skip_all)] +pub fn Settings() -> impl IntoView { + let header_items = HeaderItems { + left: vec![HeaderItem { + text: "← Ascend".to_string(), + link: Some("/".to_string()), + }], + middle: vec![HeaderItem { + text: "Settings".to_string(), + link: None, + }], + right: vec![], + }; + + view! { +
+ + +
+ // {move || view! { }} +
+
+ } +} + +#[component] +#[tracing::instrument(skip_all)] +fn Import(wall_uid: WallUid) -> impl IntoView { + let import_from_mini_moonboard = Action::from(ServerAction::::new()); + + let onclick = move |_mouse_event| { + import_from_mini_moonboard.dispatch(ImportFromMiniMoonboard { wall_uid }); + }; + + view! { +

"Import problems from"

+ + } +} + +#[server(name = ImportFromMiniMoonboard)] +#[tracing::instrument] +async fn import_from_mini_moonboard(wall_uid: WallUid) -> Result<(), ServerFnError> { + use crate::server::config::Config; + use crate::server::db::Database; + + tracing::info!("Importing mini moonboard problems"); + + let config = expect_context::(); + let db = expect_context::(); + + crate::server::operations::import_mini_moonboard_problems(&config, db, wall_uid).await?; + + // TODO: Return information about what was done + Ok(()) +} diff --git a/crates/ascend/src/pages/wall.rs b/crates/ascend/src/pages/wall.rs index 2bdc103..22b6c02 100644 --- a/crates/ascend/src/pages/wall.rs +++ b/crates/ascend/src/pages/wall.rs @@ -1,6 +1,7 @@ // TODO: Put current problem UID in url use crate::codec::ron::RonEncoded; +use crate::components::ProblemInfo; use crate::components::button::Button; use crate::components::header::HeaderItem; use crate::components::header::HeaderItems; @@ -168,30 +169,3 @@ fn Hold(hold: models::Hold, role: Signal>) -> impl IntoView { tracing::trace!("view"); view! {
{img}
} } - -#[component] -#[tracing::instrument(skip_all)] -fn ProblemInfo(problem: models::Problem) -> impl IntoView { - tracing::trace!("Enter problem info"); - - let name = problem.name; - let set_by = problem.set_by; - let method = problem.method; - - view! { -
- - - -
- } -} - -#[component] -#[tracing::instrument(skip_all)] -fn NameValue(#[prop(into)] name: String, #[prop(into)] value: String) -> impl IntoView { - view! { -

{name}

-

{value}

- } -} diff --git a/todo.md b/todo.md index b048e86..a5c316d 100644 --- a/todo.md +++ b/todo.md @@ -1,5 +1,3 @@ -- save images with a uuid -- downscale images - associate routes with wall - group routes by pattern (pattern family has shift/mirror variations) - generate pattern families of variations when importing problems @@ -10,3 +8,7 @@ - use wall id in URL. - decide on routes vs problems terminology - decide on holds vs wall-edit terminology +- clock +- hotkeys (enter =next problem, arrow = shift left/right up/down) +- remove brightness reduction when mousing over holds +- impl `sizes` hint next to `srcset`