refactor: Used askama_axum::Template
docs: https://djc.github.io/askama/integrations.html#axum-integration
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
use askama::Template;
|
||||
use askama_axum::IntoResponse;
|
||||
use askama_axum::Template;
|
||||
use axum::{extract::Query, routing, Router};
|
||||
use serde::Deserialize;
|
||||
|
||||
@ -16,12 +15,12 @@ struct MenuParameters {
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "layout/nav/profile-menu-items.html")]
|
||||
struct MenuResponse {
|
||||
struct MenuTemplate {
|
||||
mobile: bool,
|
||||
items: Vec<MenuItem>,
|
||||
}
|
||||
|
||||
impl MenuResponse {
|
||||
impl MenuTemplate {
|
||||
fn get_classes(&self, is_current_item: &bool) -> String {
|
||||
let common_classes = match self.mobile {
|
||||
true => "block px-4 py-2 text-base font-medium text-gray-500 hover:bg-gray-100 hover:text-gray-800".to_string(),
|
||||
@ -36,8 +35,8 @@ impl MenuResponse {
|
||||
}
|
||||
}
|
||||
|
||||
async fn menu(Query(params): Query<MenuParameters>) -> impl IntoResponse {
|
||||
MenuResponse {
|
||||
async fn menu(Query(params): Query<MenuParameters>) -> MenuTemplate {
|
||||
MenuTemplate {
|
||||
mobile: params.mobile,
|
||||
items: vec![
|
||||
MenuItem {
|
||||
@ -57,7 +56,6 @@ async fn menu(Query(params): Query<MenuParameters>) -> impl IntoResponse {
|
||||
},
|
||||
],
|
||||
}
|
||||
.into_response()
|
||||
}
|
||||
|
||||
pub fn get_routes() -> Router {
|
||||
|
Reference in New Issue
Block a user