This commit is contained in:
Asger Juul Brunshøj 2025-03-24 23:08:15 +01:00
parent f1be2dd735
commit 58698a1087

View File

@ -70,6 +70,7 @@ pub fn Wall() -> impl IntoView {
let wall = wall.await?;
let problems = problems.await?;
let user_interactions = user_interactions.await?;
let user_interactions = RwSignal::new(user_interactions);
let v = view! { <WithWall wall problems user_interactions /> };
Ok::<_, ServerFnError>(v)
})}
@ -92,7 +93,7 @@ fn WithProblem(#[prop(into)] problem: Signal<models::Problem>) -> impl IntoView
fn WithWall(
#[prop(into)] wall: Signal<models::Wall>,
#[prop(into)] problems: Signal<BTreeMap<models::ProblemUid, models::Problem>>,
#[prop(into)] user_interactions: Signal<BTreeMap<models::ProblemUid, models::UserInteraction>>,
#[prop(into)] user_interactions: RwSignal<BTreeMap<models::ProblemUid, models::UserInteraction>>,
) -> impl IntoView {
tracing::trace!("Enter");
@ -100,8 +101,21 @@ fn WithWall(
let (problem_uid, set_problem_uid) = leptos_router::hooks::query_signal::<models::ProblemUid>("problem");
let submit_attempt = ServerAction::<RonEncoded<server_functions::UpsertTodaysAttempt>>::new();
Effect::new(move || {
if let Some(Ok(v)) = submit_attempt.value().get() {
let v = v.into_inner();
user_interactions.update(|map| {
map.insert(v.problem_uid, v);
});
}
});
let submit_attempt_cb = StoredValue::new(move |attempt: server_functions::UpsertTodaysAttempt| {
submit_attempt.dispatch(RonEncoded(attempt));
});
let problem = signals::problem(problems, problem_uid.into());
let user_interaction = signals::user_interaction(user_interactions, problem_uid.into());
let user_interaction = signals::user_interaction(user_interactions.into(), problem_uid.into());
// Filter
let (filter_holds, set_filter_holds) = signal(BTreeSet::new());
@ -154,16 +168,9 @@ fn WithWall(
});
};
let grid = view! {
<Transition fallback=|| ()>
{move || {
Suspend::new(async move {
tracing::debug!("executing grid suspend");
let view = view! { <Grid wall=wall.get() problem on_click_hold /> };
Ok::<_, ServerFnError>(view)
})
}}
</Transition>
let grid = move || {
let wall = wall.get();
view! { <Grid wall problem on_click_hold /> }
};
let filter = move || {
@ -295,7 +302,14 @@ fn WithWall(
let Some(problem_uid) = problem_uid.get() else {
return view! {}.into_any();
};
view! { <WithUserInteraction wall_uid problem_uid user_interaction /> }
view! {
<WithUserInteraction
wall_uid
problem_uid
user_interaction
submit_attempt=submit_attempt_cb
/>
}
.into_any()
}}
</div>
@ -309,39 +323,22 @@ fn WithUserInteraction(
#[prop(into)] wall_uid: Signal<models::WallUid>,
#[prop(into)] problem_uid: Signal<models::ProblemUid>,
#[prop(into)] user_interaction: Signal<Option<models::UserInteraction>>,
submit_attempt: StoredValue<impl Fn(server_functions::UpsertTodaysAttempt) + Sync + Send + 'static>,
) -> impl IntoView {
tracing::debug!("Enter WithUserInteraction");
let parent_user_interaction = user_interaction;
let user_interaction = RwSignal::new(None);
Effect::new(move || {
let i = parent_user_interaction.get();
tracing::info!("setting user interaction to parent user interaction value: {i:?}");
user_interaction.set(i);
});
let submit_attempt = ServerAction::<RonEncoded<server_functions::UpsertTodaysAttempt>>::new();
let submit_attempt_value = submit_attempt.value();
Effect::new(move || {
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()));
}
});
let todays_attempt = signals::todays_attempt(user_interaction.into());
let todays_attempt = signals::todays_attempt(user_interaction);
let mut attempt_radio_buttons = vec![];
for variant in [models::Attempt::Flash, models::Attempt::Send, models::Attempt::Attempt] {
let ui_toggle = Signal::derive(move || todays_attempt.get() == Some(variant));
let onclick = move |_| {
let attempt = if ui_toggle.get() { None } else { Some(variant) };
submit_attempt.dispatch(RonEncoded(server_functions::UpsertTodaysAttempt {
submit_attempt.read_value()(server_functions::UpsertTodaysAttempt {
wall_uid: wall_uid.get(),
problem_uid: problem_uid.get(),
attempt,
}));
});
};
attempt_radio_buttons.push(view! { <AttemptRadioButton on:click=onclick variant selected=ui_toggle /> });
}