mirror of
https://github.com/penpot/penpot.git
synced 2025-01-25 07:58:49 -05:00
Add profile photo uploading support.
This commit is contained in:
parent
4b0c8cec07
commit
2df37e3ba2
5 changed files with 69 additions and 10 deletions
|
@ -106,7 +106,7 @@
|
||||||
(rx/of)))]
|
(rx/of)))]
|
||||||
(let [params {:old-password (:old-password data)
|
(let [params {:old-password (:old-password data)
|
||||||
:password (:password-1 data)}]
|
:password (:password-1 data)}]
|
||||||
(->> (rp/req :update/password params)
|
(->> (rp/req :update/profile-password params)
|
||||||
(rx/map password-updated)
|
(rx/map password-updated)
|
||||||
(rx/catch rp/client-error? on-error))))))
|
(rx/catch rp/client-error? on-error))))))
|
||||||
|
|
||||||
|
@ -122,3 +122,18 @@
|
||||||
(if errors
|
(if errors
|
||||||
(udf/assign-errors :profile/password errors)
|
(udf/assign-errors :profile/password errors)
|
||||||
(UpdatePassword. data))))
|
(UpdatePassword. data))))
|
||||||
|
|
||||||
|
;; --- Update Photo
|
||||||
|
|
||||||
|
(defrecord UpdatePhoto [file done]
|
||||||
|
rs/WatchEvent
|
||||||
|
(-apply-watch [_ state stream]
|
||||||
|
(->> (rp/req :update/profile-photo {:file file})
|
||||||
|
(rx/do done)
|
||||||
|
(rx/map fetch-profile))))
|
||||||
|
|
||||||
|
(defn update-photo
|
||||||
|
([file]
|
||||||
|
(UpdatePhoto. file (constantly nil)))
|
||||||
|
([file done]
|
||||||
|
(UpdatePhoto. file done)))
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
(rx/map decode-payload))))
|
(rx/map decode-payload))))
|
||||||
|
|
||||||
(defmethod request :update/profile
|
(defmethod request :update/profile
|
||||||
[type {:keys [metadata id] :as body}]
|
[type {:keys [metadata] :as body}]
|
||||||
(let [body (assoc body :metadata (t/encode metadata))
|
(let [body (assoc body :metadata (t/encode metadata))
|
||||||
params {:url (str url "/profile/me")
|
params {:url (str url "/profile/me")
|
||||||
:method :put
|
:method :put
|
||||||
|
@ -32,9 +32,18 @@
|
||||||
(->> (send! params)
|
(->> (send! params)
|
||||||
(rx/map decode-payload))))
|
(rx/map decode-payload))))
|
||||||
|
|
||||||
(defmethod request :update/password
|
(defmethod request :update/profile-password
|
||||||
[type data]
|
[type data]
|
||||||
(let [params {:url (str url "/profile/me/password")
|
(let [params {:url (str url "/profile/me/password")
|
||||||
:method :put
|
:method :put
|
||||||
:body data}]
|
:body data}]
|
||||||
(send! params)))
|
(send! params)))
|
||||||
|
|
||||||
|
(defmethod request :update/profile-photo
|
||||||
|
[_ {:keys [file] :as body}]
|
||||||
|
(let [body (doto (js/FormData.)
|
||||||
|
(.append "file" file))
|
||||||
|
params {:url (str url "/profile/me/photo")
|
||||||
|
:method :post
|
||||||
|
:body body}]
|
||||||
|
(send! params)))
|
||||||
|
|
|
@ -21,9 +21,10 @@
|
||||||
[uxbox.ui.messages :as uum]
|
[uxbox.ui.messages :as uum]
|
||||||
[uxbox.data.users :as udu]
|
[uxbox.data.users :as udu]
|
||||||
[uxbox.data.forms :as udf]
|
[uxbox.data.forms :as udf]
|
||||||
|
[uxbox.util.interop :refer (iterable->seq)]
|
||||||
[uxbox.util.dom :as dom]))
|
[uxbox.util.dom :as dom]))
|
||||||
|
|
||||||
;; --- Profile Form
|
;; --- Constants
|
||||||
|
|
||||||
(def formdata
|
(def formdata
|
||||||
(-> (l/in [:forms :profile/main])
|
(-> (l/in [:forms :profile/main])
|
||||||
|
@ -117,6 +118,34 @@
|
||||||
:name "profile-form"
|
:name "profile-form"
|
||||||
:mixins [(mx/local) rum/reactive mx/static]}))
|
:mixins [(mx/local) rum/reactive mx/static]}))
|
||||||
|
|
||||||
|
;; --- Profile Photo Form
|
||||||
|
|
||||||
|
(defn- profile-photo-form-render
|
||||||
|
[own]
|
||||||
|
(letfn [(on-change [event]
|
||||||
|
(let [target (dom/get-target event)
|
||||||
|
file (-> (dom/get-files target)
|
||||||
|
(iterable->seq)
|
||||||
|
(first))]
|
||||||
|
(rs/emit! (udu/update-photo file))
|
||||||
|
(dom/clean-value! target)))]
|
||||||
|
(let [{:keys [photo]} (rum/react profile-l)
|
||||||
|
photo (if (str/empty? photo)
|
||||||
|
"images/avatar.jpg"
|
||||||
|
photo)]
|
||||||
|
(html
|
||||||
|
[:form.avatar-form
|
||||||
|
[:img {:src photo :border "0"}]
|
||||||
|
[:input {:type "file"
|
||||||
|
:value ""
|
||||||
|
:on-change on-change}]]))))
|
||||||
|
|
||||||
|
(def profile-photo-form
|
||||||
|
(mx/component
|
||||||
|
{:render profile-photo-form-render
|
||||||
|
:name profile-photo-form
|
||||||
|
:mixins [mx/static rum/reactive]}))
|
||||||
|
|
||||||
;; --- Profile Page
|
;; --- Profile Page
|
||||||
|
|
||||||
(defn profile-page-render
|
(defn profile-page-render
|
||||||
|
@ -128,9 +157,7 @@
|
||||||
[:section.dashboard-content.user-settings
|
[:section.dashboard-content.user-settings
|
||||||
[:section.user-settings-content
|
[:section.user-settings-content
|
||||||
[:span.user-settings-label "Your avatar"]
|
[:span.user-settings-label "Your avatar"]
|
||||||
[:form.avatar-form
|
(profile-photo-form)
|
||||||
[:img {:src "images/avatar.jpg" :border "0"}]
|
|
||||||
[:input {:type "file"}]]
|
|
||||||
(profile-form)
|
(profile-form)
|
||||||
]]]))
|
]]]))
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
(ns uxbox.ui.users
|
(ns uxbox.ui.users
|
||||||
(:require [sablono.core :as html :refer-macros [html]]
|
(:require [sablono.core :as html :refer-macros [html]]
|
||||||
|
[cuerdas.core :as str]
|
||||||
[lentes.core :as l]
|
[lentes.core :as l]
|
||||||
[rum.core :as rum]
|
[rum.core :as rum]
|
||||||
[uxbox.router :as r]
|
[uxbox.router :as r]
|
||||||
|
@ -56,13 +57,16 @@
|
||||||
(defn user-render
|
(defn user-render
|
||||||
[own]
|
[own]
|
||||||
(let [profile (rum/react profile-l)
|
(let [profile (rum/react profile-l)
|
||||||
local (:rum/local own)]
|
local (:rum/local own)
|
||||||
|
photo (if (str/empty? (:photo profile))
|
||||||
|
"/images/avatar.jpg"
|
||||||
|
(:photo profile))]
|
||||||
|
|
||||||
(html
|
(html
|
||||||
[:div.user-zone {:on-mouse-enter #(swap! local assoc :open true)
|
[:div.user-zone {:on-mouse-enter #(swap! local assoc :open true)
|
||||||
:on-mouse-leave #(swap! local assoc :open false)}
|
:on-mouse-leave #(swap! local assoc :open false)}
|
||||||
[:span (:fullname profile)]
|
[:span (:fullname profile)]
|
||||||
[:img {:border "0"
|
[:img {:border "0" :src photo}]
|
||||||
:src "/images/avatar.jpg"}]
|
|
||||||
(user-menu (:open @local))])))
|
(user-menu (:open @local))])))
|
||||||
|
|
||||||
(def user
|
(def user
|
||||||
|
|
|
@ -66,6 +66,10 @@
|
||||||
[node]
|
[node]
|
||||||
(.-checked node))
|
(.-checked node))
|
||||||
|
|
||||||
|
(defn clean-value!
|
||||||
|
[node]
|
||||||
|
(set! (.-value node) ""))
|
||||||
|
|
||||||
(defn ^boolean equals?
|
(defn ^boolean equals?
|
||||||
[node-a node-b]
|
[node-a node-b]
|
||||||
(.isEqualNode node-a node-b))
|
(.isEqualNode node-a node-b))
|
||||||
|
|
Loading…
Add table
Reference in a new issue