From 1e62b11a013e574d6ba100d9a0514b5006835401 Mon Sep 17 00:00:00 2001 From: asonix Date: Sun, 31 Jan 2021 17:22:15 -0600 Subject: [PATCH] Server: Start work on better nav bar --- scss/layout.scss | 20 +++++ src/nav.rs | 99 ++++++++++++++++------- templates/admin/submission_box.rs.html | 4 +- templates/bar.rs.html | 53 ++++++++++++ templates/comments/profile_box.rs.html | 4 +- templates/layouts/wide.rs.html | 32 ++------ templates/profiles/discover.rs.html | 4 +- templates/profiles/list.rs.html | 4 +- templates/submissions/profile_box.rs.html | 4 +- 9 files changed, 159 insertions(+), 65 deletions(-) create mode 100644 templates/bar.rs.html diff --git a/scss/layout.scss b/scss/layout.scss index 0b95951..3bb3b03 100644 --- a/scss/layout.scss +++ b/scss/layout.scss @@ -25,6 +25,26 @@ picture { display: none; } +.profile-nav { + display: flex; + align-items: center; + + .bar-icon { + margin-right: 0; + margin-left: 16px; + } + .toolkit-icon--link .toolkit-icon { + border-width: 1px; + } + + .notification-bell { + .toolkit-link, + i { + display: block; + } + } +} + .narrow-nav { display: none; } diff --git a/src/nav.rs b/src/nav.rs index 379a063..3128217 100644 --- a/src/nav.rs +++ b/src/nav.rs @@ -1,15 +1,19 @@ use crate::{ - admin::Admin, extensions::ProfileExt, middleware::UserProfile, - notifications::total_for_profile, ActixLoader, State, + admin::Admin, + error::Error, + extensions::ProfileExt, + middleware::UserProfile, + notifications::total_for_profile, + views::{OwnedProfileView, ProfileView}, + ActixLoader, State, }; use actix_web::{ dev::Payload, - web::{Data, Query}, + web::{self, Data, Query}, FromRequest, HttpRequest, }; use futures::future::LocalBoxFuture; use hyaenidae_accounts::LogoutState; -use hyaenidae_profiles::store::Profile; use hyaenidae_toolkit::Button; use i18n_embed_fl::fl; @@ -66,6 +70,29 @@ impl FromRequest for NavState { None }; + let store = state.profiles.clone(); + + let profile = if let Some(profile) = profile { + let profile = web::block(move || { + let icon = if let Some(file_id) = profile.icon() { + store.store.files.by_id(file_id)? + } else { + None + }; + + Ok(OwnedProfileView { + profile, + icon, + banner: None, + }) as Result<_, Error> + }) + .await?; + + Some(profile) + } else { + None + }; + Ok(NavState { profile, notification_count, @@ -73,14 +100,14 @@ impl FromRequest for NavState { admin, href, is_open, - dark: false, + dark: true, }) }) } } pub struct NavState { - profile: Option, + profile: Option, notification_count: Option, logout_state: Option, admin: Option, @@ -94,50 +121,70 @@ impl NavState { &self.href } - fn submission_button(&self, loader: &ActixLoader) -> Button { - Button::primary(&fl!(loader, "nav-submission-button")).href("/submissions/create") + pub(crate) fn profile<'a>(&'a self) -> Option> { + self.profile.as_ref().map(|p| ProfileView { + profile: &p.profile, + icon: p.icon.as_ref(), + banner: p.banner.as_ref(), + }) + } + + pub(crate) fn submission_button(&self, loader: &ActixLoader) -> Button { + Button::primary_link(&fl!(loader, "nav-submission-button")).href("/submissions/create") } fn nav_button(&self, loader: &ActixLoader) -> Button { - Button::secondary(&fl!(loader, "nav-text")) + Button::link(&fl!(loader, "nav-text")) .href(&self.href) .class("nav-link") } - fn browse_button(&self, loader: &ActixLoader) -> Button { - Button::secondary(&fl!(loader, "nav-browse-button")).href("/browse") + pub(crate) fn browse_button(&self, loader: &ActixLoader) -> Button { + Button::link(&fl!(loader, "nav-browse-button")).href("/browse") } fn profile_button(&self, loader: &ActixLoader) -> Button { - if let Some(profile) = self.profile.as_ref() { - Button::secondary(&fl!(loader, "nav-profile-button")).href(&profile.view_path()) + if let Some(view) = self.profile.as_ref() { + Button::link(&fl!(loader, "nav-profile-button")).href(&view.profile.view_path()) } else { - Button::secondary(&fl!(loader, "nav-switch-profile-button")).href("/profiles/change") + Button::link(&fl!(loader, "nav-switch-profile-button")).href("/profiles/change") } } + pub(crate) fn notifications_path(&self) -> &'static str { + "/notifications" + } + fn notifications_button(&self, loader: &ActixLoader) -> Button { - Button::secondary(&fl!(loader, "nav-notifications-button")).href("/notifications") + Button::link(&fl!(loader, "nav-notifications-button")).href(self.notifications_path()) } fn admin_button(&self, loader: &ActixLoader) -> Button { - Button::secondary(&fl!(loader, "nav-admin-button")).href("/admin") + Button::link(&fl!(loader, "nav-admin-button")).href("/admin") } fn account_button(&self, loader: &ActixLoader) -> Button { - Button::secondary(&fl!(loader, "nav-account-button")).href("/session/account") + Button::link(&fl!(loader, "nav-account-button")).href("/session/account") } fn login_button(&self, loader: &ActixLoader) -> Button { - Button::primary_outline(&fl!(loader, "nav-login-button")).href("/session/auth/login") + Button::primary_link(&fl!(loader, "nav-login-button")).href("/session/auth/login") } fn register_button(&self, loader: &ActixLoader) -> Button { - Button::primary_outline(&fl!(loader, "nav-register-button")).href("/session/auth/register") + Button::primary_link(&fl!(loader, "nav-register-button")).href("/session/auth/register") } fn logout_button(&self, logout_state: &LogoutState, loader: &ActixLoader) -> Button { - Button::primary_outline(&fl!(loader, "nav-logout-button")).form(&logout_state.logout_path()) + Button::primary_link(&fl!(loader, "nav-logout-button")).form(&logout_state.logout_path()) + } + + pub(crate) fn has_notifications(&self) -> bool { + if let Some(count) = self.notification_count { + count > 0 + } else { + false + } } pub(crate) fn buttons(&self, loader: &ActixLoader) -> Vec