-
Notifications
You must be signed in to change notification settings - Fork 985
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
669a232
commit 3145ecd
Showing
6 changed files
with
156 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,58 @@ | ||
(ns status-im.contexts.profile.contact.actions.view | ||
(:require [quo.core :as quo] | ||
(:require [clojure.string :as string] | ||
[quo.core :as quo] | ||
[react-native.core :as rn] | ||
[status-im.common.not-implemented :as not-implemented] | ||
[utils.i18n :as i18n])) | ||
[status-im.contexts.profile.contact.add-nickname.view :as add-nickname] | ||
[utils.i18n :as i18n] | ||
[utils.re-frame :as rf])) | ||
|
||
(defn view | ||
[] | ||
[quo/action-drawer | ||
[[{:icon :i/edit | ||
:label (i18n/label :t/add-nickname-title) | ||
:on-press not-implemented/alert | ||
:accessibility-label :add-nickname} | ||
{:icon :i/qr-code | ||
:label (i18n/label :t/show-qr) | ||
:on-press not-implemented/alert | ||
:accessibility-label :show-qr-code} | ||
{:icon :i/share | ||
:label (i18n/label :t/share-profile) | ||
:on-press not-implemented/alert | ||
:accessibility-label :share-profile} | ||
{:icon :i/untrustworthy | ||
:label (i18n/label :t/mark-untrustworthy) | ||
:on-press not-implemented/alert | ||
:accessibility-label :mark-untrustworthy | ||
:add-divider? true | ||
:danger? true} | ||
{:icon :i/block | ||
:label (i18n/label :t/block-user) | ||
:on-press not-implemented/alert | ||
:accessibility-label :block-user | ||
:danger? true}]]]) | ||
(let [{:keys [nickname public-key]} (rf/sub [:contacts/current-contact]) | ||
on-add-nickname (rn/use-callback #(rf/dispatch [:show-bottom-sheet | ||
{:content | ||
(fn [] [add-nickname/view])}])) | ||
on-remove-nickname (rn/use-callback | ||
(fn [] | ||
(rf/dispatch [:hide-bottom-sheet]) | ||
(rf/dispatch [:toasts/upsert | ||
{:id :remove-nickname | ||
:type :positive | ||
:text (i18n/label :t/nickname-removed)}]) | ||
(rf/dispatch [:contacts/update-nickname public-key ""])) | ||
[public-key]) | ||
has-nickname? (rn/use-memo (fn [] (not (string/blank? nickname))) [nickname])] | ||
[quo/action-drawer | ||
[[{:icon :i/edit | ||
:label (if has-nickname? | ||
(i18n/label :t/edit-nickname) | ||
(i18n/label :t/add-nickname-title)) | ||
:on-press on-add-nickname | ||
:accessibility-label (if nickname :edit-nickname :add-nickname)} | ||
{:icon :i/qr-code | ||
:label (i18n/label :t/show-qr) | ||
:on-press not-implemented/alert | ||
:accessibility-label :show-qr-code} | ||
{:icon :i/share | ||
:label (i18n/label :t/share-profile) | ||
:on-press not-implemented/alert | ||
:accessibility-label :share-profile} | ||
(when has-nickname? | ||
{:icon :i/delete | ||
:label (i18n/label :t/remove-nickname) | ||
:on-press on-remove-nickname | ||
:add-divider? true | ||
:accessibility-label :remove-nickname | ||
:danger? true}) | ||
{:icon :i/untrustworthy | ||
:label (i18n/label :t/mark-untrustworthy) | ||
:on-press not-implemented/alert | ||
:accessibility-label :mark-untrustworthy | ||
:add-divider? (when-not has-nickname? true) | ||
:danger? true} | ||
{:icon :i/block | ||
:label (i18n/label :t/block-user) | ||
:on-press not-implemented/alert | ||
:accessibility-label :block-user | ||
:danger? true}]]])) |
6 changes: 6 additions & 0 deletions
6
src/status_im/contexts/profile/contact/add_nickname/style.cljs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
(ns status-im.contexts.profile.contact.add-nickname.style) | ||
|
||
(def input-wrapper | ||
{:padding-vertical 8 | ||
:padding-horizontal 20 | ||
:gap 8}) |
81 changes: 81 additions & 0 deletions
81
src/status_im/contexts/profile/contact/add_nickname/view.cljs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
(ns status-im.contexts.profile.contact.add-nickname.view | ||
(:require [clojure.string :as string] | ||
[quo.core :as quo] | ||
[react-native.core :as rn] | ||
[status-im.common.validation.profile :as profile-validator] | ||
[status-im.constants :as constants] | ||
[status-im.contexts.profile.contact.add-nickname.style :as style] | ||
[status-im.contexts.profile.utils :as profile.utils] | ||
[utils.debounce :as debounce] | ||
[utils.i18n :as i18n] | ||
[utils.re-frame :as rf])) | ||
|
||
(defn view | ||
[] | ||
(let [{:keys [public-key primary-name nickname customization-color] | ||
:as profile} (rf/sub [:contacts/current-contact]) | ||
;; TODO(@mohsen): remove :blue, https://github.com/status-im/status-mobile/issues/18733 | ||
customization-color (or customization-color :blue) | ||
full-name (profile.utils/displayed-name profile) | ||
profile-picture (profile.utils/photo profile) | ||
[unsaved-nickname set-unsaved-nickname] (rn/use-state nickname) | ||
[error-msg set-error-msg] (rn/use-state nil) | ||
validate-nickname (rn/use-callback | ||
(debounce/debounce | ||
(fn [name] | ||
(set-error-msg | ||
(profile-validator/validation-nickname name))) | ||
300)) | ||
on-cancel (rn/use-callback #(rf/dispatch [:hide-bottom-sheet])) | ||
on-nickname-change (rn/use-callback (fn [text] | ||
(set-unsaved-nickname text) | ||
(validate-nickname text))) | ||
on-nickname-submit (rn/use-callback | ||
(fn [] | ||
(rf/dispatch [:hide-bottom-sheet]) | ||
(rf/dispatch [:toasts/upsert | ||
{:id :add-nickname | ||
:type :positive | ||
:text (i18n/label | ||
(if (string/blank? nickname) | ||
:t/nickname-added | ||
:t/nickname-updated) | ||
{:primary-name primary-name})}]) | ||
(rf/dispatch [:contacts/update-nickname public-key | ||
(string/trim unsaved-nickname)])) | ||
[public-key unsaved-nickname])] | ||
[:<> | ||
[quo/drawer-top | ||
{:type :context-tag | ||
:context-tag-type :default | ||
:title (i18n/label :t/add-nickname-title) | ||
:full-name full-name | ||
:profile-picture profile-picture | ||
:customization-color customization-color}] | ||
[rn/view {:style style/input-wrapper} | ||
[quo/input | ||
{:type :text | ||
:char-limit constants/profile-name-max-length | ||
:max-length constants/profile-name-max-length | ||
:auto-focus true | ||
:default-value unsaved-nickname | ||
:error? (not (string/blank? error-msg)) | ||
:label (i18n/label :t/nickname) | ||
:on-change-text on-nickname-change} | ||
:on-submit-editing on-nickname-submit] | ||
[quo/info-message | ||
{:icon :i/info | ||
:size :default | ||
:type (if-not (string/blank? error-msg) :error :default)} | ||
(if-not (string/blank? error-msg) | ||
error-msg | ||
(i18n/label :t/nickname-visible-to-you))]] | ||
[quo/bottom-actions | ||
{:actions :two-actions | ||
:button-one-label (i18n/label :t/add-nickname-title) | ||
:button-one-props {:disabled? (or (string/blank? unsaved-nickname) | ||
(not (string/blank? error-msg))) | ||
:on-press on-nickname-submit} | ||
:button-two-label (i18n/label :t/cancel) | ||
:button-two-props {:type :grey | ||
:on-press on-cancel}}]])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters