feat(grfn/bbbg): Move nav to page-global
Change-Id: I0a313d9df818fcbfeea5484123c1e7bcec439d66 Reviewed-on: https://cl.tvl.fyi/c/depot/+/4509 Reviewed-by: grfn <grfn@gws.fyi> Autosubmit: grfn <grfn@gws.fyi> Tested-by: BuildkiteCI
This commit is contained in:
parent
4643585e01
commit
9ea538beea
3 changed files with 39 additions and 27 deletions
|
@ -5,6 +5,37 @@
|
|||
[hiccup.core :refer [html]]
|
||||
[ring.util.response :refer [content-type response]]))
|
||||
|
||||
(def ^:dynamic *authenticated?* false)
|
||||
|
||||
(defn authenticated? [request]
|
||||
(some? (get-in request [:session ::user/id])))
|
||||
|
||||
(defn wrap-auth-required [handler]
|
||||
(fn [req]
|
||||
(when (authenticated? req)
|
||||
(handler req))))
|
||||
|
||||
(defn wrap-dynamic-auth [handler]
|
||||
(fn [req]
|
||||
(binding [*authenticated?* (authenticated? req)]
|
||||
(handler req))))
|
||||
|
||||
(defn global-nav []
|
||||
[:nav.global-nav
|
||||
[:ul
|
||||
(when *authenticated?*
|
||||
[:li [:a {:href "/attendees"}
|
||||
"Attendees"]])
|
||||
[:li [:a {:href "/events"}
|
||||
"Events"]]
|
||||
(if authenticated?
|
||||
[:li [:form {:method :post
|
||||
:action "/auth/sign-out"}
|
||||
[:input {:type "submit"
|
||||
:value "Sign Out"}]]]
|
||||
[:li [:a {:href "/auth/discord"}
|
||||
"Sign In"]])]])
|
||||
|
||||
(defn render-page [opts & body]
|
||||
(let [[{:keys [title]} body]
|
||||
(if (map? opts)
|
||||
|
@ -22,6 +53,7 @@
|
|||
:href "/main.css"}]]
|
||||
[:body
|
||||
[:div.content
|
||||
(global-nav)
|
||||
(flash/render-flash)
|
||||
body]
|
||||
[:script {:src "https://cdnjs.cloudflare.com/ajax/libs/tarekraafat-autocomplete.js/10.2.6/autoComplete.js"}]
|
||||
|
@ -32,14 +64,6 @@
|
|||
response
|
||||
(content-type "text/html")))
|
||||
|
||||
(defn authenticated? [request]
|
||||
(some? (get-in request [:session ::user/id])))
|
||||
|
||||
(defn wrap-auth-required [handler]
|
||||
(fn [req]
|
||||
(when (authenticated? req)
|
||||
(handler req))))
|
||||
|
||||
(comment
|
||||
(render-page
|
||||
[:h1 "hi"])
|
||||
|
|
|
@ -9,23 +9,10 @@
|
|||
[ring.util.response :refer [redirect]]
|
||||
[bbbg.discord :as discord]))
|
||||
|
||||
(defn- home-page [{:keys [authenticated?]}]
|
||||
[:nav.home-nav
|
||||
[:ul
|
||||
(when authenticated?
|
||||
[:li [:a {:href "/attendees"}
|
||||
"Attendees"]])
|
||||
[:li [:a {:href "/events"}
|
||||
"Events"]]
|
||||
[:li [:a {:href "/signup-forms"}
|
||||
"Event Signup Form"]]
|
||||
(if authenticated?
|
||||
[:li [:form {:method :post
|
||||
:action "/auth/sign-out"}
|
||||
[:input {:type "submit"
|
||||
:value "Sign Out"}]]]
|
||||
[:li [:a {:href "/auth/discord"}
|
||||
"Sign In"]])]])
|
||||
(defn- home-page []
|
||||
[:div.home-page
|
||||
[:a {:href "/signup-forms"}
|
||||
"Event Signup Form"]])
|
||||
|
||||
(defn auth-failure []
|
||||
[:div.auth-failure
|
||||
|
@ -36,8 +23,7 @@
|
|||
|
||||
(defn home-routes [{:keys [db] :as env}]
|
||||
(routes
|
||||
(GET "/" request
|
||||
(page-response (home-page {:authenticated? (authenticated? request)})))
|
||||
(GET "/" [] (page-response (home-page)))
|
||||
|
||||
(POST "/auth/sign-out" request
|
||||
(if (authenticated? request)
|
||||
|
|
|
@ -3,6 +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.events :as events]
|
||||
[bbbg.handlers.home :as home]
|
||||
[bbbg.handlers.signup-form :as signup-form]
|
||||
|
@ -82,6 +83,7 @@
|
|||
|
||||
(defn middleware [app env]
|
||||
(-> app
|
||||
wrap-dynamic-auth
|
||||
(wrap-discord-auth env)
|
||||
wrap-keyword-params
|
||||
wrap-params
|
||||
|
|
Loading…
Reference in a new issue