Added the functionality to insert a workout
This commit is contained in:
44
src/pages/workouts.rs
Normal file
44
src/pages/workouts.rs
Normal file
@@ -0,0 +1,44 @@
|
||||
use crate::{AppError, icons, layouts, util::AppState};
|
||||
use axum::{Router, extract::State, routing::get};
|
||||
use maud::{Markup, html};
|
||||
|
||||
mod new;
|
||||
|
||||
pub fn routes() -> Router<AppState> {
|
||||
Router::new()
|
||||
.route("/", get(page))
|
||||
.nest("/new", new::routes())
|
||||
// .nest("/{id}", id::routes())
|
||||
}
|
||||
|
||||
async fn page(State(state): State<AppState>) -> Result<Markup, AppError> {
|
||||
let workouts = sqlx::query_as!(
|
||||
crate::models::Workout,
|
||||
"SELECT workout_id, name, description FROM workouts"
|
||||
)
|
||||
.fetch_all(&state.pool)
|
||||
.await?;
|
||||
|
||||
let content = html! {
|
||||
h1 { "Workouts" }
|
||||
a href="/workouts/new" { "new workout +" }
|
||||
ul class="list" {
|
||||
@for workout in workouts {
|
||||
li hx-get={ "/workouts/" (workout.workout_id) } hx-target="body" hx-push-url="true" class="list-row" {
|
||||
div {}
|
||||
div {
|
||||
div class="font-bold" { (workout.name) }
|
||||
div class="text-xs" { (workout.description) }
|
||||
}
|
||||
a class="btn btn-square btn-ghost" {
|
||||
div class="size-[1.6em]" {
|
||||
(icons::eye())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Ok(layouts::desktop(content, "Exercises"))
|
||||
}
|
Reference in New Issue
Block a user