Make events to update a profile more generic
This commit is contained in:
parent
d2d17bb57f
commit
96a06e70bc
|
@ -4,27 +4,32 @@
|
||||||
[utils.re-frame :as rf]))
|
[utils.re-frame :as rf]))
|
||||||
|
|
||||||
(rf/reg-event-fx :profile/edit-accent-colour-success
|
(rf/reg-event-fx :profile/edit-accent-colour-success
|
||||||
(fn [_ [customization-color]]
|
(fn [_ [customization-color navigate-back? show-toast?]]
|
||||||
{:fx [[:dispatch [:profile/save-local-accent-color customization-color]]
|
{:fx [[:dispatch [:profile/save-local-accent-color customization-color]]
|
||||||
[:dispatch [:navigate-back]]
|
(when navigate-back?
|
||||||
[:dispatch
|
[:dispatch [:navigate-back]])
|
||||||
[:toasts/upsert
|
(when show-toast?
|
||||||
{:type :positive
|
[:dispatch
|
||||||
:theme :dark
|
[:toasts/upsert
|
||||||
:text (i18n/label :t/accent-colour-updated)}]]]}))
|
{:type :positive
|
||||||
|
:theme :dark
|
||||||
|
:text (i18n/label :t/accent-colour-updated)}]])]}))
|
||||||
|
|
||||||
(rf/reg-event-fx :profile/save-local-accent-color
|
(rf/reg-event-fx :profile/save-local-accent-color
|
||||||
(fn [{:keys [db]} [customization-color]]
|
(fn [{:keys [db]} [customization-color]]
|
||||||
{:db (assoc-in db [:profile/profile :customization-color] customization-color)}))
|
{:db (assoc-in db [:profile/profile :customization-color] customization-color)}))
|
||||||
|
|
||||||
(defn edit-accent-colour
|
(defn edit-accent-colour
|
||||||
[{:keys [db]} [customization-color]]
|
[{:keys [db]}
|
||||||
|
[{:keys [color navigate-back? show-toast?]
|
||||||
|
:or {navigate-back? true
|
||||||
|
show-toast? true}}]]
|
||||||
(let [key-uid (get-in db [:profile/profile :key-uid])]
|
(let [key-uid (get-in db [:profile/profile :key-uid])]
|
||||||
{:fx [[:json-rpc/call
|
{:fx [[:json-rpc/call
|
||||||
[{:method "wakuext_setCustomizationColor"
|
[{:method "wakuext_setCustomizationColor"
|
||||||
:params [{:customizationColor customization-color
|
:params [{:customizationColor color
|
||||||
:keyUid key-uid}]
|
:keyUid key-uid}]
|
||||||
:on-success [:profile/edit-accent-colour-success customization-color]
|
:on-success [:profile/edit-accent-colour-success color navigate-back? show-toast?]
|
||||||
:on-error #(log/error "failed to edit accent color." {:error %})}]]]}))
|
:on-error #(log/error "failed to edit accent color." {:error %})}]]]}))
|
||||||
|
|
||||||
(rf/reg-event-fx :profile/edit-accent-colour edit-accent-colour)
|
(rf/reg-event-fx :profile/edit-accent-colour edit-accent-colour)
|
||||||
|
|
|
@ -58,7 +58,8 @@
|
||||||
{:type :primary
|
{:type :primary
|
||||||
:customization-color @unsaved-custom-color
|
:customization-color @unsaved-custom-color
|
||||||
:on-press (fn []
|
:on-press (fn []
|
||||||
(rf/dispatch [:profile/edit-accent-colour @unsaved-custom-color]))}
|
(rf/dispatch [:profile/edit-accent-colour
|
||||||
|
{:color @unsaved-custom-color}]))}
|
||||||
(i18n/label :t/save-colour)]]]]))))
|
(i18n/label :t/save-colour)]]]]))))
|
||||||
|
|
||||||
(defn view
|
(defn view
|
||||||
|
|
|
@ -11,19 +11,22 @@
|
||||||
(update db :profile/profile dissoc :images))}))
|
(update db :profile/profile dissoc :images))}))
|
||||||
|
|
||||||
(rf/reg-event-fx :profile/edit-profile-picture-success
|
(rf/reg-event-fx :profile/edit-profile-picture-success
|
||||||
(fn [_ [images]]
|
(fn [_ [show-toast? images]]
|
||||||
(let [has-picture? (rf/sub [:profile/has-picture])]
|
(let [has-picture? (rf/sub [:profile/has-picture])]
|
||||||
{:fx [[:dispatch [:profile/update-local-picture (reverse images)]]
|
{:fx [[:dispatch [:profile/update-local-picture (reverse images)]]
|
||||||
[:dispatch
|
(when show-toast?
|
||||||
[:toasts/upsert
|
[:dispatch
|
||||||
{:type :positive
|
[:toasts/upsert
|
||||||
:theme :dark
|
{:type :positive
|
||||||
:text (i18n/label (if has-picture?
|
:theme :dark
|
||||||
:t/profile-picture-updated
|
:text (i18n/label (if has-picture?
|
||||||
:t/profile-picture-added))}]]]})))
|
:t/profile-picture-updated
|
||||||
|
:t/profile-picture-added))}]])]})))
|
||||||
|
|
||||||
(defn edit-profile-picture
|
(defn edit-profile-picture
|
||||||
[{:keys [db]} [picture crop-width crop-height]]
|
[{:keys [db]}
|
||||||
|
[{:keys [picture crop-width crop-height show-toast?]
|
||||||
|
:or {show-toast? true}}]]
|
||||||
(let [key-uid (get-in db [:profile/profile :key-uid])
|
(let [key-uid (get-in db [:profile/profile :key-uid])
|
||||||
crop-width (or crop-width profile-picture-picker/crop-size)
|
crop-width (or crop-width profile-picture-picker/crop-size)
|
||||||
crop-height (or crop-height profile-picture-picker/crop-size)
|
crop-height (or crop-height profile-picture-picker/crop-size)
|
||||||
|
@ -31,25 +34,28 @@
|
||||||
{:fx [[:json-rpc/call
|
{:fx [[:json-rpc/call
|
||||||
[{:method "multiaccounts_storeIdentityImage"
|
[{:method "multiaccounts_storeIdentityImage"
|
||||||
:params [key-uid path 0 0 crop-width crop-height]
|
:params [key-uid path 0 0 crop-width crop-height]
|
||||||
:on-success [:profile/edit-profile-picture-success]}]]]}))
|
:on-success [:profile/edit-profile-picture-success show-toast?]}]]]}))
|
||||||
|
|
||||||
(rf/reg-event-fx :profile/edit-picture edit-profile-picture)
|
(rf/reg-event-fx :profile/edit-picture edit-profile-picture)
|
||||||
|
|
||||||
(rf/reg-event-fx :profile/delete-profile-picture-success
|
(rf/reg-event-fx :profile/delete-profile-picture-success
|
||||||
(fn [_]
|
(fn [_ [show-toast?]]
|
||||||
{:fx [[:dispatch [:profile/update-local-picture nil]]
|
{:fx [[:dispatch [:profile/update-local-picture nil]]
|
||||||
[:dispatch
|
(when show-toast?
|
||||||
[:toasts/upsert
|
[:dispatch
|
||||||
{:type :positive
|
[:toasts/upsert
|
||||||
:theme :dark
|
{:type :positive
|
||||||
:text (i18n/label :t/profile-picture-removed)}]]]}))
|
:theme :dark
|
||||||
|
:text (i18n/label :t/profile-picture-removed)}]])]}))
|
||||||
|
|
||||||
(defn delete-profile-picture
|
(defn delete-profile-picture
|
||||||
[{:keys [db]}]
|
[{:keys [db]}
|
||||||
|
[{:keys [show-toast?]
|
||||||
|
:or {show-toast? true}}]]
|
||||||
(let [key-uid (get-in db [:profile/profile :key-uid])]
|
(let [key-uid (get-in db [:profile/profile :key-uid])]
|
||||||
{:fx [[:json-rpc/call
|
{:fx [[:json-rpc/call
|
||||||
[{:method "multiaccounts_deleteIdentityImage"
|
[{:method "multiaccounts_deleteIdentityImage"
|
||||||
:params [key-uid]
|
:params [key-uid]
|
||||||
:on-success [:profile/delete-profile-picture-success]}]]]}))
|
:on-success [:profile/delete-profile-picture-success show-toast?]}]]]}))
|
||||||
|
|
||||||
(rf/reg-event-fx :profile/delete-picture delete-profile-picture)
|
(rf/reg-event-fx :profile/delete-picture delete-profile-picture)
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
has-picture? (rf/sub [:profile/has-picture])
|
has-picture? (rf/sub [:profile/has-picture])
|
||||||
on-change-profile-pic (fn [picture]
|
on-change-profile-pic (fn [picture]
|
||||||
(if picture
|
(if picture
|
||||||
(rf/dispatch [:profile/edit-picture picture])
|
(rf/dispatch [:profile/edit-picture {:picture picture}])
|
||||||
(rf/dispatch [:profile/delete-picture])))]
|
(rf/dispatch [:profile/delete-picture])))]
|
||||||
[rn/view
|
[rn/view
|
||||||
{:key :edit-profile
|
{:key :edit-profile
|
||||||
|
|
|
@ -5,21 +5,26 @@
|
||||||
[utils.re-frame :as rf]))
|
[utils.re-frame :as rf]))
|
||||||
|
|
||||||
(rf/reg-event-fx :profile/edit-profile-name-success
|
(rf/reg-event-fx :profile/edit-profile-name-success
|
||||||
(fn [_]
|
(fn [{:keys [db]} [display-name navigate-back? show-toast?]]
|
||||||
{:fx [[:dispatch [:navigate-back]]
|
{:db (assoc-in db [:profile/profile :display-name] display-name)
|
||||||
[:dispatch
|
:fx [(when navigate-back?
|
||||||
[:toasts/upsert
|
[:dispatch [:navigate-back]])
|
||||||
{:type :positive
|
(when show-toast?
|
||||||
:theme :dark
|
[:dispatch
|
||||||
:text (i18n/label :t/name-updated)}]]]}))
|
[:toasts/upsert
|
||||||
|
{:type :positive
|
||||||
|
:theme :dark
|
||||||
|
:text (i18n/label :t/name-updated)}]])]}))
|
||||||
|
|
||||||
(defn edit-profile-name
|
(defn edit-profile-name
|
||||||
[{:keys [db]} [name]]
|
[_
|
||||||
{:db (assoc-in db [:profile/profile :display-name] name)
|
[{:keys [display-name navigate-back? show-toast?]
|
||||||
:fx [[:json-rpc/call
|
:or {navigate-back? true
|
||||||
|
show-toast? true}}]]
|
||||||
|
{:fx [[:json-rpc/call
|
||||||
[{:method "wakuext_setDisplayName"
|
[{:method "wakuext_setDisplayName"
|
||||||
:params [name]
|
:params [display-name]
|
||||||
:on-success [:profile/edit-profile-name-success]}]]]})
|
:on-success [:profile/edit-profile-name-success display-name navigate-back? show-toast?]}]]]})
|
||||||
|
|
||||||
(rf/reg-event-fx :profile/edit-name edit-profile-name)
|
(rf/reg-event-fx :profile/edit-name edit-profile-name)
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,7 @@
|
||||||
{:type :primary
|
{:type :primary
|
||||||
:customization-color customization-color
|
:customization-color customization-color
|
||||||
:on-press (fn []
|
:on-press (fn []
|
||||||
(rf/dispatch [:profile/edit-name @full-name]))
|
(rf/dispatch [:profile/edit-name {:display-name @full-name}]))
|
||||||
:disabled? (boolean (or @typing?
|
:disabled? (boolean (or @typing?
|
||||||
(string/blank? @full-name)
|
(string/blank? @full-name)
|
||||||
(not (string/blank? @error-msg))))}
|
(not (string/blank? @error-msg))))}
|
||||||
|
|
Loading…
Reference in New Issue