Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contacts page improvement #44

Merged
merged 3 commits into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions repl-sessions/revoke.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -46,6 +52,6 @@
(range 1 11)))))

(def tx (temp-user-tx
(test-user-eid "Arne")))
(test-user-eid "Laurence")))

(db/transact tx)
14 changes: 14 additions & 0 deletions src/co/gaiwan/compass/db/queries.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
59 changes: 51 additions & 8 deletions src/co/gaiwan/compass/html/contacts.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]))

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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))
Loading