feat(grfn/bbbg): Add styling for active nav item

Change-Id: I5fbbd5ea6965d107cb9a44dff89ac77d0598c1f1
Reviewed-on: https://cl.tvl.fyi/c/depot/+/4588
Reviewed-by: grfn <grfn@gws.fyi>
Autosubmit: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
This commit is contained in:
Griffin Smith 2021-12-24 15:00:22 -05:00 committed by clbot
parent ae7eff703c
commit bd85e08e3d
3 changed files with 28 additions and 7 deletions

View file

@ -3,7 +3,8 @@
[bbbg.user :as user] [bbbg.user :as user]
[bbbg.views.flash :as flash] [bbbg.views.flash :as flash]
[hiccup.core :refer [html]] [hiccup.core :refer [html]]
[ring.util.response :refer [content-type response]])) [ring.util.response :refer [content-type response]]
[clojure.string :as str]))
(def ^:dynamic *authenticated?* false) (def ^:dynamic *authenticated?* false)
@ -20,14 +21,29 @@
(binding [*authenticated?* (authenticated? req)] (binding [*authenticated?* (authenticated? req)]
(handler req)))) (handler req))))
(def ^:dynamic *current-uri*)
(defn wrap-current-uri [handler]
(fn [req]
(binding [*current-uri* (:uri req)]
(handler req))))
(defn nav-item [href label]
(let [active?
(when *current-uri*
(str/starts-with?
*current-uri*
href))]
[:li {:class (when active? "active")}
[:a {:href href}
label]]))
(defn global-nav [] (defn global-nav []
[:nav.global-nav [:nav.global-nav
[:ul [:ul
[:li [:a {:href "/events"} (nav-item "/events" "Events")
"Events"]]
(when *authenticated?* (when *authenticated?*
[:li [:a {:href "/attendees"} (nav-item "/attendees" "Attendees"))
"Attendees"]])
[:li.spacer] [:li.spacer]
[:li [:li
(if *authenticated?* (if *authenticated?*

View file

@ -69,6 +69,10 @@
[(& hover) [(& hover)
{:color blue}]] {:color blue}]]
[:li.active
{:font-weight "bold"
:border-bottom [["1px" "solid" black]]}]
[:.spacer [:.spacer
{:flex 1}]]) {:flex 1}]])

View file

@ -3,7 +3,7 @@
[bbbg.discord.auth :as discord.auth :refer [wrap-discord-auth]] [bbbg.discord.auth :as discord.auth :refer [wrap-discord-auth]]
[bbbg.handlers.attendee-checks :as attendee-checks] [bbbg.handlers.attendee-checks :as attendee-checks]
[bbbg.handlers.attendees :as attendees] [bbbg.handlers.attendees :as attendees]
[bbbg.handlers.core :refer [wrap-dynamic-auth]] [bbbg.handlers.core :refer [wrap-dynamic-auth wrap-current-uri]]
[bbbg.handlers.events :as events] [bbbg.handlers.events :as events]
[bbbg.handlers.home :as home] [bbbg.handlers.home :as home]
[bbbg.handlers.signup-form :as signup-form] [bbbg.handlers.signup-form :as signup-form]
@ -23,7 +23,7 @@
[ring.middleware.resource :refer [wrap-resource]] [ring.middleware.resource :refer [wrap-resource]]
[ring.middleware.session :refer [wrap-session]] [ring.middleware.session :refer [wrap-session]]
[ring.middleware.session.cookie :refer [cookie-store]] [ring.middleware.session.cookie :refer [cookie-store]]
[ring.util.response :refer [content-type resource-response response]] [ring.util.response :refer [content-type response]]
[clojure.java.io :as io]) [clojure.java.io :as io])
(:import (:import
java.util.Base64)) java.util.Base64))
@ -89,6 +89,7 @@
(defn middleware [app env] (defn middleware [app env]
(-> app (-> app
(wrap-resource "public") (wrap-resource "public")
wrap-current-uri
wrap-dynamic-auth wrap-dynamic-auth
(wrap-discord-auth env) (wrap-discord-auth env)
wrap-keyword-params wrap-keyword-params