Suppress remove photo option when no profile pic

Signed-off-by: yenda <eric@status.im>
This commit is contained in:
acolytec3 2019-10-22 20:36:25 -04:00 committed by yenda
parent acdad6d598
commit 3cc157b0fb
No known key found for this signature in database
GPG Key ID: 0095623C0069DCE6
8 changed files with 77 additions and 42 deletions

View File

@ -28,7 +28,8 @@
[status-im.wallet.core :as wallet] [status-im.wallet.core :as wallet]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[status-im.ui.screens.db :refer [app-db]] [status-im.ui.screens.db :refer [app-db]]
[status-im.multiaccounts.biometric.core :as biometric])) [status-im.multiaccounts.biometric.core :as biometric]
[status-im.utils.identicon :as identicon]))
(def rpc-endpoint "https://goerli.infura.io/v3/f315575765b14720b32382a61a89341a") (def rpc-endpoint "https://goerli.infura.io/v3/f315575765b14720b32382a61a89341a")
(def contract-address "0xfbf4c8e2B41fAfF8c616a0E49Fb4365a5355Ffaf") (def contract-address "0xfbf4c8e2B41fAfF8c616a0E49Fb4365a5355Ffaf")
@ -271,6 +272,7 @@
:address address :address address
:photo-path photo-path :photo-path photo-path
:name name) :name name)
(assoc :profile/photo-added? (= (identicon/identicon public-key) photo-path))
(update :multiaccounts/login dissoc (update :multiaccounts/login dissoc
:error :error
:password))} :password))}

View File

@ -107,6 +107,8 @@
(reg-root-key-sub :my-profile/advanced? :my-profile/advanced?) (reg-root-key-sub :my-profile/advanced? :my-profile/advanced?)
(reg-root-key-sub :my-profile/editing? :my-profile/editing?) (reg-root-key-sub :my-profile/editing? :my-profile/editing?)
(reg-root-key-sub :my-profile/profile :my-profile/profile) (reg-root-key-sub :my-profile/profile :my-profile/profile)
(reg-root-key-sub :profile/photo-added? :profile/photo-added?)
;;multiaccount ;;multiaccount
(reg-root-key-sub :multiaccounts/multiaccounts :multiaccounts/multiaccounts) (reg-root-key-sub :multiaccounts/multiaccounts :multiaccounts/multiaccounts)
(reg-root-key-sub :multiaccounts/login :multiaccounts/login) (reg-root-key-sub :multiaccounts/login :multiaccounts/login)

View File

@ -67,7 +67,7 @@
- minimized-toolbar - minimized-toolbar
- flat-list-with-large-header" - flat-list-with-large-header"
[header-in-toolbar nav-item toolbar-action-items header content list-ref] [header-in-toolbar nav-item toolbar-action-items header content list-ref]
(let [to-hide (reagent/atom false) (let [to-hide (reagent/atom true)
anim-opacity (animation/create-value 0) anim-opacity (animation/create-value 0)
scroll-y (animation/create-value 0)] scroll-y (animation/create-value 0)]
(animation/add-listener scroll-y (fn [anim] (animation/add-listener scroll-y (fn [anim]
@ -83,3 +83,25 @@
#(reset! to-hide false))))) #(reset! to-hide false)))))
{:minimized-toolbar [minimized-toolbar header-in-toolbar nav-item toolbar-action-items anim-opacity] {:minimized-toolbar [minimized-toolbar header-in-toolbar nav-item toolbar-action-items anim-opacity]
:content-with-header [flat-list-with-large-header header content list-ref scroll-y]})) :content-with-header [flat-list-with-large-header header content list-ref scroll-y]}))
(defn add-listener [anim-opacity scroll-y]
(let [to-hide (atom false)]
(animation/add-listener
scroll-y
(fn [anim]
(cond
(and (>= (.-value anim) 40) (not @to-hide))
(animation/start
(styles/minimized-toolbar-fade-in anim-opacity)
#(reset! to-hide true))
(and (< (.-value anim) 40) @to-hide)
(animation/start
(styles/minimized-toolbar-fade-out anim-opacity)
#(reset! to-hide false)))))))
(defn minimized-toolbar-handler [header-in-toolbar nav-item toolbar-action-items anim-opacity]
[minimized-toolbar header-in-toolbar nav-item toolbar-action-items anim-opacity])
(defn flat-list-with-header-handler [header content list-ref scroll-y]
[flat-list-with-large-header header content list-ref scroll-y])

View File

@ -115,6 +115,7 @@
:allow-icon-change? false :allow-icon-change? false
:include-remove-action? false}]) :include-remove-action? false}])
;;TO-DO Rework generate-view to use 3 functions from large-toolbar
(views/defview profile [] (views/defview profile []
(views/letsubs [list-ref (reagent/atom nil) (views/letsubs [list-ref (reagent/atom nil)
contact [:contacts/current-contact]] contact [:contacts/current-contact]]

View File

@ -22,6 +22,7 @@
(spec/def :profile/name correct-name?) (spec/def :profile/name correct-name?)
(spec/def :profile/status (spec/nilable string?)) (spec/def :profile/status (spec/nilable string?))
(spec/def :profile/photo-path (spec/nilable base64-encoded-image-path?)) (spec/def :profile/photo-path (spec/nilable base64-encoded-image-path?))
(spec/def :profile/photo-added? (spec/nilable boolean?))
(spec/def :my-profile/default-name (spec/nilable string?)) (spec/def :my-profile/default-name (spec/nilable string?))
(spec/def :my-profile/editing? (spec/nilable boolean?)) (spec/def :my-profile/editing? (spec/nilable boolean?))

View File

@ -38,7 +38,8 @@
{:db (-> db {:db (-> db
(assoc-in [:my-profile/profile :photo-path] (assoc-in [:my-profile/profile :photo-path]
(identicon/identicon (multiaccounts.model/current-public-key cofx))) (identicon/identicon (multiaccounts.model/current-public-key cofx)))
(assoc :my-profile/editing? true))} (assoc :my-profile/editing? true
:profile/photo-added? false))}
(profile.models/save)))) (profile.models/save))))
(handlers/register-handler-fx (handlers/register-handler-fx

View File

@ -69,7 +69,8 @@
{:db (-> db {:db (-> db
(assoc-in [:my-profile/profile :photo-path] (assoc-in [:my-profile/profile :photo-path]
(str "data:image/jpeg;base64," base64-image)) (str "data:image/jpeg;base64," base64-image))
(assoc :my-profile/editing? true))} (assoc :my-profile/editing? true)
(assoc :profile/photo-added? true))}
save) save)
{:open-image-picker this-event})) {:open-image-picker this-event}))

