193 UI updated

This commit is contained in:
Ivan Grishaev 2018-02-06 19:58:39 +03:00
parent 8937816a8c
commit 2b7dff9648
2 changed files with 27 additions and 37 deletions

View File

@ -62,6 +62,10 @@
(fn [db [_ path value]]
(assoc-in db path value)))
(reg-event-db
:update-in
(fn [db [_ path func & args]]
(apply update-in db path func args)))
(reg-event-db
:set-active-page
@ -311,48 +315,35 @@
{:db db
:dispatch [:set-active-page :update-address]}))
(reg-event-fx
:save-user-address
(fn [{:keys [db]} [_ user-id address]]
(prn "save-user-address" user-id address)
{:db (assoc db :updating-address true)
:http {:method POST
:url "/api/user/address"
:on-success #(do
(dispatch [:assoc-in [:user :address] address])
(dispatch [:set-flash-message
:success
"Address saved"]))
:on-error #(do
(println %)
(dispatch [:set-flash-message
:error
(:response %)]))
:finally #(dispatch [:clear-updating-address])
:params {:user-id user-id :address address}}}))
(reg-event-fx
:mark-user-hidden
(fn [{:keys [db]} [_ user-id hidden]]
{:http {:method POST
:url "/api/user/hidden"
:save-user-fields
(fn [{:keys [db]} [_ user-id fields]]
(prn (merge {:user-id user-id} fields))
{:dispatch [:set-updating-user]
:http {:method POST
:url "/api/user"
:on-success #(do
(dispatch [:assoc-in [:user :is_hidden] hidden])
(dispatch [:update-in [:user] merge fields])
(dispatch [:set-flash-message
:success
"Settings saved"]))
:on-error #(do
(dispatch [:set-flash-message
:error (:response %)]))
:params {:user-id user-id :hidden hidden}}}))
:on-error #(dispatch [:set-flash-message
:error
(:response %)])
:finally #(dispatch [:clear-updating-user])
:params (merge {:user-id user-id} fields)}}))
(reg-event-db
:clear-updating-address
:set-updating-user
(fn [db _]
(dissoc db :updating-address)))
(assoc db :updating-user true)))
(reg-event-db
:clear-updating-user
(fn [db _]
(dissoc db :updating-user)))
(reg-event-fx
:save-payout-hash

View File

@ -8,7 +8,7 @@
(defn update-address-page []
(let [db (rf/subscribe [:db])
user (rf/subscribe [:user])
updating-address (rf/subscribe [:get-in [:updating-address]])
updating-user (rf/subscribe [:get-in [:updating-user]])
address (r/atom @(rf/subscribe [:get-in [:user :address]]))
hidden (rf/subscribe [:get-in [:user :is_hidden]])]
@ -35,11 +35,9 @@
:max-length 42}]])]
[:button
(merge {:on-click
#(rf/dispatch [:save-user-address
(:id @user)
@address])
#(rf/dispatch [:save-user-fields (:id @user) {:address @address}])
:class (str "ui button small update-address-button"
(when @updating-address
(when @updating-user
" busy loading"))})
"UPDATE"]
@ -48,11 +46,12 @@
[:input
{:type :checkbox
:disabled @updating-user
:id :input-hidden
:checked @hidden
:on-change
(fn [e]
(let [value (-> e .-target .-checked)]
(rf/dispatch [:mark-user-hidden (:id @user) value])))}]
(rf/dispatch [:save-user-fields (:id @user) {:is_hidden value}])))}]
[:label {:for :input-hidden} "Disguise myself from the top hunters and activity lists."]]]]))))