Skip to content

Commit

Permalink
split out templates into own file
Browse files Browse the repository at this point in the history
  • Loading branch information
Joeyh021 committed Aug 25, 2023
1 parent ea9fe2c commit 7b11c35
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
28 changes: 4 additions & 24 deletions src/routes/app.rs → src/routes/app/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use super::handle_error;
use crate::{db, types::GoPair, AppState};
use anyhow::Context;
use askama::Template;
use axum::{
extract::State,
http::StatusCode,
Expand All @@ -10,19 +9,12 @@ use axum::{
Form, Router,
};
use axum_sessions::extractors::ReadableSession;
pub async fn home() -> impl IntoResponse {
#[derive(Template)]
#[template(path = "home.html")]
struct IndexTemplate;

IndexTemplate
}
mod templates;
use templates::*;

#[derive(Template)]
#[template(path = "app.html")]
struct AppTemplate {
username: String,
message: Option<String>,
pub async fn home() -> impl IntoResponse {
IndexTemplate
}

async fn app(session: ReadableSession, _: State<AppState>) -> Result<impl IntoResponse> {
Expand All @@ -37,18 +29,6 @@ async fn app(session: ReadableSession, _: State<AppState>) -> Result<impl IntoRe
})
}

#[derive(Template)]
#[template(path = "panel.html")]
struct PanelTemplate {
message: Option<String>,
}

#[derive(Template)]
#[template(path = "table.html")]
struct TableTemplate {
redirects: Vec<crate::types::Redirect>,
}

///this returns just the html for the table body. Used for lazy loading and reloading by HTMX.
async fn table(
session: ReadableSession,
Expand Down
24 changes: 24 additions & 0 deletions src/routes/app/templates.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use askama::Template;

#[derive(Template)]
#[template(path = "app.html")]
pub struct AppTemplate {
pub username: String,
pub message: Option<String>,
}

#[derive(Template)]
#[template(path = "home.html")]
pub struct IndexTemplate;

#[derive(Template)]
#[template(path = "panel.html")]
pub struct PanelTemplate {
pub message: Option<String>,
}

#[derive(Template)]
#[template(path = "table.html")]
pub struct TableTemplate {
pub redirects: Vec<crate::types::Redirect>,
}

0 comments on commit 7b11c35

Please sign in to comment.