From 9fb203de320fc2b0e919c3d1c07f89efc2e2c4f2 Mon Sep 17 00:00:00 2001 From: realaravinth Date: Fri, 11 Mar 2022 23:45:07 +0530 Subject: [PATCH] feat: conditionally display profile link --- src/pages/gists/new.rs | 2 +- src/pages/mod.rs | 13 +++++++++---- templates/components/nav/auth.html | 8 +++++--- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/pages/gists/new.rs b/src/pages/gists/new.rs index 1b09669..a706594 100644 --- a/src/pages/gists/new.rs +++ b/src/pages/gists/new.rs @@ -63,7 +63,7 @@ impl NewGist { payload: Option<&[FieldNames<&str>]>, ) -> Self { const FIELDNAMES_KEY: &str = "fieldnames"; - let mut ctx = auth_ctx(username, settings); + let mut ctx = auth_ctx(Some(username), settings); ctx.insert("visibility_private", GistVisibility::Private.to_str()); ctx.insert("visibility_unlisted", GistVisibility::Unlisted.to_str()); ctx.insert("visibility_public", GistVisibility::Public.to_str()); diff --git a/src/pages/mod.rs b/src/pages/mod.rs index 3171bd5..39f41d9 100644 --- a/src/pages/mod.rs +++ b/src/pages/mod.rs @@ -97,11 +97,16 @@ pub fn context(s: &Settings) -> Context { ctx } -pub fn auth_ctx(username: &str, s: &Settings) -> Context { +pub fn auth_ctx(username: Option<&str>, s: &Settings) -> Context { use routes::GistProfilePathComponent; - let profile_link = PAGES - .gist - .get_profile_route(GistProfilePathComponent { username }); + let mut profile_link = None; + if let Some(name) = username { + profile_link = Some( + PAGES + .gist + .get_profile_route(GistProfilePathComponent { username: name }), + ); + } let mut ctx = Context::new(); let footer = Footer::new(s); ctx.insert("footer", &footer); diff --git a/templates/components/nav/auth.html b/templates/components/nav/auth.html index d34737a..4137d4c 100644 --- a/templates/components/nav/auth.html +++ b/templates/components/nav/auth.html @@ -16,9 +16,11 @@ - + {% if loggedin_user %} + + {% endif %}