Add rudimentary entry page, fix main frame link navigation

This commit is contained in:
Tyler Hallada 2023-06-02 00:31:25 -04:00
parent 0b7acadd60
commit ea236dff4e
5 changed files with 23 additions and 2 deletions

18
src/handlers/entry.rs Normal file
View File

@ -0,0 +1,18 @@
use axum::extract::{State, Path};
use axum::response::Response;
use maud::html;
use sqlx::PgPool;
use crate::error::Result;
use crate::models::entry::get_entry;
use crate::partials::layout::Layout;
pub async fn get(Path(id): Path<i32>, State(pool): State<PgPool>, layout: Layout) -> Result<Response> {
let entry = get_entry(&pool, id).await?;
Ok(layout.render(html! {
@let title = entry.title.unwrap_or_else(|| "Untitled".to_string());
h1 { a href=(entry.url) { (title) } }
@let description = entry.description.unwrap_or_else(|| "No description".to_string());
p { (description) }
}))
}

View File

@ -13,7 +13,8 @@ pub async fn get(State(pool): State<PgPool>, layout: Layout) -> Result<Response>
ul {
@for entry in entries {
@let title = entry.title.unwrap_or_else(|| "Untitled".to_string());
li { (title) }
@let url = format!("/entry/{}", entry.id);
li { a href=(url) { (title) } }
}
}
}))

View File

@ -1,3 +1,4 @@
pub mod api;
pub mod entry;
pub mod home;
pub mod feeds;

View File

@ -42,6 +42,7 @@ async fn main() -> Result<()> {
.route("/api/v1/entry/:id", get(handlers::api::entry::get))
.route("/", get(handlers::home::get))
.route("/feeds", get(handlers::feeds::get))
.route("/entry/:id", get(handlers::entry::get))
.with_state(AppState {
pool,
config,

View File

@ -45,7 +45,7 @@ impl Layout {
}
body {
(header())
turbo-frame id="main" {
turbo-frame id="main" data-turbo-action="advance" {
(template)
}
}