Skip to content

Commit

Permalink
Refactorings and fixes
Browse files Browse the repository at this point in the history
- Add dev/prod discord and ticket type config
- Styling tweaks
- Clean up and style flash box
- More ns-level docstrings (still some missing)
- Return `nil` from db/entity instead of empty map if not found
- Discord login flow: use middleware, add extra redirect step
- Fix oauth state checking and redirect tracking
  • Loading branch information
plexus committed Aug 17, 2024
1 parent 7daadf5 commit 042b099
Show file tree
Hide file tree
Showing 29 changed files with 375 additions and 291 deletions.
2 changes: 0 additions & 2 deletions resources/co/gaiwan/compass/config.edn
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{:port 8099
:discord/client-id "1228962758796775444"
:discord/public-key "f58a0fd30eaecaa690e8065717f61988d6fbdb5ee11658469d86ad016380656e"
:tito/event-slug "heart-of-clojure/2024"
:uploads/dir "uploads"}
16 changes: 15 additions & 1 deletion resources/co/gaiwan/compass/dev.edn
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,18 @@
:datomic/url "datomic:mem://compass"
:http/show-exception-details? true
:live.js? true
:tito/fake-api-stubs? true}
:tito/fake-api-stubs? true

;; Compass Test Server (https://discord.gg/WD72GE3VAj)
;; compass-dev bot (https://discord.com/developers/applications/983315200398733362)
:discord/client-id "983315200398733362"
:discord/public-key "fca03a0789343028329c53ea68af6f6ed32858283329615dd89ce0dd3908c8d3"
:discord/server-id "1263107498823385098"
:discord/ticket-holder-role "1273578623210881037"
:discord/ticket-roles {"crew" "1274001163754143886"
"sponsor" "1274001246390587514"
"speaker" "1274001093080383548"}
;; confgure locally
;; :discord/client-secret ""
;; :discord/bot-token ""
}
18 changes: 16 additions & 2 deletions resources/co/gaiwan/compass/prod.edn
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
{:port 8080
:compass/origin "https://compass.heartofclojure.eu"}
{:port 8080
:compass/origin "https://compass.heartofclojure.eu"

;; Heart of Clojure Server
:discord/client-id "1228962758796775444"
:discord/public-key "f58a0fd30eaecaa690e8065717f61988d6fbdb5ee11658469d86ad016380656e"
:discord/server-id "1217429335221342218"
:discord/ticket-holder-role "1267502146643820564"
:discord/ticket-roles {"crew" "1217465896369524828"
"sponsor" "1258771176134541312"
"speaker" "1256227155143295076"}
;; confgure locally
;; :discord/client-secret ""
;; :discord/bot-token ""

}
35 changes: 31 additions & 4 deletions resources/public/css/styles.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
:where(html) {
--size-0: 0;
--co-gaiwan-compass-html-components--toggle-radius-left: 0.5rem;
--co-gaiwan-compass-html-components--toggle-radius-left: var(--radius-2);
--sessions-arc-color: var(--lime-5);
--hoc-pink: #e25f7d;
--hoc-pink-3: var(--hoc-pink);
Expand All @@ -11,7 +11,7 @@
--hoc-pink-1: #e7879d;
--hoc-pink-2: #cd4e6a;
--hoc-pink-4: #c0415b;
--co-gaiwan-compass-html-components--toggle-radius-right: 0.5rem;
--co-gaiwan-compass-html-components--toggle-radius-right: var(--radius-2);
}

:where(html) {
Expand Down Expand Up @@ -75,7 +75,7 @@ h5, h4, h2, h1, h3 {
}

button, .btn {
border-radius: 0.4rem;
border-radius: var(--radius-2);
}

dialog {
Expand All @@ -86,6 +86,14 @@ body {
font-family: Open Sans, sans-serif;
}

@keyframes fade-to-pale {

to {
opacity: 1;
}

}

.graphics-compass_logo path {
fill: var(--hoc-pink);
}
Expand Down Expand Up @@ -185,6 +193,7 @@ body {

.co_gaiwan_compass_html_auth__popup p {
margin: var(--size-4);
margin-top: var(--size-2);
}

.co_gaiwan_compass_html_auth__popup .discord-login {
Expand All @@ -194,7 +203,7 @@ body {
padding-left: var(--size-4);
padding-right: var(--size-4);
background-color: #7289da;
border-radius: 0.5rem;
border-radius: var(--radius-2);
color: var(--gray-0);
text-align: center;
}
Expand All @@ -207,6 +216,7 @@ body {
width: 3rem;
height: 2.25rem;
padding: 0.4rem;
--_icon-color: var(--text-1);
}

.co_gaiwan_compass_html_auth__popup .graphics-discord {
Expand Down Expand Up @@ -517,3 +527,20 @@ body {
grid-template-columns: 10rem 1fr;
gap: var(--size-2);
}

.co_gaiwan_compass_html_layout__flash_box {
border-width: 1px;
padding-bottom: var(--size-2);
border-color: var(--green-2);
animation: fade-to-pale linear 0.5s forwards;
margin-top: var(--size-3);
margin-bottom: var(--size-3);
font-weight: 600;
background-color: var(--green-1);
padding-right: var(--size-3);
border-radius: var(--radius-2);
color: var(--blue-12);
padding-left: var(--size-3);
padding-top: var(--size-2);
opacity: 0.5;
}
18 changes: 18 additions & 0 deletions src/co/gaiwan/compass/config.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
(ns co.gaiwan.compass.config
"Configuration API
Gives us just enough flexiblity to comfortably have separate prod/edn
config+secrets, maximally checking in anything that isn't a secret into the
repo, and allowing for convenient local overrides.
Main public API: `config/value`, the rest is plumbing.
Merge in order (where applicable)
- `resources/co/gaiwan/compass/config.edn` - Base config file, shared values
- `resources/co/gaiwan/compass/prod.edn` - Prod specific values
- `resources/co/gaiwan/compass/dev.edn` - Dev specific values
- `config.local.edn` - Local overrides, does not get checked in
- environment variables - After munging, e.g. :f-oo/bar -> F_OO__BAR
When running with launchpad config files are watched for changes.
"
(:require
[aero.core :as aero]
[clojure.java.io :as io]
Expand Down
5 changes: 2 additions & 3 deletions src/co/gaiwan/compass/css.clj
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
(ns co.gaiwan.compass.css
"Ornament/CSS compiling, watching, and configuration"
(:require
[clojure.java.io :as io]
[clojure.string :as str]
[co.gaiwan.compass.css.colors :as colors]
[co.gaiwan.compass.css.components :as components]
[co.gaiwan.compass.css.tokens :as tokens]
[garden.compiler :as gc]
[lambdaisland.ornament :as o]))

(require 'co.gaiwan.compass.css.styles
)
(require 'co.gaiwan.compass.css.styles)

(o/set-tokens!
{:components (with-meta components/girouette-components {:replace true})
Expand Down
44 changes: 0 additions & 44 deletions src/co/gaiwan/compass/css/colors.clj

This file was deleted.

1 change: 1 addition & 0 deletions src/co/gaiwan/compass/css/components.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(ns co.gaiwan.compass.css.components
"Override Girouette components, mainly to make use of Open Props tokens"
(:require
[girouette.tw.accessibility :as accessibility]
[girouette.tw.animation :as animation]
Expand Down
7 changes: 5 additions & 2 deletions src/co/gaiwan/compass/css/styles.clj
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
(ns co.gaiwan.compass.css.styles
(:require [lambdaisland.ornament :as o]))
"Top level CSS rules"
(:require
[co.gaiwan.compass.css.tokens :as t]
[lambdaisland.ornament :as o]))

(o/defrules resets
[[#{:ul :ol} :list-none :m-0 :p-0]
[:body :overflow-x-hidden :w-screen]
[#{:h1 :h2 :h3 :h4 :h5} {:max-inline-size "inherit"}]

;; override open-props normalize, we like the buttons a bit more rounded
[#{:button :.btn} {:border-radius "0.4rem"}]
[#{:button :.btn} {:border-radius t/--radius-2}]

;; reset dialog
[:dialog :p-0]
Expand Down
1 change: 1 addition & 0 deletions src/co/gaiwan/compass/css/tokens.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(ns co.gaiwan.compass.css.tokens
"Design tokens, partly imported from Open Props, partly defined here"
{:ornament/prefix ""}
(:require
[charred.api :as charred]
Expand Down
3 changes: 2 additions & 1 deletion src/co/gaiwan/compass/db.clj
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@
(walk/postwalk munge-from-db (apply d/q args)))

(defn entity [lookup]
(->munged-entity (d/entity (db) lookup)))
(when-let [e (d/entity (db) lookup)]
(->munged-entity e)))

(comment
;; reload schema and data
Expand Down
1 change: 1 addition & 0 deletions src/co/gaiwan/compass/db/data.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(ns co.gaiwan.compass.db.data
"Static data that gets imported at boot"
(:require [clojure.java.io :as io]
[clojure.pprint :as pprint]))

Expand Down
1 change: 1 addition & 0 deletions src/co/gaiwan/compass/db/queries.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(ns co.gaiwan.compass.db.queries
"Database queries, to be used in routes"
(:require
[co.gaiwan.compass.db :as db]))

Expand Down
3 changes: 2 additions & 1 deletion src/co/gaiwan/compass/db/schema.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(ns co.gaiwan.compass.db.schema)
(ns co.gaiwan.compass.db.schema
"Datomic schema, using shorthand vectors")

;; bigdec | bigint | boolean | bytes | double | float | instant |
;; keyword | long | ref | string | symbol | tuple | uuid | uri
Expand Down
20 changes: 11 additions & 9 deletions src/co/gaiwan/compass/html/auth.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,25 @@
:flex-col :items-center
:gap-4
[:.top :flex :self-end :p-2]
[:p :m-4]
[:p :m-4 :mt-2]
[:.discord-login :mb-4 :py-3 :px-4
{:background-color "#7289da"
:border-radius "0.5rem"
:border-radius t/--radius-2
:color t/--gray-0
:text-align "center"}
[:&:hover {:text-decoration "none"}]]
[graphics/cross {:width "3rem" :height "2.25rem" :padding "0.4rem"}]
[graphics/cross {:width "3rem" :height "2.25rem" :padding "0.4rem"
:--_icon-color t/--text-1}]
[graphics/discord {:height "2rem" :width "2rem" :--_logo-color t/--gray-0}]
([next-url]
[:<>
[:div.top
[:a.top
[graphics/cross {:class "btn close-button" :on-click "window.modal.close()"}]]
[:p "Please authenticate using Discord to make full use of the Compass app. This will also give you access to our Discord server where you can chat with speakers and attendees."]
[:p "You can authenticate using Discord to make full use of the Compass app. This will also give you access to our Discord server where you can chat with speakers and attendees."]
[:a.btn.discord-login
{:href (oauth/flow-init-url (if next-url
{:redirect-url next-url}
{}))}
{:hx-boost "false"
:href (if next-url
(str "/oauth2/discord/redirect?redirect_url=" next-url)
(str "/oauth2/discord/redirect"))}
[graphics/discord]
"Login with discord"]]))
"Continue with Discord"]]))
4 changes: 2 additions & 2 deletions src/co/gaiwan/compass/html/components.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
[co.gaiwan.compass.css.tokens :as t]
[lambdaisland.ornament :as o]))

(o/defprop --toggle-radius-left "0.5rem")
(o/defprop --toggle-radius-right "0.5rem")
(o/defprop --toggle-radius-left t/--radius-2)
(o/defprop --toggle-radius-right t/--radius-2)

(o/defstyled toggle-button :label
"Toggle implemented as a checkbox (can also be used as a radio button)."
Expand Down
23 changes: 21 additions & 2 deletions src/co/gaiwan/compass/html/layout.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
(:require
[charred.api :as charred]
[co.gaiwan.compass.config :as config]
[co.gaiwan.compass.css.tokens :as t]
[co.gaiwan.compass.html.navigation :as nav]
[lambdaisland.ornament :as o]
[ring.middleware.anti-forgery :as anti-forgery]))
Expand All @@ -14,6 +15,24 @@

(def start-time (System/currentTimeMillis))

(o/defstyled flash-box :div
:my-3
:px-3 :py-2
{:background-color t/--green-1
:color t/--blue-12
:border-radius t/--radius-2
:border-color t/--green-2
:border-width "1px"
:font-weight "600"
:opacity 0.5
:animation "fade-to-pale linear 0.5s forwards"
})

(o/defrules fade-flash-box
(garden.stylesheet/at-keyframes
:fade-to-pale
[:to {:opacity 1}]))

(defn base-layout [{:keys [head body flash user request] :as opts}]
[:html
[:head
Expand Down Expand Up @@ -42,8 +61,8 @@
[:div#app
[nav/menu-panel user]
[:main
(when flash
[:p.flash flash])
[nav/nav-bar user]
(when flash
[flash-box flash])
body
#_[:pre (with-out-str (clojure.pprint/pprint request))]]]]])
Loading

0 comments on commit 042b099

Please sign in to comment.