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.views.flash :as flash]
[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)
@ -20,14 +21,29 @@
(binding [*authenticated?* (authenticated? 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 []
[:nav.global-nav
[:ul
[:li [:a {:href "/events"}
"Events"]]
(nav-item "/events" "Events")
(when *authenticated?*
[:li [:a {:href "/attendees"}
"Attendees"]])
(nav-item "/attendees" "Attendees"))
[:li.spacer]
[:li
(if *authenticated?*

View file

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

View file

@ -3,7 +3,7 @@
[bbbg.discord.auth :as discord.auth :refer [wrap-discord-auth]]
[bbbg.handlers.attendee-checks :as attendee-checks]
[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.home :as home]
[bbbg.handlers.signup-form :as signup-form]
@ -23,7 +23,7 @@
[ring.middleware.resource :refer [wrap-resource]]
[ring.middleware.session :refer [wrap-session]]
[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])
(:import
java.util.Base64))
@ -89,6 +89,7 @@
(defn middleware [app env]
(-> app
(wrap-resource "public")
wrap-current-uri
wrap-dynamic-auth
(wrap-discord-auth env)
wrap-keyword-params