View File

@ -24,7 +24,8 @@
[status-im.utils.identicon :as identicon] [status-im.utils.identicon :as identicon]
[status-im.utils.platform :as platform] [status-im.utils.platform :as platform]
[status-im.utils.config :as config] [status-im.utils.config :as config]
[status-im.utils.universal-links.core :as universal-links]) [status-im.utils.universal-links.core :as universal-links]
[status-im.ui.components.animation :as animation])
(:require-macros [status-im.utils.views :as views])) (:require-macros [status-im.utils.views :as views]))
(views/defview share-chat-key [] (views/defview share-chat-key []
@ -70,11 +71,11 @@
;:icon :main-icons/link ;:icon :main-icons/link
:accessibility-label :share-my-contact-code-button}]]]))) :accessibility-label :share-my-contact-code-button}]]])))
(defn- header [{:keys [photo-path] :as account}] (defn- header [{:keys [photo-path] :as account} photo-added?]
[profile.components/profile-header [profile.components/profile-header
{:contact account {:contact account
:allow-icon-change? true :allow-icon-change? true
:include-remove-action? (seq photo-path)}]) :include-remove-action? photo-added?}])
(defn- header-in-toolbar [account] (defn- header-in-toolbar [account]
(let [displayed-name (multiaccounts/displayed-name account)] (let [displayed-name (multiaccounts/displayed-name account)]
@ -196,45 +197,49 @@
:on-press :on-press
#(re-frame/dispatch [:multiaccounts.logout.ui/logout-pressed])}]) #(re-frame/dispatch [:multiaccounts.logout.ui/logout-pressed])}])
(views/defview my-profile [] (defn minimized-toolbar-handler [anim-opacity]
(views/letsubs [list-ref (reagent/atom nil) (let [{:keys [public-key]
{:keys [public-key :as multiaccount} @(re-frame/subscribe [:multiaccount])]
[large-toolbar/minimized-toolbar-handler
(header-in-toolbar multiaccount)
nil
(toolbar-action-items public-key)
anim-opacity]))
(defn content-with-header [list-ref scroll-y]
(let [{:keys [public-key
preferred-name preferred-name
seed-backed-up? seed-backed-up?
mnemonic mnemonic
keycard-key-uid keycard-key-uid
address] address]
:as multiaccount} [:multiaccount] :as multiaccount} @(re-frame/subscribe [:multiaccount])
active-contacts-count [:contacts/active-count] active-contacts-count @(re-frame/subscribe [:contacts/active-count])
tribute-to-talk [:tribute-to-talk/profile] tribute-to-talk @(re-frame/subscribe [:tribute-to-talk/profile])
registrar [:ens.stateofus/registrar]] registrar @(re-frame/subscribe [:ens.stateofus/registrar])
(let [show-backup-seed? (and (not seed-backed-up?) photo-added? @(re-frame/subscribe [:profile/photo-added?])
(not (string/blank? mnemonic))) show-backup-seed? (and (not seed-backed-up?)
(not (string/blank? mnemonic)))]
;; toolbar-contents [large-toolbar/flat-list-with-header-handler
header-in-toolbar (header-in-toolbar multiaccount) (header multiaccount photo-added?)
toolbar-action-items (toolbar-action-items public-key) (flat-list-content
;; flatlist contents
header (header multiaccount)
content (flat-list-content
preferred-name registrar tribute-to-talk preferred-name registrar tribute-to-talk
active-contacts-count show-backup-seed? active-contacts-count show-backup-seed?
keycard-key-uid) keycard-key-uid)
list-ref
scroll-y]))
;; generated toolbar and content with header (defn my-profile []
generated-view (large-toolbar/generate-view (let [list-ref (reagent/atom nil)
header-in-toolbar anim-opacity (animation/create-value 0)
nil scroll-y (animation/create-value 0)]
toolbar-action-items (large-toolbar/add-listener anim-opacity scroll-y)
header (fn []
content
list-ref)]
[react/safe-area-view [react/safe-area-view
{:style {:style
(merge {:flex 1} (merge {:flex 1}
(when platform/ios? (when platform/ios?
{:margin-bottom tabs.styles/tabs-diff}))} {:margin-bottom tabs.styles/tabs-diff}))}
[status-bar/status-bar {:type :main}] [status-bar/status-bar {:type :main}]
(:minimized-toolbar generated-view) [minimized-toolbar-handler anim-opacity]
(:content-with-header generated-view)]))) [content-with-header list-ref scroll-y]])))