From 529607b7d4bd545b7734027fdb7031e921bc1b6a Mon Sep 17 00:00:00 2001 From: Laurence Chen Date: Sun, 15 Sep 2024 21:16:21 +0200 Subject: [PATCH 1/3] show private name if set, link, private bio --- repl-sessions/revoke.clj | 18 ++++++---- src/co/gaiwan/compass/html/contacts.clj | 47 ++++++++++++++++++++----- 2 files changed, 51 insertions(+), 14 deletions(-) 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/html/contacts.clj b/src/co/gaiwan/compass/html/contacts.clj index 85e8997..2aaa7fc 100644 --- a/src/co/gaiwan/compass/html/contacts.clj +++ b/src/co/gaiwan/compass/html/contacts.clj @@ -41,8 +41,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 +64,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 +80,34 @@ [: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) + c (into {} c)] + (pr-str c))] + [:script + "function downloadEDN(event) { + event.preventDefault(); // prevent the default button behavior + + var data = document.getElementById('edn').innerHTML; + 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); + };"]])) From 5a07c0285b9333319c167fb1bf8ed7b781dc381b Mon Sep 17 00:00:00 2001 From: Laurence Chen Date: Sun, 15 Sep 2024 21:28:15 +0200 Subject: [PATCH 2/3] make export contact button works --- src/co/gaiwan/compass/html/contacts.clj | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/co/gaiwan/compass/html/contacts.clj b/src/co/gaiwan/compass/html/contacts.clj index 2aaa7fc..d668a2c 100644 --- a/src/co/gaiwan/compass/html/contacts.clj +++ b/src/co/gaiwan/compass/html/contacts.clj @@ -89,14 +89,17 @@ [:button.remove-btn {:hx-delete (url-for :contact/link {:id (:db/id c)})} [graphics/person-remove] "Remove"]])]] [:div#edn {:style {:display "none"}} - (for [c (:user/contacts user) - c (into {} c)] - (pr-str c))] + (for [c (:user/contacts user)] + (let [c (into {} c) + c (dissoc c :db/id :user/contacts :user/uuid)] + ;; We might want to add the profile-link + (pr-str c)))] [: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); @@ -111,3 +114,10 @@ document.body.removeChild(a); window.URL.revokeObjectURL(url); };"]])) + +(comment + (require '[co.gaiwan.compass.db :as db]) + (def eid 17592186045516) + (def user (db/entity eid)) + (def c (:user/contacts user)) + (pr-str c)) From 71bc62f0f584f623f13a876aaee05ccfa5f8f9ba Mon Sep 17 00:00:00 2001 From: Laurence Chen Date: Sun, 15 Sep 2024 21:45:26 +0200 Subject: [PATCH 3/3] improve the data of export contact --- src/co/gaiwan/compass/db/queries.clj | 14 ++++++++++++++ src/co/gaiwan/compass/html/contacts.clj | 10 ++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) 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 d668a2c..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])) @@ -90,10 +91,9 @@ [graphics/person-remove] "Remove"]])]] [:div#edn {:style {:display "none"}} (for [c (:user/contacts user)] - (let [c (into {} c) - c (dissoc c :db/id :user/contacts :user/uuid)] - ;; We might want to add the profile-link - (pr-str c)))] + (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 @@ -117,7 +117,9 @@ (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))