From 66721dad25ad5125cb6b94d61417d90f56ecb6bf Mon Sep 17 00:00:00 2001 From: Laurence Chen Date: Wed, 4 Sep 2024 17:25:31 +0800 Subject: [PATCH 1/3] add bidirectional connection after scanning QR code --- src/co/gaiwan/compass/routes/profiles.clj | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/co/gaiwan/compass/routes/profiles.clj b/src/co/gaiwan/compass/routes/profiles.clj index e61a8d8..1dc67bf 100644 --- a/src/co/gaiwan/compass/routes/profiles.clj +++ b/src/co/gaiwan/compass/routes/profiles.clj @@ -186,7 +186,9 @@ ;; contact -> A ;; user -> B _ @(db/transact [{:db/id contact-eid - :user/contacts user-eid}])] + :user/contacts user-eid} + {:db/id user-eid + :user/contacts contact-eid}])] (response/redirect "/profile" {:flash "Successfully Saved!"}))) From da47f009e395a6ae2ffdb434e99229592a5a5a11 Mon Sep 17 00:00:00 2001 From: Laurence Chen Date: Wed, 4 Sep 2024 18:08:06 +0800 Subject: [PATCH 2/3] add a little margin to QR code showing --- src/co/gaiwan/compass/routes/profiles.clj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/co/gaiwan/compass/routes/profiles.clj b/src/co/gaiwan/compass/routes/profiles.clj index 1dc67bf..8c67513 100644 --- a/src/co/gaiwan/compass/routes/profiles.clj +++ b/src/co/gaiwan/compass/routes/profiles.clj @@ -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}) From 346b29e053e1b2fe73231d99a9d3bf25304c106f Mon Sep 17 00:00:00 2001 From: Laurence Chen Date: Wed, 4 Sep 2024 20:12:42 +0800 Subject: [PATCH 3/3] add a button to accept invitation --- src/co/gaiwan/compass/routes/profiles.clj | 32 +++++++++++++++-------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/co/gaiwan/compass/routes/profiles.clj b/src/co/gaiwan/compass/routes/profiles.clj index 8c67513..9520f18 100644 --- a/src/co/gaiwan/compass/routes/profiles.clj +++ b/src/co/gaiwan/compass/routes/profiles.clj @@ -158,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")))) @@ -172,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 @@ -190,8 +199,8 @@ :user/contacts user-eid} {:db/id user-eid :user/contacts contact-eid}])] - (response/redirect "/profile" - {:flash "Successfully Saved!"}))) + {:location :contact/add + :hx/trigger "contact-added"})) (defn routes [] [["/profile" @@ -219,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}}]]])