Skip to content

Commit

Permalink
Tidy up new activity flow
Browse files Browse the repository at this point in the history
  • Loading branch information
plexus committed Jul 21, 2024
1 parent 775f5ad commit 1e4111b
Show file tree
Hide file tree
Showing 11 changed files with 181 additions and 152 deletions.
16 changes: 16 additions & 0 deletions repl-sessions/db.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
(ns repl-sessions.db
(:require
[co.gaiwan.compass.db :as db]
[datomic.api :as d]))

(db/q
'[:find
[(pull ?e [* {:session/type [*]
:session/location [*]}]) ...]
:where
[?e :session/title]]
(db/db))
(deref
(db/transact [[:db/retractEntity 17592186045468]]))
(user/conn)

45 changes: 26 additions & 19 deletions resources/public/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ body {
background-position: 50% 50%;
}

.sessions-session_actions {
display: flex;
justify-content: flex-end;
width: 100%;
margin-top: var(--size-2);
}

.sessions-session_card {
display: flex;
gap: var(--size-1);
Expand Down Expand Up @@ -219,25 +226,6 @@ body {
display: block;
}

.sessions-session_actions {
display: flex;
justify-content: flex-end;
width: 100%;
margin-top: var(--size-2);
}

.home-filters {
display: flex;
flex-wrap: wrap;
margin-top: var(--size-3);
margin-bottom: var(--size-3);
}

.home-filters button {
font-weight: 400;
flex-grow: 1;
}

.sessions-session_list {
display: grid;
gap: var(--size-3);
Expand Down Expand Up @@ -266,4 +254,23 @@ body {
grid-template-columns: repeat(4, 1fr);
}

}

.sessions-session_form form {
display: grid;
grid-template-columns: 10rem 1fr;
gap: var(--size-2);
}

.home-filters {
display: flex;
flex-wrap: wrap;
gap: var(--size-1);
margin-top: var(--size-3);
margin-bottom: var(--size-3);
}

.home-filters button, .home-filters .btn {
font-weight: 400;
flex-grow: 1;
}
8 changes: 5 additions & 3 deletions resources/public/js/cx.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Additional utilties in the vein of HTMX, driven by HTML element attributes.

addEventListener("DOMContentLoaded", (_) => {
// cx-toggle : CSS class to toggle on click, either on clicked element, or on cx-target
// cx-toggle : CSS class to toggle on click, either on clicked element, or on cx-target
function handle_cx_toggle(e) {
[...(document.querySelectorAll('[cx-toggle]'))].forEach((el) => {
let klass = el.getAttribute('cx-toggle')
let selector = el.getAttribute('cx-target')
let target = selector ? el.closest(selector) : el;
el.addEventListener("click", (_) => target.classList.toggle(klass))
})
});
}
addEventListener("DOMContentLoaded", handle_cx_toggle);
addEventListener("htmx:afterSwap", handle_cx_toggle);
12 changes: 9 additions & 3 deletions src/co/gaiwan/compass/db/schema.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
[:discord/expires-at :instant "Expiration timestamp for the OAuth2 token"]
[:discord/refresh-token :string "Discord OAuth2 refresh-token"]

[:session/title :string "Title of the talk/workshop/activity" :identity]
[:session/subtitle :string "Subtitle of the session, for talks/workshops = speaker names" :identity]
[:session/title :string "Title of the talk/workshop/activity"]
[:session/subtitle :string "Subtitle of the session, for talks/workshops = speaker names"]
[:session/description :string "Full description or abstract"]
[:session/type :ref "Type of the session"]
[:session/organized :ref "User who organizes this session"]
Expand All @@ -31,7 +31,10 @@
[:session.type/name :string "Type of session, e.g. talk, activity"]
[:session.type/color :string "CSS color or var reference used for rendering"]

[:location/name :string "Name of the location" :identity]])
[:location/name :string "Name of the location" :identity]
[:oauth/state-id :uuid "State parameter passed along with the oauth flow" :identity]
[:oauth/redirect-url :string "Location to redirect to after login"]
])

