From 9157df2b86124ff1bca7f418438b423f50b74f86 Mon Sep 17 00:00:00 2001 From: Laurence Chen Date: Thu, 1 Aug 2024 16:27:38 +0800 Subject: [PATCH] let the session-card's participate/leave change using the POST -> evt -> GET --- src/co/gaiwan/compass/html/sessions.clj | 9 +++++---- src/co/gaiwan/compass/routes/sessions.clj | 10 +++++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/co/gaiwan/compass/html/sessions.clj b/src/co/gaiwan/compass/html/sessions.clj index 9efb9c7..4fcbd0f 100644 --- a/src/co/gaiwan/compass/html/sessions.clj +++ b/src/co/gaiwan/compass/html/sessions.clj @@ -60,9 +60,6 @@ ([session user] [:<> [:button {:hx-post (str "/sessions/" (:db/id session) "/participate") - :hx-target (str "closest ." session-card) - :hx-select (str "." session-card) - :hx-swap "outerHTML" :on-click "event.stopPropagation()" :hx-indicator (str ".c" (:db/id session))} (if (session/participating? session user) @@ -108,7 +105,11 @@ capacity signup-count] :as session} user] [:<> - {:style {--session-type-color (:session.type/color type)} + {:hx-get (str "/sessions/" (:db/id session) "/card") + :hx-trigger (str "session-" (:db/id session) "-updated from:body") + :hx-target (str "closest ." session-card) + :hx-select (str "." session-card " > *") + :style {--session-type-color (:session.type/color type)} :cx-toggle "expanded" :cx-target (str "." session-card)} [:div.type (:session.type/name type)] diff --git a/src/co/gaiwan/compass/routes/sessions.clj b/src/co/gaiwan/compass/routes/sessions.clj index dc731e3..1f2c292 100644 --- a/src/co/gaiwan/compass/routes/sessions.clj +++ b/src/co/gaiwan/compass/routes/sessions.clj @@ -28,6 +28,12 @@ (db/entity session-eid) (:identity req)]})) +(defn GET-session-card [req] + (let [session-eid (parse-long (get-in req [:path-params :id]))] + {:html/body [h/session-card + (db/entity session-eid) + (:identity req)]})) + (defn duration-string-to-iso8601 "Convert \"03:00\" to iso8601 format \"PT3H\" " [duration-str] @@ -130,4 +136,6 @@ (new-session req) (GET-session req)))}}] ["/:id/participate" - {:post {:handler participate-session}}]]) + {:post {:handler participate-session}}] + ["/:id/card" + {:get {:handler GET-session-card}}]])