feat: conditionally display profile link

master
Aravinth Manivannan 2022-03-11 23:45:07 +05:30
parent 3e42c621fb
commit 9fb203de32
Signed by: realaravinth
GPG Key ID: AD9F0F08E855ED88
3 changed files with 15 additions and 8 deletions

View File

@ -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());

View File

@ -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);

View File

@ -16,9 +16,11 @@
<div class="nav__link-container">
<a class="nav__link" rel="noreferrer" href="{{ page.gist.new }}">New Paste</a>
</div>
<div class="nav__link-container">
<a class="nav__link" rel="noreferrer" href="{{ loggedin_user }}">Profile</a>
</div>
{% if loggedin_user %}
<div class="nav__link-container">
<a class="nav__link" rel="noreferrer" href="{{ loggedin_user }}">Profile</a>
</div>
{% endif %}
<div class="nav__link-container">
<a class="nav__link" rel="noreferrer" href="{{ page.auth.logout }}">Log out</a>
</div>