(defn inflate-schema [s]
(for [[ident type doc & flags] s]
Expand All @@ -50,3 +53,6 @@

(defn schema-tx []
(inflate-schema schema))

(comment
(user/reset))
53 changes: 10 additions & 43 deletions src/co/gaiwan/compass/html/home.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,23 @@
"Front page views and components"
{:ornament/prefix "home-"}
(:require
[co.gaiwan.compass.html.graphics :as graphics]
[co.gaiwan.compass.html.sessions :as sessions]
[co.gaiwan.compass.css.tokens :as t :refer :all]
[co.gaiwan.compass.http.oauth :as oauth]
[co.gaiwan.compass.util :as util]
[clojure.datafy :as df]
[java-time.api :as time]
[lambdaisland.ornament :as o]))

(o/defstyled filters :section#filters
:flex :flex-wrap
:flex :flex-wrap :gap-1
:my-3
[:button :font-normal :flex-grow]
([]
[#{:button :.btn} :font-normal :flex-grow]
([all-sessions]
[:<>
[:button "Today"]
[:button "All"]
[:button "Today " (count (filter #(= (time/month-day)
(time/month-day (:session/time %)))
all-sessions))]
[:button "All " (count all-sessions)]
[:button "My Activities"]
[:button "Created By Me"]
[:button "Create An Activity"]
[:a.btn {:href "/sessions/new" :hx-boost "false"} "Create An Activity"]
]))

;; [:div
Expand Down Expand Up @@ -61,36 +59,5 @@
(o/defstyled home :div
([{:keys [user sessions]}]
[:<>
[filters]
[filters sessions]
[sessions/session-list sessions]]))

(comment
[sessions/session-card (sessions/rand-session)]

;; Not in use now
(defn week-day-str [day]
(let [week-days ["Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday"]]
(nth week-days (dec day))))

(defn session-model
"session data from database to frontend
input `x` is a vecotr of
`[session-graph type-keyword location-name]`"
[v]
(let [[session-graph type-keyword location-name] v
{:session/keys [time speaker name capacity organized
duration]} session-graph
{:keys [day-of-week month day-of-month
hour minute]} (df/datafy time)
day-of-week-str (week-day-str day-of-week)
date-str (format "%02d.%02d" day-of-month month)
time-str (format "%02d:%02d" hour minute)]
{:title name
:speaker speaker
:type type-keyword
:organized organized
:day day-of-week-str
:date date-str
:time time-str
:location location-name})))
11 changes: 1 addition & 10 deletions src/co/gaiwan/compass/html/navigation.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,6 @@
[co.gaiwan.compass.http.oauth :as oauth]
[lambdaisland.ornament :as o]))

(defn hx-a
"Use like :a, but uses htmx to only swap out the <main> element, so everything
but the navbar and menu."
[attrs & children]
(into [:a attrs #_(assoc attrs
:hx-target "main" :hx-select "main"
:hx-get (get attrs :href))]
children))

(o/defstyled nav-bar :nav
:flex :items-center
:bg-surface-1
Expand All @@ -24,7 +15,7 @@
([user]
[:<>
[graphics/compass-logo]
[:h1 [hx-a {:href "/"} "Compass"]]
[:h1 [:a {:href "/"} "Compass"]]
[:button {:cx-toggle "menu-open" :cx-target "body"}
[graphics/hamburger]]]))

Expand Down
65 changes: 34 additions & 31 deletions src/co/gaiwan/compass/html/sessions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -121,47 +121,50 @@
;; Create / edit

