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

Make attendee and profile links good enough #27

Closed
wants to merge 5 commits into from
Closed
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
43 changes: 29 additions & 14 deletions src/co/gaiwan/compass/html/profiles.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,40 @@
(o/defprop --arc-thickness "30px")

(o/defstyled image-frame :div
[:.img :w-full
{:padding --arc-thickness
[:.img :w-100px
{#_#_:padding --arc-thickness
#_#_:margin-left "-100%"}
[:>* :w-full :aspect-square :rounded-full
{:background-size "cover"
:background-position "50% 50%"}]]
([{:profile/keys [image]} user]
([{:profile/keys [image]}]
[:<>
[:div.img
[:div
{:style {:background-image image}}]]]))

;; UI of attendee list

(o/defstyled attendee-card :div
[image-frame :w-100px]
([{:public-profile/keys [name hidden? bio]
:user/keys [uuid] :as user}]
[:<>
[image-frame {:profile/image (user/avatar-css-value user)}]
[:div.details
[:h3 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)]])
(when bio
[:textarea (m/md->hiccup bio)])]]))

;; UI of profile detail

(o/defstyled edit-profile-btn :button
([user]
[:<>
Expand All @@ -38,23 +60,14 @@
([{:public-profile/keys [name]
:user/keys [uuid] :as user}]
[:<>
[image-frame {:profile/image (user/avatar-css-value (:public-profile/avatar-url user))} user]
[image-frame {:profile/image (user/avatar-css-value user)}]
[:div.details
[:h3.title name]]
#_[:div (pr-str user)]
[:div.actions
[edit-profile-btn user]]]))

(o/defstyled attendee-card :div
[image-frame :w-100px]
([{:public-profile/keys [name bio]
:user/keys [uuid] :as user}]
[:<>
[image-frame {:profile/image (user/avatar-css-value (:public-profile/avatar-url user))} user]
[:div.details
[:h3 name]
(when bio
[:textarea (m/md->hiccup bio)])]]))
;; UI of profile form

(o/defstyled private-name :div
([user {:keys [private-name-switch] :as params}]
Expand Down Expand Up @@ -135,6 +148,8 @@
"Show different name to confidantes?"]
[:div.input-block {:id "private-name-block"}]
[:div
(when user
[image-frame {:profile/image (user/avatar-css-value user)}])
[:label {:for "image"} "Avatar"]
[:input {:id "image" :name "image" :type "file" :accept "image/png, image/jpeg"}]]
[:div
Expand Down
36 changes: 20 additions & 16 deletions src/co/gaiwan/compass/routes/profiles.clj
Original file line number Diff line number Diff line change
Expand Up @@ -111,30 +111,34 @@
txes)]
txes))

(defn profile-image-file
(^java.io.File
[profile-eid filename]
(io/file (config/value :uploads/dir) (str profile-eid "_" filename))))

(defn save-uploaded-image
[profile-eid {:keys [filename tempfile]}]
(let [image-file (profile-image-file profile-eid filename)]
(io/make-parents image-file)
(io/copy tempfile image-file)
{:db/id profile-eid
:public-profile/avatar-url (.getName image-file)}))

(defn POST-save-profile
"Save profile to DB

The typical params is like:
{:name \"Arne\"
:tityle \"CEO of Gaiwan\"
:image {:content-type :filename :size :tempfile}}"
[{:keys [params identity] :as req}]
(let [{:keys [filename tempfile] :as image} (:image params)
file-id (str (:db/id identity))
filepath (str (config/value :uploads/dir) "/" file-id "_" filename)
;; creating the transaction
txes (params->profile-data params)
txes (if image
(conj txes
{:db/id (parse-long (:user-id params))
:public-profile/avatar-url (str "/" filepath)})
txes)
_ (tap> {:txes txes})
{:keys [tempids]} @(db/transact txes)]
;; (tap> req)
;; Copy the image file content to the uploads directory
[{:keys [params] {:keys [image]} :params}]
(let [{:keys [tempids]} @(db/transact (params->profile-data params))]
(tap> {:transact-profile true})
(when image
(io/copy tempfile (io/file filepath)))
@(db/transact
[(save-uploaded-image (parse-long (:user-id params)) image)]))
(tap> {:image image
:transact-image true})
(response/redirect "/profile"
{:flash "Successfully Saved!"})))

Expand Down