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

Laurence/issue 40 new #43

Merged
merged 6 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
21 changes: 20 additions & 1 deletion repl-sessions/participants.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,21 @@
[co.gaiwan.compass.model.assets :as assets]
[datomic.api :as d]))

(defn test-user-eid
"Query the database to find out a certain login by discord user"
[user-name]
(db/q
'[:find ?e .
:in $ ?u
:where
[?e :public-profile/name ?u]]
(db/db) user-name))

(def user-eid
(test-user-eid "Laurence"))

(def new-session-eid
17592186045520)
17592186045455)
;; Avatar source URL https://github.com/alohe/avatars
(defn temp-user-tx
" Create the user txes
Expand All @@ -26,8 +39,14 @@
(mapv
(fn [x]
{:db/id (str "temp-" x)
:user/uuid (random-uuid)
:user/contacts user-eid
:discord/email (str "temp-email-" x "@gaiwan.co")
:public-profile/hidden? (if (even? x) true false)
:public-profile/name (str "temp-user-" x)
:public-profile/bio "problic-bio"
:private-profile/bio "private-bio"
:private-profile/name "private-name"
:public-profile/avatar-url (assets/download-image (str avatar-url-part x ".png"))})
(range 1 11))
;; Below is for session join
Expand Down
55 changes: 39 additions & 16 deletions src/co/gaiwan/compass/html/profiles.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[co.gaiwan.compass.html.components :as c]
[co.gaiwan.compass.http.routing :refer [url-for]]
[co.gaiwan.compass.model.user :as user]
[markdown-to-hiccup.core :as m]
[lambdaisland.ornament :as o]))

;; UI of profile detail
Expand All @@ -18,24 +19,47 @@

(o/defstyled profile-detail :div#detail
[c/image-frame :w-100px {t/--arc-thickness "7%"}]
[:.details
[:.bio :mt-2]
[:.links :my-2]
[:.link :w-full :flex :flex-1 :py-1 :font-size-3]
[:.link-type :w-12 :px-2]
[:.link-ref :flex-grow :px-2]]
[:.contact-card :my-6 :shadow-3
{:background-color t/--surface-2
:padding t/--size-3
:border-radius t/--size-2}]
([{:public-profile/keys [name hidden?]
:user/keys [uuid] :as user}]
:user/keys [uuid] :as user} viewer]
[:<>
[:div [c/image-frame {:profile/image (user/avatar-css-value user)}]]
[:div.details
[:h3.title name]]
(if hidden?
[:label "Hide profile from public listing"]
[:label "Show profile from public listing"])
(when (:private-profile/name user)
[:div
[:label "Another Name:"]
[:label (:private-profile/name user)]])

#_[:div (pr-str user)]
;; Disable Edit Profile before we can show profile details pretty
[:div.actions
[edit-profile-btn user]]]))
[:h3.title name]
(when (:public-profile/bio user)
[:div.bio
(m/component (m/md->hiccup (:public-profile/bio user)))])
[:div.links
(for [link (:public-profile/links user)]
[:div.link
[:div.link-type (:profile-link/type link)]
[:div.link-ref (:profile-link/href link)]])]]
;; if the user is connected (contact), show "contact card"
(when (some #{(:db/id viewer)} (map :db/id (:user/contacts user)))
[:div.contact-card
[:div.details
[:h3.title (:private-profile/name user)]
(when (:private-profile/bio user)
[:div.bio
(m/component (m/md->hiccup (:private-profile/bio user)))])
[:div.links
(for [link (:private-profile/links user)]
[:div.link
[:div.link-type (:profile-link/type link)]
[:div.link-ref (:profile-link/href link)]])]]])
;; hide edit button unless it's your own profile
(when (= (:db/id viewer) (:db/id user))
[:div.actions
[edit-profile-btn user]])]))

(o/defstyled private-name :div
([user {:keys [private-name-switch] :as params}]
Expand Down Expand Up @@ -158,8 +182,7 @@
(:private-profile/bio user))]]
[links-table (:private-profile/links user)
{:variant "private"
:caption "Links Visible to Contacts"}]
]
:caption "Links Visible to Contacts"}]]

[:input {:type "submit" :value "Save Profile"}]]
[:script
Expand Down
23 changes: 15 additions & 8 deletions src/co/gaiwan/compass/html/sessions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@
["0%, 100%" {:opacity 1}]
["50%" {:opacity 0.5}]))

(o/defstyled handle-the-hidden :div
([participants]
(let [hiddens (count (filter #(:public-profile/hidden? %) participants))]
(when (pos? hiddens)
(str "and " hiddens " more")))))

(o/defstyled attendee :div
:flex :items-center :my-2 :py-2
:shadow-2 :font-size-3
Expand All @@ -192,7 +198,8 @@
[:<>
[c/image-frame {:profile/image (user/avatar-css-value p)}]
[:div.details
[:div.profile-name (:public-profile/name p)]]]))
[:a {:href (url-for :profile/show {:user-uuid (:user/uuid p)})}
[:div.profile-name (:public-profile/name p)]]]]))

(o/defstyled session-detail :div
[capacity-gauge :w-100px]
Expand Down Expand Up @@ -282,13 +289,13 @@
(if (:session/ticket-required? session)
[:p.large "YES ✅"]
[:p.large "NO ❎"])]]
(when (session/organizing? session user)
;; Only show the participants' list to organizer.
[:div.participants
[:h3 "Participants"]
#_(pr-str participants)
(for [p participants]
[attendee p])])
#_(when (session/organizing? session user))
[:div.participants
[:h3 "Participants"]
(for [p participants]
(when-not (:public-profile/hidden? p)
[attendee p]))
[handle-the-hidden participants]]

[:div.actions

Expand Down
14 changes: 8 additions & 6 deletions src/co/gaiwan/compass/routes/profiles.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[clj.qrgen :as qr]
[clojure.java.io :as io]
[clojure.string :as str]
[io.pedestal.log :as log]
[co.gaiwan.compass.config :as config]
[co.gaiwan.compass.db :as db]
[co.gaiwan.compass.db.queries :as q]
Expand All @@ -12,14 +13,16 @@
[co.gaiwan.compass.http.routing :refer [url-for]]
[co.gaiwan.compass.model.assets :as assets]
[co.gaiwan.compass.model.attendees :as attendees]

[ring.util.response :as ring-response]))

(defn GET-profile [{:keys [params] :as req}]
;; (log/debug :debug {:req req})
{:html/body
[h/profile-detail
(if-let [user-uuid (:user-uuid params)]
(db/entity [:user/uuid user-uuid])
(:identity req))]})
(if-let [profile-id (get-in req [:path-params :user-uuid])]
(db/entity [:user/uuid (parse-uuid profile-id)])
(:identity req)) (:identity req)]})

(defn GET-profile-form [req]
{:html/body [h/profile-form
Expand Down Expand Up @@ -90,7 +93,7 @@
(defn parse-link-data [params variant]
(map vector
(get params (keyword (str variant "-link-type")))
(get params (keyword (str variant "-link-ref")))) )
(get params (keyword (str variant "-link-ref")))))

(defn reconcile-links [user-id variant old-links new-links]
(let [existing-pairs (map (juxt :profile-link/type :profile-link/href) old-links)
Expand Down Expand Up @@ -149,8 +152,7 @@
(conj [:db/retract user-id :private-profile/name (:private-profile/name user)])

(not (str/blank? name_private))
(conj [:db/add user-id :private-profile/name name_private])
)))
(conj [:db/add user-id :private-profile/name name_private]))))

(defn POST-save-profile
"Save profile to DB
Expand Down
Loading