diff options
Diffstat (limited to 'server/src/routes/ui/layout.rs')
-rw-r--r-- | server/src/routes/ui/layout.rs | 50 |
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() + } +} |