(o/defstyled session-form :div
[:form :grid {:grid-template-columns "10rem 1fr"} :gap-2]
([params]
[:<>
[:h2 "Create Activity"]
[:form {:method "POST" :action "/sessions"}
[:div
[:label {:for "name"} "Activity Name"]
[:input {:id "name" :name "name" :type "text"}]]
[:label {:for "title"} "Title"]
[:input {:id "title" :name "title" :type "text"}]

[:div
[:label {:for "type"} "Type"]
[:select {:id "type" :name "type"}
[:option {:value "activity"} "activity"]]]
[:label {:for "subtitle"} "Subtitle"]
[:input {:id "subtitle" :name "subtitle" :type "text"}]

[:div
[:label {:for "location"} "Location"]
[:select {:id "location" :name "location"}
[:option {:value "depot-main-stage"} "Het Depot - main stage"]
[:option {:value "depot-bar"} "Het Depot - Bar"]
[:option {:value "hal5-zone-a"} "Hal 5 - zone A"]
[:option {:value "hal5-zone-b"} "Hal 5 - zone B"]
[:option {:value "hal5-hoc-cafe"} "Hal 5 - HoC Café"]
[:option {:value "hal5-foodcourt"} "Hal 5 - Foodcourt"]
[:option {:value "hal5-park"} "Hal 5 - park"]
[:option {:value "hal5-outside-seating"} "Hal 5 - outside seating"]
[:option {:value "hal5-long-table"} "Hal 5 - long table"]]]
[:label {:for "start-time"} "Start Time"]
[:input {:id "start-time" :name "start-time" :type "datetime-local"}]

[:div
[:label {:for "capacity"} "Capacity"]
[:input {:id "capacity" :name "capacity" :type "number"}]]
[:label {:for "end-time"} "End Time"]
[:input {:id "end-time" :name "end-time" :type "datetime-local"}]

[:div
[:label {:for "description"} "Description"]
[:textarea {:id "description" :name "description"}]]
[:label {:for "type"} "Type"]
[:select {:id "type" :name "type"}
[:option {:value "activity"} "activity"]]

[:div
[:label {:for "ticket"} "Requires Ticket?"]
[:input {:id "ticket" :name "ticket-required?" :type "checkbox"}]]
[:label {:for "location"} "Location"]
[:select {:id "location" :name "location"}
[:option {:value "depot-main-stage"} "Het Depot - main stage"]
[:option {:value "depot-bar"} "Het Depot - Bar"]
[:option {:value "hal5-zone-a"} "Hal 5 - zone A"]
[:option {:value "hal5-zone-b"} "Hal 5 - zone B"]
[:option {:value "hal5-hoc-cafe"} "Hal 5 - HoC Café"]
[:option {:value "hal5-foodcourt"} "Hal 5 - Foodcourt"]
[:option {:value "hal5-park"} "Hal 5 - park"]
[:option {:value "hal5-outside-seating"} "Hal 5 - outside seating"]
[:option {:value "hal5-long-table"} "Hal 5 - long table"]]

[:div
[:label {:for "published"} "Published/Visible?"]
[:input {:id "published" :name "published?" :type "checkbox"}]]
[:label {:for "capacity"} "Capacity"]
[:input {:id "capacity" :name "capacity" :type "number" :value 0}]

[:label {:for "description"} "Description"]
[:textarea {:id "description" :name "description"}]

[:label {:for "ticket"} "Requires Ticket?"]
[:input {:id "ticket" :name "ticket-required?" :type "checkbox"}]

[:label {:for "published"} "Published/Visible?"]
[:input {:id "published" :name "published?" :type "checkbox"}]

[:input {:type "submit" :value "Create"}]]]))

30 changes: 20 additions & 10 deletions src/co/gaiwan/compass/http/oauth.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,24 @@
(def discord-oauth-endpoint "https://discord.com/oauth2/authorize")
(def discord-api-endpoint "https://discord.com/api/v10")

(def default-scopes ["email" "identify"])

(defn flow-init-url
([]
(flow-init-url ["email" "identify"]))
([scopes]
(-> (uri/uri discord-oauth-endpoint)
(uri/assoc-query*
{:client_id (config/value :discord/client-id)
:response_type "code"
:redirect_uri (str (config/value :compass/origin) "/oauth2/discord/callback")
:scope (str/join " " scopes)}))))
(flow-init-url nil))
([{:keys [scopes redirect-url]
:or {scopes default-scopes}}]
(let [state (random-uuid)]
(when redirect-url
@(db/transact [{:oauth/state-id state
:oauth/redirect-url redirect-url}]))
(-> (uri/uri discord-oauth-endpoint)
(uri/assoc-query*
{:client_id (config/value :discord/client-id)
:response_type "code"
:redirect_uri (str (config/value :compass/origin) "/oauth2/discord/callback")
:scope (str/join " " scopes)
:state state})))))

;; Add as bot to server
#_
Expand All @@ -47,7 +55,9 @@

(defn GET-callback [{:keys [query-params]}]
(let [code (get query-params "code")
{:keys [status body]} (exchange-code code)]
state (get query-params "state")
{:keys [status body]} (exchange-code code)
redirect-url (:oauth/redirect-url (db/entity [:oauth/state-id (java.util.UUID/fromString state)]))]
(if (not= 200 status)
{:status 302
:headers {"Location" "/"}
Expand All @@ -70,7 +80,7 @@
(def tx-data tx-data)
@(db/transact tx-data )
{:status 302
:headers {"Location" "/"}
:headers {"Location" (or redirect-url "/")}
:flash [:p "You are signed in!"]
:session {:identity user-uuid}}))))

Expand Down
7 changes: 0 additions & 7 deletions src/co/gaiwan/compass/routes/home.clj
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
:sessions (all-sessions {:type "all"
:location "all"})}]})

(defn GET-filters [req]
{:html/body [h/filters]})

(defn GET-conf-sessions [req]
(let [qs-m (uri/query-string->map (:query-string req))]
{:html/head [:title "sessions"]
Expand All @@ -45,9 +42,5 @@
["/"
{:name :index
:get {:handler GET-home}}]
["/show-filters"
{:get {:handler GET-filters-showed}}]
["/hide-filters"
{:get {:handler GET-filters-hidden}}]
["/conf-sessions"
{:get {:handler GET-conf-sessions}}]])
Loading

0 comments on commit 1e4111b

Please sign in to comment.