Skip to content

Commit

Permalink
Show qr code in modal
Browse files Browse the repository at this point in the history
  • Loading branch information
plexus committed Sep 3, 2024
1 parent da516c4 commit e5a5af3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/co/gaiwan/compass/html/navigation.clj
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,14 @@
;; "/attendees" "Attendees"
;; "/profile" "Profile & Settings"
"/sessions/new" "Create Activity"
"/contact" "Add Contact"}]
}]
[:li [:a {:href href
:on-click "document.body.classList.toggle('menu-open')"}
caption]])]]))
caption]])]
[:li [:a {:href (url-for :contact/qr)
:hx-target "#modal"
:on-click "document.body.classList.toggle('menu-open')"}
"Add Contact"]]]))

(o/defrules toggle-menu-button)

Expand Down
23 changes: 18 additions & 5 deletions src/co/gaiwan/compass/routes/profiles.clj
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
(ns co.gaiwan.compass.routes.profiles
"We need a page/route for user's profile"
(:require
[clj.qrgen :as qr]
[clojure.java.io :as io]
[clojure.string :as str]
[co.gaiwan.compass.config :as config]
[co.gaiwan.compass.db :as db]
[co.gaiwan.compass.db.queries :as q]
[co.gaiwan.compass.html.profiles :as h]
[co.gaiwan.compass.http.response :as response]
[co.gaiwan.compass.http.routing :refer [url-for]]
[co.gaiwan.compass.model.assets :as assets]
[co.gaiwan.compass.model.attendees :as attendees]
[clj.qrgen :as qr]
[ring.util.response :as ring-response]))

(defn GET-profile [req]
Expand Down Expand Up @@ -146,13 +147,19 @@
[?e :user/hash ?hash]]
(db/db) qr-hash))

(defn GET-qr-html [req]
{:html/body [:div
[:h2 "Add Contact"]
[:img {:src (url-for :contact/qr-png)}]]
:html/layout false})

(defn GET-qr-code
[{: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-image (qr/as-bytes (qr/from url))]
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 @@ -164,7 +171,10 @@
(for [atd (attendees/user-list attendees)]
(h/attendee-card atd))]}))

(defn GET-contact
(defn GET-contact [req]
{:html/body [:button {:hx-post (url-for :contact/add {:uuid "123"})}]})

(defn POST-contact
"Part of the url is hash of the contact's user eid
Decode it and add that contact"
[{:keys [identity] :as req}]
Expand Down Expand Up @@ -200,8 +210,11 @@
{:middleware [[response/wrap-requires-auth]]
:get {:handler file-handler}}]
["/contact"
{:middleware [[response/wrap-requires-auth]]
:get {:handler GET-qr-code}}]
{:middleware [[response/wrap-requires-auth]]}
["/qr" {:name :contact/qr
:get {:handler GET-qr-html}}]
["/qr.png" {:name :contact/qr-png
:get {:handler GET-qr-code}}]]
["/attendees"
[""
{:middleware [[response/wrap-requires-auth]]
Expand Down

0 comments on commit e5a5af3

Please sign in to comment.