fix: type signatures for the state passing.

This commit is contained in:
Jeremy Wall 2024-02-07 07:10:12 -06:00
parent bb856bb464
commit 4d2524efdc
2 changed files with 15 additions and 6 deletions

View File

@ -66,7 +66,7 @@ async fn main() -> anyhow::Result<()> {
.nest("/api", routes::mk_api_routes(config.clone())) .nest("/api", routes::mk_api_routes(config.clone()))
// HTMX ui component endpoints // HTMX ui component endpoints
.nest("/ui", routes::mk_ui_routes(config.clone())) .nest("/ui", routes::mk_ui_routes(config.clone()))
.route("/", get(routes::index).with_state(config.clone())) .route("/", get(routes::index).with_state(State(config.clone())))
.layer(TraceLayer::new_for_http()) .layer(TraceLayer::new_for_http())
.with_state(State(config.clone())); .with_state(State(config.clone()));
let socket_addr = args.listen.unwrap_or("127.0.0.1:3000".to_string()); let socket_addr = args.listen.unwrap_or("127.0.0.1:3000".to_string());

View File

@ -58,11 +58,20 @@ pub fn mk_api_routes(config: Arc<Vec<Dashboard>>) -> Router<Config> {
) )
} }
pub fn mk_ui_routes(config: Arc<Vec<Dashboard>>) -> Router<Config> { pub async fn dash_ui(State(config): State<Config>, Path(idx): Path<usize>) -> Markup {
Router::new() html!(
"TODO(jwall): Fill this in"
)
} }
pub async fn index(State(config): Config) -> Markup { pub fn mk_ui_routes(config: Arc<Vec<Dashboard>>) -> Router<Config> {
Router::new().route(
"/dash/:idx",
get(dash_ui).with_state(State(config))
)
}
pub async fn index(State(config): State<Config>) -> Markup {
html! { html! {
html { html {
head { head {
@ -76,7 +85,7 @@ pub async fn index(State(config): Config) -> Markup {
} }
} }
pub async fn app(State(config): Config) -> Markup { pub async fn app(State(config): State<Config>) -> Markup {
let titles = config let titles = config
.iter() .iter()
.map(|d| d.title.clone()) .map(|d| d.title.clone())
@ -87,7 +96,7 @@ pub async fn app(State(config): Config) -> Markup {
// Header menu // Header menu
ul { ul {
@for title in &titles { @for title in &titles {
li hx-get=(format!("/ui/dash/{}/", title.0)) hx-target="#dashboard" { (title.1) } li hx-get=(format!("/ui/dash/{}", title.0)) hx-target="#dashboard" { (title.1) }
} }
} }
// dashboard display // dashboard display