Skip to content

Commit

Permalink
Merge pull request #33 from GaiwanTeam/laurence/bidirection-contact-a…
Browse files Browse the repository at this point in the history
…fter-QR-code

bidirection contacts added after scanning QR code
  • Loading branch information
humorless authored Sep 4, 2024
2 parents d95677b + 346b29e commit 0f241c8
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions src/co/gaiwan/compass/routes/profiles.clj
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@

(defn GET-qr-html [req]
{:html/body [:div
{:style {:margin "var(--size-4)"}}
[:h2 "Add Contact"]
[:img {:src (url-for :contact/qr-png)}]]
:html/layout false})
Expand All @@ -157,8 +158,8 @@
[{:keys [identity] :as req}]
(let [user-eid (:db/id identity)
host (config/value :compass/origin)
qr-hash (eid->qr-hash user-eid)
url (str host "/attendees/" qr-hash)
qr-hash (str (eid->qr-hash user-eid))
url (str host (url-for :contact/add {:qr-hash qr-hash}))
qr-image (qr/as-bytes (qr/from url :size [400 400]))]
(-> (ring-response/response qr-image)
(assoc-in [:headers "content-type"] "image/png"))))
Expand All @@ -171,8 +172,17 @@
(for [atd (attendees/user-list attendees)]
(h/attendee-card atd))]}))

(defn GET-contact [req]
{:html/body [:button {:hx-post (url-for :contact/add {:uuid "123"})}]})
(defn GET-contact
[req]
{:html/body
[:div
[:a
{:href (url-for :profile/index)
:style {:display "none"}
:hx-trigger "contact-added from:body"}]
[:button
{:hx-post (url-for :contact/add {:qr-hash (get-in req [:path-params :qr-hash])})}
(str "Accept invite")]]})

(defn POST-contact
"Part of the url is hash of the contact's user eid
Expand All @@ -186,9 +196,11 @@
;; contact -> A
;; user -> B
_ @(db/transact [{:db/id contact-eid
:user/contacts user-eid}])]
(response/redirect "/profile"
{:flash "Successfully Saved!"})))
:user/contacts user-eid}
{:db/id user-eid
:user/contacts contact-eid}])]
{:location :contact/add
:hx/trigger "contact-added"}))

(defn routes []
[["/profile"
Expand Down Expand Up @@ -216,12 +228,13 @@
["/qr" {:name :contact/qr
:get {:handler GET-qr-html}}]
["/qr.png" {:name :contact/qr-png
:get {:handler GET-qr-code}}]]
:get {:handler GET-qr-code}}]
["/:qr-hash"
{:name :contact/add
:post {:handler POST-contact}
:get {:handler GET-contact}}]]
["/attendees"
[""
{:name :attendees/index
:middleware [[response/wrap-requires-auth]]
:get {:handler GET-attendees}}]
["/:qr-hash"
{:middleware [[response/wrap-requires-auth]]
:get {:handler GET-contact}}]]])
:get {:handler GET-attendees}}]]])

0 comments on commit 0f241c8

Please sign in to comment.