refactor(examples): shrink workout route wiring

Move workout interaction wiring behind an app-owned registry function and use typed form adapters so the runnable binary no longer carries repetitive per-handler closure boilerplate.

req: codegen/002

req: examples/001
This commit is contained in:
slhx agent
2026-06-11 21:44:11 +02:00
parent 5e4f02f419
commit d991addbb5
2 changed files with 60 additions and 67 deletions
+2 -49
View File
@@ -2,8 +2,7 @@ use axum::extract::State;
use axum::response::IntoResponse;
use axum::routing::get;
use axum::Router;
use hemx_axum::{interactions, runtime_js, runtime_js_path, EffectResponse, InteractionRequest};
use hemx_workout_example::ui::workout;
use hemx_axum::{runtime_js, runtime_js_path, EffectResponse, InteractionRequest};
use hemx_workout_example::{self as workout_app, AppState};
use std::net::SocketAddr;
use std::str::FromStr;
@@ -39,53 +38,7 @@ async fn interact(
State(state): State<AppState>,
request: InteractionRequest,
) -> Result<EffectResponse, impl IntoResponse> {
request
.dispatch_async(
interactions(hemx_workout_example::ui::BUILD_FINGERPRINT)
.on(workout::complete_set, {
let state = state.clone();
move |_| workout_app::complete_set(&state)
})
.on(workout::change_weight, {
let state = state.clone();
move |form| {
workout_app::change_weight(&state, form.parse::<f32>("kg").unwrap_or(0.0))
}
})
.on(workout::skip_exercise, {
let state = state.clone();
move |_| workout_app::skip_exercise(&state)
})
.on(workout::record_note, {
let state = state.clone();
move |form| {
workout_app::record_note(
&state,
form.value("text").unwrap_or("").to_owned(),
)
}
})
.on(workout::replay_export, {
let state = state.clone();
move |_| workout_app::replay_export(&state)
})
.on(workout::export_log, {
let state = state.clone();
move |_| workout_app::export_log(&state)
})
.on(workout::record_share_result, {
let state = state.clone();
move |_| workout_app::record_share_result(&state)
})
.on(workout::request_native_haptic, {
let state = state.clone();
move |_| workout_app::request_native_haptic(&state)
})
.on(workout::record_native_haptic_ack, move |_| {
workout_app::record_native_haptic_ack(&state)
}),
)
.await
request.dispatch_async(workout_app::registry(state)).await
}
async fn runtime() -> impl IntoResponse {