Skip to content

Commit

Permalink
Does only return partial html
Browse files Browse the repository at this point in the history
  • Loading branch information
MTrost committed Jul 26, 2024
1 parent 74c7fb9 commit 0aaea78
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/co/gaiwan/compass/html/sessions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
[:<>
[:button {:hx-post (str "/sessions/" (:db/id session) "/participate")
:hx-target (str "closest ." session-card)
:hx-select (str "." session-card)
:hx-swap "outerHTML"}
"Participate"]
[:a {:href (str "/sessions/" (:db/id session))}
Expand Down
21 changes: 14 additions & 7 deletions src/co/gaiwan/compass/routes/sessions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,15 @@
:published? \"on\"}"
[{:keys [params]}]
(let [{:keys [tempids]} @(db/transact [(params->session-data params)])]
(def tempids tempids)
(util/redirect ["/sessions" (get tempids "session")]
{:flash "Successfully created!"})))

(defn just-the-body [{:keys [body]}] body)

(defn session-card-response [session user]
{:html/layout just-the-body
:html/body [h/session-card session user]})

(defn participate-session
""
[req]
Expand All @@ -78,28 +83,30 @@
(do
(let [user-id (:db/id user)
session-eid (parse-long (get-in req [:path-params :id]))
session (db/entity session-eid)
session-seletor '[* {:session/type [*]
:session/location [*]}]
pull-session #(db/pull session-seletor session-eid)
session (pull-session)
participants (->> session
:session/participants
(map :db/id)
set)
capacity (:session/capacity session)
signup-cnt (:session/signup-count session)
session-selector '[* {:session/type [*]
:session/location [*]}]]
]
(cond
(participants user-id)
(do @(db/transact [[:db/cas session-eid :session/signup-count signup-cnt (dec signup-cnt)]
[:db/retract session-eid :session/participants user-id]])
{:html/body [h/session-card (db/pull session-selector session-eid) user]})
(session-card-response (pull-session) user))
(< (or signup-cnt 0) capacity)
(do
;;TODO: add try/catch to handle :db/cas
@(db/transact [[:db/cas session-eid :session/signup-count signup-cnt ((fnil inc 0) signup-cnt)]
[:db/add session-eid :session/participants user-id]])
{:html/body [h/session-card (db/pull session-selector session-eid) user]})
(session-card-response (pull-session) user))
:else
{:html/body [h/session-card session user]}))
(session-card-response session user)))
#_{:html/body (pr-str (db/entity (parse-long (get-in req [:path-params :id]))))})
(util/redirect (oauth/flow-init-url {:redirect-url (str "/sessions/" (get-in req [:path-params :id]) "/participate")}))))

Expand Down

0 comments on commit 0aaea78

Please sign in to comment.