refactor: user interaction signal
This commit is contained in:
parent
9b15daaf6d
commit
98703f2c8b
@ -125,13 +125,7 @@ fn WithWall(
|
||||
});
|
||||
|
||||
let problem = crate::resources::problem_by_uid_optional(wall_uid, problem_uid.into());
|
||||
let user_interaction = Signal::derive(move || {
|
||||
let Some(problem_uid) = problem_uid.get() else {
|
||||
return None;
|
||||
};
|
||||
let user_interactions = user_interactions.read();
|
||||
user_interactions.get(&problem_uid).cloned()
|
||||
});
|
||||
let user_interaction = signals::user_interaction(user_interactions, problem_uid.into());
|
||||
|
||||
let fn_next_problem = move || {
|
||||
let problems = filtered_problems.read();
|
||||
@ -346,7 +340,6 @@ fn WithUserInteraction(
|
||||
let submit_attempt = ServerAction::<RonEncoded<server_functions::UpsertTodaysAttempt>>::new();
|
||||
let submit_attempt_value = submit_attempt.value();
|
||||
Effect::new(move || {
|
||||
tracing::info!("flaf");
|
||||
if let Some(Ok(v)) = submit_attempt_value.get() {
|
||||
tracing::info!("setting user interaction to action return value: {v:?}");
|
||||
user_interaction.set(Some(v.into_inner()));
|
||||
@ -532,6 +525,7 @@ fn Section(children: Children, #[prop(into)] title: MaybeProp<String>) -> impl I
|
||||
mod signals {
|
||||
use crate::models;
|
||||
use leptos::prelude::*;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
pub fn latest_attempt(user_interaction: Signal<Option<models::UserInteraction>>) -> Signal<Option<models::DatedAttempt>> {
|
||||
Signal::derive(move || user_interaction.read().as_ref().and_then(models::UserInteraction::latest_attempt))
|
||||
@ -540,4 +534,15 @@ mod signals {
|
||||
pub fn todays_attempt(latest_attempt: Signal<Option<models::UserInteraction>>) -> Signal<Option<models::Attempt>> {
|
||||
Signal::derive(move || latest_attempt.read().as_ref().and_then(models::UserInteraction::todays_attempt))
|
||||
}
|
||||
|
||||
pub fn user_interaction(
|
||||
user_interactions: Signal<BTreeMap<models::ProblemUid, models::UserInteraction>>,
|
||||
problem_uid: Signal<Option<models::ProblemUid>>,
|
||||
) -> Signal<Option<models::UserInteraction>> {
|
||||
Signal::derive(move || {
|
||||
let problem_uid = problem_uid.get()?;
|
||||
let user_interactions = user_interactions.read();
|
||||
user_interactions.get(&problem_uid).cloned()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user