Add a toggle between dark and light theme
This commit is contained in:
parent
d22617538e
commit
559ed139aa
34 changed files with 640 additions and 469 deletions
|
|
@ -7,12 +7,7 @@ use axum::{
|
|||
response::{Html, IntoResponse, Response},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
Result,
|
||||
data::{db, model},
|
||||
html_templates::*,
|
||||
ron_utils, translation,
|
||||
};
|
||||
use crate::{Context, Result, data::db, html_templates::*, ron_utils};
|
||||
|
||||
pub mod fragments;
|
||||
pub mod recipe;
|
||||
|
|
@ -21,7 +16,7 @@ pub mod user;
|
|||
|
||||
// Will embed RON error in HTML page.
|
||||
pub async fn ron_error_to_html(
|
||||
Extension(tr): Extension<translation::Tr>,
|
||||
Extension(context): Extension<Context>,
|
||||
req: Request,
|
||||
next: Next,
|
||||
) -> Result<Response> {
|
||||
|
|
@ -35,10 +30,9 @@ pub async fn ron_error_to_html(
|
|||
};
|
||||
return Ok(Html(
|
||||
MessageTemplate {
|
||||
user: None,
|
||||
context,
|
||||
message: &message,
|
||||
as_code: true,
|
||||
tr,
|
||||
}
|
||||
.render()?,
|
||||
)
|
||||
|
|
@ -54,14 +48,16 @@ pub async fn ron_error_to_html(
|
|||
#[debug_handler]
|
||||
pub async fn home_page(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
Extension(tr): Extension<translation::Tr>,
|
||||
Extension(context): Extension<Context>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
let recipes = Recipes {
|
||||
published: connection
|
||||
.get_all_published_recipe_titles(tr.current_lang_code(), user.as_ref().map(|u| u.id))
|
||||
.get_all_published_recipe_titles(
|
||||
context.tr.current_lang_code(),
|
||||
context.user.as_ref().map(|u| u.id),
|
||||
)
|
||||
.await?,
|
||||
unpublished: if let Some(user) = user.as_ref() {
|
||||
unpublished: if let Some(user) = context.user.as_ref() {
|
||||
connection
|
||||
.get_all_unpublished_recipe_titles(user.id)
|
||||
.await?
|
||||
|
|
@ -71,18 +67,15 @@ pub async fn home_page(
|
|||
current_id: None,
|
||||
};
|
||||
|
||||
Ok(Html(HomeTemplate { user, recipes, tr }.render()?))
|
||||
Ok(Html(HomeTemplate { context, recipes }.render()?))
|
||||
}
|
||||
|
||||
///// 404 /////
|
||||
|
||||
#[debug_handler]
|
||||
pub async fn not_found(
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
Extension(tr): Extension<translation::Tr>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
pub async fn not_found(Extension(context): Extension<Context>) -> Result<impl IntoResponse> {
|
||||
Ok((
|
||||
StatusCode::NOT_FOUND,
|
||||
Html(MessageTemplate::new_with_user("404: Not found", tr, user).render()?),
|
||||
Html(MessageTemplate::new_with_user("404: Not found", context.tr, context.user).render()?),
|
||||
))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue