diff --git a/repl-sessions/revoke.clj b/repl-sessions/revoke.clj index 435fc55..bc74729 100644 --- a/repl-sessions/revoke.clj +++ b/repl-sessions/revoke.clj @@ -33,11 +33,17 @@ (concat (mapv (fn [x] - {:db/id (str "temp-" x) - :user/contacts eid - :discord/email (str "temp-email-" x "@gaiwan.co") - :public-profile/name (str "temp-user-" x) - :public-profile/avatar-url (assets/download-image (str avatar-url-part x ".png"))}) + (cond-> {:db/id (str "temp-" x) + :user/uuid (random-uuid) + :user/contacts eid + :discord/email (str "temp-email-" x "@gaiwan.co") + :public-profile/name (str "temp-user-" x) + :public-profile/bio "public bio ... " + :public-profile/avatar-url (assets/download-image (str avatar-url-part x ".png"))} + (even? x) + (assoc :private-profile/name "private-name") + (even? x) + (assoc :private-profile/bio "private bio ..."))) (range 1 11)) (mapv (fn [x] @@ -46,6 +52,6 @@ (range 1 11))))) (def tx (temp-user-tx - (test-user-eid "Arne"))) + (test-user-eid "Laurence"))) (db/transact tx) diff --git a/src/co/gaiwan/compass/db/queries.clj b/src/co/gaiwan/compass/db/queries.clj index 157d894..ee3eae7 100644 --- a/src/co/gaiwan/compass/db/queries.clj +++ b/src/co/gaiwan/compass/db/queries.clj @@ -5,6 +5,20 @@ #_(set! *print-namespace-maps* false) +(defn contact-data + "return the exported version of the contact + + the input eid is the contact's eid" + [eid] + (db/pull '[:public-profile/name + :pubilc-profile/avatar-url + :public-profile/bio + :private-profile/name + :private-profile/bio + {:public-profile/links [:profile-link/type :profile-link/href]} + {:private-profile/links [:profile-link/type :profile-link/href]}] + eid)) + (defn ?resolve-ident "Maybe resolve ident diff --git a/src/co/gaiwan/compass/html/contacts.clj b/src/co/gaiwan/compass/html/contacts.clj index 85e8997..d968057 100644 --- a/src/co/gaiwan/compass/html/contacts.clj +++ b/src/co/gaiwan/compass/html/contacts.clj @@ -7,6 +7,7 @@ [co.gaiwan.compass.html.graphics :as graphics] [co.gaiwan.compass.http.routing :refer [url-for]] [co.gaiwan.compass.model.user :as user] + [co.gaiwan.compass.db.queries :as queries] [lambdaisland.ornament :as o] [markdown-to-hiccup.core :as m])) @@ -41,8 +42,9 @@ [:textarea (m/md->hiccup bio)])]])) (o/defstyled contact-detail :div - [:.heading :flex :justify-between - :mb-3] + [:.heading :flex :justify-between :mb-3] + [:.control :flex :items-center + [:button :ml-4]] [:.contact-list :w-full :ga-4] [:.remove-btn :cursor-pointer :border-none {:background-color t/--surface-3}] [:.remove-btn @@ -63,9 +65,12 @@ [:<> [:div.heading [:h2 "Your Contacts"] - [:button {:hx-target "#modal" - :hx-get (url-for :contact/qr)} - [graphics/scan-icon] "Add Contact"]] + [:div.control + [:button {:on-click "downloadEDN(event)"} + "Export Contacts"] + [:button {:hx-target "#modal" + :hx-get (url-for :contact/qr)} + [graphics/scan-icon] "Add Contact"]]] [:div [:a {:href (url-for :contacts/index) @@ -76,7 +81,45 @@ [:div.contact [c/image-frame {:profile/image (user/avatar-css-value c)}] [:div.details - [:div.profile-name (:public-profile/name c)] - [:div.email (:discord/email c)]] + [:div.profile-name [:a {:href (url-for :profile/show {:user-uuid (:user/uuid c)})} + (if (:private-profile/name c) + (:private-profile/name c) + (:public-profile/name c))]] + [:div.bio (when (:private-profile/bio c) + (m/component (m/md->hiccup (:private-profile/bio c))))]] [:button.remove-btn {:hx-delete (url-for :contact/link {:id (:db/id c)})} - [graphics/person-remove] "Remove"]])]]])) + [graphics/person-remove] "Remove"]])]] + [:div#edn {:style {:display "none"}} + (for [c (:user/contacts user)] + (let [eid (:db/id c) + contact-data (queries/contact-data eid)] + (pr-str contact-data)))] + [:script + "function downloadEDN(event) { + event.preventDefault(); // prevent the default button behavior + + var data = document.getElementById('edn').innerHTML; + data = '[' + data + ']'; + var blob = new Blob([data], { type: 'text/edn' }); + var url = window.URL.createObjectURL(blob); + + // Create a temporary anchor element to download the CSV + var a = document.createElement('a'); + a.href = url; + a.download = 'data.edn'; + document.body.appendChild(a); + a.click(); + + // Cleanup + document.body.removeChild(a); + window.URL.revokeObjectURL(url); + };"]])) + +(comment + (require '[co.gaiwan.compass.db :as db]) + + (def eid 17592186045516) + (queries/contact-data eid) + (def user (db/entity eid)) + (def c (:user/contacts user)) + (pr-str c))