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]
[taoensso.timbre :as log]
[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 contract-address "0xfbf4c8e2B41fAfF8c616a0E49Fb4365a5355Ffaf")
@ -271,6 +272,7 @@
:address address
:photo-path photo-path
:name name)
(assoc :profile/photo-added? (= (identicon/identicon public-key) photo-path))
(update :multiaccounts/login dissoc
:error
:password))}

View File

@ -107,6 +107,8 @@
(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/profile :my-profile/profile)
(reg-root-key-sub :profile/photo-added? :profile/photo-added?)
;;multiaccount
(reg-root-key-sub :multiaccounts/multiaccounts :multiaccounts/multiaccounts)
(reg-root-key-sub :multiaccounts/login :multiaccounts/login)

View File

@ -67,7 +67,7 @@
- minimized-toolbar
- flat-list-with-large-header"
[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)
scroll-y (animation/create-value 0)]
(animation/add-listener scroll-y (fn [anim]
@ -83,3 +83,25 @@
#(reset! to-hide false)))))
{: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]}))
(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
:include-remove-action? false}])
;;TO-DO Rework generate-view to use 3 functions from large-toolbar
(views/defview profile []
(views/letsubs [list-ref (reagent/atom nil)
contact [:contacts/current-contact]]

View File

@ -22,6 +22,7 @@
(spec/def :profile/name correct-name?)
(spec/def :profile/status (spec/nilable string?))
(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/editing? (spec/nilable boolean?))

View File

@ -38,7 +38,8 @@
{:db (-> db
(assoc-in [:my-profile/profile :photo-path]
(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))))
(handlers/register-handler-fx

View File

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

View File

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