mirror of
https://github.com/status-im/open-bounty.git
synced 2025-01-11 10:06:20 +00:00
Get user profile
This commit is contained in:
parent
c97627c6cf
commit
e47c25d1ca
@ -29,11 +29,6 @@
|
||||
:title "commitETH API"
|
||||
:description "commitETH API"}}}}
|
||||
|
||||
(GET "/authenticated" []
|
||||
:auth-rules authenticated?
|
||||
:current-user user
|
||||
(ok {:user user}))
|
||||
|
||||
(context "/api" []
|
||||
(POST "/user/address" []
|
||||
:auth-rules authenticated?
|
||||
@ -42,4 +37,8 @@
|
||||
(let [result (users/update-user-address user address)]
|
||||
(if (= 1 result)
|
||||
(ok)
|
||||
(internal-server-error))))))
|
||||
(internal-server-error))))
|
||||
(GET "/user" []
|
||||
:auth-rules authenticated?
|
||||
:current-user user
|
||||
(ok {:user (users/get-user (:login user))}))))
|
||||
|
@ -3,10 +3,11 @@
|
||||
[re-frame.core :as rf]))
|
||||
|
||||
(defn input [{:keys [value-path]}]
|
||||
(let [val (reagent/atom nil)
|
||||
save #(let [v (-> @val str clojure.string/trim)]
|
||||
(when (seq v)
|
||||
(rf/dispatch [:assoc-in value-path v])))]
|
||||
(let [init-val @(rf/subscribe [:get-in value-path])
|
||||
val (reagent/atom init-val)
|
||||
save #(let [v (-> @val str clojure.string/trim)]
|
||||
(when (seq v)
|
||||
(rf/dispatch [:assoc-in value-path v])))]
|
||||
(fn [props]
|
||||
[:input.form-control
|
||||
(merge props {:type "text"
|
||||
|
@ -1,6 +1,6 @@
|
||||
(ns commiteth.db)
|
||||
|
||||
(def default-db
|
||||
{:page :home
|
||||
:user nil
|
||||
:address nil})
|
||||
{:page :home
|
||||
:user nil
|
||||
:user-profile nil})
|
||||
|
@ -21,12 +21,19 @@
|
||||
(reg-event-db
|
||||
:set-active-user
|
||||
(fn [db [_ user]]
|
||||
(dispatch [:load-user-profile])
|
||||
(assoc db :user user)))
|
||||
|
||||
(reg-event-db
|
||||
:set-user-address
|
||||
(fn [db [_ address]]
|
||||
(assoc db :address address)))
|
||||
:load-user-profile
|
||||
(GET "/api/user"
|
||||
{:headers {"Accept" "application/transit+json"}
|
||||
:handler #(dispatch [:set-user-profile %])}))
|
||||
|
||||
(reg-event-db
|
||||
:set-user-profile
|
||||
(fn [db [_ user-profile]]
|
||||
(assoc db :user-profile user-profile)))
|
||||
|
||||
(defn save-user-address [params]
|
||||
(POST "/api/user/address"
|
||||
|
@ -1,6 +1,7 @@
|
||||
(ns commiteth.profile.page
|
||||
(:require [re-frame.core :as rf]
|
||||
[commiteth.common :refer [input]]))
|
||||
[commiteth.common :refer [input]]
|
||||
[commiteth.subscriptions :refer [user-address-path]]))
|
||||
|
||||
(defn save-address
|
||||
[login address]
|
||||
@ -10,12 +11,12 @@
|
||||
(defn address-settings []
|
||||
(let [user (rf/subscribe [:user])
|
||||
login (:login @user)
|
||||
address (rf/subscribe [:address])]
|
||||
address (rf/subscribe [:get-in user-address-path])]
|
||||
(fn []
|
||||
[:div.form-group
|
||||
[:label "Address"]
|
||||
[input {:placeholder "Address"
|
||||
:value-path [:address]}]
|
||||
:value-path user-address-path}]
|
||||
[:button.btn.btn-primary.btn-lg
|
||||
{:on-click (save-address login @address)}
|
||||
"Save"]])))
|
||||
|
@ -12,6 +12,8 @@
|
||||
(:user db)))
|
||||
|
||||
(reg-sub
|
||||
:address
|
||||
(fn [db _]
|
||||
(:address db)))
|
||||
:get-in
|
||||
(fn [db [_ path] ]
|
||||
(get-in db path)))
|
||||
|
||||
(def user-address-path [:user-profile :user :address])
|
||||
|
Loading…
x
Reference in New Issue
Block a user