fix: redirect response

This commit is contained in:
Per Stark
2025-03-24 08:03:41 +01:00
parent 6bb6b8c69a
commit 9fd83b26cd

View File

@@ -1,9 +1,10 @@
use axum::{ use axum::{
extract::State, extract::State,
http::StatusCode, http::{StatusCode, Uri},
response::{Html, IntoResponse, Response}, response::{Html, IntoResponse, Response},
Extension, Extension,
}; };
use axum_htmx::HxRedirect;
use common::error::AppError; use common::error::AppError;
use minijinja::{context, Value}; use minijinja::{context, Value};
use minijinja_autoreload::AutoReloader; use minijinja_autoreload::AutoReloader;
@@ -15,10 +16,10 @@ use crate::html_state::HtmlState;
// Enum for template types // Enum for template types
#[derive(Clone)] #[derive(Clone)]
pub enum TemplateKind { pub enum TemplateKind {
Full(String), // Full page template Full(String), // Full page template
Partial(String, String), // Template name, block name Partial(String, String), // Template name, block name
Error(StatusCode), // Error template with status code Error(StatusCode), // Error template with status code
Redirect(axum::response::Redirect), // Redirect Redirect(String), // Redirect
} }
#[derive(Clone)] #[derive(Clone)]
@@ -97,11 +98,9 @@ impl TemplateResponse {
) )
} }
pub fn redirect(path: impl AsRef<str>) -> Self { pub fn redirect(path: impl Into<String>) -> Self {
let redirect_response = axum::response::Redirect::to(path.as_ref());
Self { Self {
template_kind: TemplateKind::Redirect(redirect_response), template_kind: TemplateKind::Redirect(path.into()),
context: Value::from_serialize(&()), context: Value::from_serialize(&()),
} }
} }
@@ -140,7 +139,9 @@ impl IntoResponse for TemplateStateWrapper {
}; };
(*status, html).into_response() (*status, html).into_response()
} }
TemplateKind::Redirect(redirect) => redirect.clone().into_response(), TemplateKind::Redirect(path) => {
(StatusCode::OK, [(axum_htmx::HX_REDIRECT, path.clone())], "").into_response()
}
} }
} }
} }