From 3b232b048d0b64efc72e8516b762ccfea2611d7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asger=20Juul=20Brunsh=C3=B8j?= Date: Wed, 5 Mar 2025 22:50:08 +0100 Subject: [PATCH] wip --- crates/ascend/src/components/attempt.rs | 44 +++++-- crates/ascend/src/components/button.rs | 8 +- crates/ascend/src/components/outlined_box.rs | 4 +- crates/ascend/src/components/problem_info.rs | 6 +- crates/ascend/src/pages/wall.rs | 132 ++++++++++++------- 5 files changed, 131 insertions(+), 63 deletions(-) diff --git a/crates/ascend/src/components/attempt.rs b/crates/ascend/src/components/attempt.rs index 5b35760..f46983c 100644 --- a/crates/ascend/src/components/attempt.rs +++ b/crates/ascend/src/components/attempt.rs @@ -4,27 +4,55 @@ use leptos::prelude::*; #[component] #[tracing::instrument(skip_all)] -pub fn Attempt(#[prop(into)] attempt: Signal>) -> impl IntoView { +pub fn Attempt(#[prop(into)] date: Signal>, #[prop(into)] attempt: Signal>) -> impl IntoView { tracing::trace!("Enter"); + let s = time_ago(date.get()); + let text = move || match attempt.get() { - Some(models::Attempt::Attempt) => "Learning experience", - Some(models::Attempt::Send) => "Send", Some(models::Attempt::Flash) => "Flash", + Some(models::Attempt::Send) => "Send", + Some(models::Attempt::Attempt) => "Learning experience", None => "No attempt", }; + let text_color = match attempt.get() { + Some(models::Attempt::Flash) => "text-cyan-500", + Some(models::Attempt::Send) => "text-teal-500", + Some(models::Attempt::Attempt) => "text-pink-500", + None => "", + }; + let icon = move || match attempt.get() { - Some(models::Attempt::Attempt) => view! { }.into_any(), - Some(models::Attempt::Send) => view! { }.into_any(), Some(models::Attempt::Flash) => view! { }.into_any(), + Some(models::Attempt::Send) => view! { }.into_any(), + Some(models::Attempt::Attempt) => view! { }.into_any(), None => view! { }.into_any(), }; + let classes = format!("flex flex-row gap-3 {}", text_color); + view! { -
- {icon} - {text} +
+
{s}
+ +
+ {text} + {icon} +
} } + +fn time_ago(dt: chrono::DateTime) -> String { + let now = chrono::Utc::now(); + let duration = now.signed_duration_since(dt); + + if duration.num_days() == 0 { + "Today".to_string() + } else if duration.num_days() == 1 { + "1 day ago".to_string() + } else { + format!("{} days ago", duration.num_days()) + } +} diff --git a/crates/ascend/src/components/button.rs b/crates/ascend/src/components/button.rs index 53837a7..2d61763 100644 --- a/crates/ascend/src/components/button.rs +++ b/crates/ascend/src/components/button.rs @@ -20,7 +20,7 @@ pub fn Button( let icon_view = icon.get().map(|i| { let icon_view = i.into_view(); - let mut classes = "self-center rounded-sm".to_string(); + let mut classes = "self-center".to_string(); classes.push(' '); classes.push_str(margin); classes.push(' '); @@ -48,11 +48,7 @@ pub fn Button( }; view! { -
+
+ + {move || Suspend::new(async move { + tracing::info!("executing probleminfo suspend"); + let problem = problem.await?; + let view = problem + .map(|problem| { + view! { } + }); + Ok::<_, ServerFnError>(view) + })} + +
+ + + impl IntoView { - - {move || Suspend::new(async move { - tracing::info!("executing probleminfo suspend"); - let problem = problem.await?; - let problem_view = problem - .map(|problem| view! { }); - let view = view! { {problem_view} }; - Ok::<_, ServerFnError>(view) - })} - - - - - - {move || { - let x = 10; - 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! { - - } - }); - attempt_suspend - }} - + {foo()} }; @@ -274,7 +306,7 @@ fn AttemptRadio( tracing::debug!("Enter"); view! { -
+