add: notifications ui

This commit is contained in:
trisua 2025-03-30 22:26:20 -04:00
parent 9dc75d7095
commit f5b75382e5
14 changed files with 179 additions and 14 deletions

View file

@ -128,8 +128,8 @@ pub fn routes() -> Router {
)
.route("/notifications/{id}", delete(notifications::delete_request))
.route(
"/notifications/{id}/read",
delete(notifications::update_read_status_request),
"/notifications/{id}/read_status",
post(notifications::update_read_status_request),
)
}

View file

@ -1,9 +1,11 @@
use super::render_error;
use crate::{State, assets::initial_context, get_lang, get_user_from_token};
use axum::{
Extension,
response::{Html, IntoResponse},
};
use axum_extra::extract::CookieJar;
use tetratto_core::model::Error;
/// `/`
pub async fn index_request(jar: CookieJar, Extension(data): Extension<State>) -> impl IntoResponse {
@ -15,3 +17,35 @@ pub async fn index_request(jar: CookieJar, Extension(data): Extension<State>) ->
Html(data.1.render("misc/index.html", &mut context).unwrap())
}
/// `/notifs`
pub async fn notifications_request(
jar: CookieJar,
Extension(data): Extension<State>,
) -> impl IntoResponse {
let data = data.read().await;
let user = match get_user_from_token!(jar, data.0) {
Some(ua) => ua,
None => {
return Err(Html(
render_error(Error::NotAllowed, &jar, &data, &None).await,
));
}
};
let notifications = match data.0.get_notifications_by_owner(user.id).await {
Ok(p) => p,
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
};
let lang = get_lang!(jar, data.0);
let mut context = initial_context(&data.0.0, lang, &Some(user)).await;
context.insert("notifications", &notifications);
// return
Ok(Html(
data.1
.render("misc/notifications.html", &mut context)
.unwrap(),
))
}

View file

@ -17,6 +17,7 @@ pub fn routes() -> Router {
Router::new()
// misc
.route("/", get(misc::index_request))
.route("/notifs", get(misc::notifications_request))
// auth
.route("/auth/register", get(auth::register_request))
.route("/auth/login", get(auth::login_request))