aboutsummaryrefslogtreecommitdiff
path: root/server/src/routes/ui/layout.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2023-01-22 13:56:06 +0100
committermetamuffin <metamuffin@disroot.org>2023-01-22 13:56:06 +0100
commitec76bbe5398f51ffa55bfd315b30c0a07245d4e6 (patch)
treefa0e1723f861de6fee21a35524bb7768fab0b6ce /server/src/routes/ui/layout.rs
parent84e093afa908dc68a7b0ae97ba8dc76aa0901d26 (diff)
downloadjellything-ec76bbe5398f51ffa55bfd315b30c0a07245d4e6.tar
jellything-ec76bbe5398f51ffa55bfd315b30c0a07245d4e6.tar.bz2
jellything-ec76bbe5398f51ffa55bfd315b30c0a07245d4e6.tar.zst
this is *horrible*
Diffstat (limited to 'server/src/routes/ui/layout.rs')
-rw-r--r--server/src/routes/ui/layout.rs50
1 files changed, 47 insertions, 3 deletions
diff --git a/server/src/routes/ui/layout.rs b/server/src/routes/ui/layout.rs
index cda8b0f..c25e644 100644
--- a/server/src/routes/ui/layout.rs
+++ b/server/src/routes/ui/layout.rs
@@ -1,9 +1,18 @@
+use super::{account::session::Session, Defer, HtmlTemplate};
+use crate::{uri, CONF};
+use async_std::task::block_on;
use markup::Render;
-
-use crate::CONF;
+use rocket::{
+ http::ContentType,
+ request::{FromRequest, Outcome},
+ response::{self, Responder},
+ Request, Response,
+};
+use std::{convert::Infallible, io::Cursor};
+use tokio::runtime::Handle;
markup::define! {
- Layout<Main: Render>(title: String, main: Main) {
+ Layout<Main: Render>(title: String, main: Main, session: Option<Session>) {
@markup::doctype()
html {
head {
@@ -15,9 +24,44 @@ markup::define! {
nav {
h1 { a[href="/"] { @CONF.brand } }
a[href="/library"] { "My Library" }
+
+ div.account {
+ @if let Some(session) = session {
+
+ } else {
+ // a[href=uri!(r_account_register())] { "Register" }
+ // a[href=uri!(r_account_login())] { "Log in" }
+ }
+ }
}
#main { @main }
}
}
}
}
+
+pub type DynLayoutPage<'a> = LayoutPage<markup::DynRender<'a>>;
+
+pub struct LayoutPage<T> {
+ pub title: String,
+ pub content: T,
+}
+
+impl<'r, Main: Render> Responder<'r, 'static> for LayoutPage<Main> {
+ fn respond_to(self, req: &'r Request<'_>) -> response::Result<'static> {
+ let session = block_on(req.guard::<Option<Session>>()).unwrap();
+ let mut out = String::new();
+ Layout {
+ main: self.content,
+ title: self.title,
+ session,
+ }
+ .render(&mut out)
+ .unwrap();
+
+ Response::build()
+ .header(ContentType::HTML)
+ .streamed_body(Cursor::new(out))
+ .ok()
+ }
+}