|
1 | 1 | (ns status-im.contexts.profile.contact.actions.view
|
2 |
| - (:require [quo.core :as quo] |
| 2 | + (:require [clojure.string :as string] |
| 3 | + [quo.core :as quo] |
| 4 | + [react-native.core :as rn] |
3 | 5 | [status-im.common.not-implemented :as not-implemented]
|
4 |
| - [utils.i18n :as i18n])) |
| 6 | + [status-im.contexts.profile.contact.add-nickname.view :as add-nickname] |
| 7 | + [utils.i18n :as i18n] |
| 8 | + [utils.re-frame :as rf])) |
5 | 9 |
|
6 | 10 | (defn view
|
7 | 11 | []
|
8 |
| - [quo/action-drawer |
9 |
| - [[{:icon :i/edit |
10 |
| - :label (i18n/label :t/add-nickname-title) |
11 |
| - :on-press not-implemented/alert |
12 |
| - :accessibility-label :add-nickname} |
13 |
| - {:icon :i/qr-code |
14 |
| - :label (i18n/label :t/show-qr) |
15 |
| - :on-press not-implemented/alert |
16 |
| - :accessibility-label :show-qr-code} |
17 |
| - {:icon :i/share |
18 |
| - :label (i18n/label :t/share-profile) |
19 |
| - :on-press not-implemented/alert |
20 |
| - :accessibility-label :share-profile} |
21 |
| - {:icon :i/untrustworthy |
22 |
| - :label (i18n/label :t/mark-untrustworthy) |
23 |
| - :on-press not-implemented/alert |
24 |
| - :accessibility-label :mark-untrustworthy |
25 |
| - :add-divider? true |
26 |
| - :danger? true} |
27 |
| - {:icon :i/block |
28 |
| - :label (i18n/label :t/block-user) |
29 |
| - :on-press not-implemented/alert |
30 |
| - :accessibility-label :block-user |
31 |
| - :danger? true}]]]) |
| 12 | + (let [{:keys [nickname public-key]} (rf/sub [:contacts/current-contact]) |
| 13 | + on-add-nickname (rn/use-callback #(rf/dispatch [:show-bottom-sheet |
| 14 | + {:content |
| 15 | + (fn [] [add-nickname/view])}])) |
| 16 | + on-remove-nickname (rn/use-callback |
| 17 | + (fn [] |
| 18 | + (rf/dispatch [:hide-bottom-sheet]) |
| 19 | + (rf/dispatch [:toasts/upsert |
| 20 | + {:id :remove-nickname |
| 21 | + :type :positive |
| 22 | + :text (i18n/label :t/nickname-removed)}]) |
| 23 | + (rf/dispatch [:contacts/update-nickname public-key ""])) |
| 24 | + [public-key]) |
| 25 | + has-nickname? (rn/use-memo (fn [] (not (string/blank? nickname))) [nickname])] |
| 26 | + [quo/action-drawer |
| 27 | + [[{:icon :i/edit |
| 28 | + :label (if has-nickname? |
| 29 | + (i18n/label :t/edit-nickname) |
| 30 | + (i18n/label :t/add-nickname-title)) |
| 31 | + :on-press on-add-nickname |
| 32 | + :accessibility-label (if nickname :edit-nickname :add-nickname)} |
| 33 | + {:icon :i/qr-code |
| 34 | + :label (i18n/label :t/show-qr) |
| 35 | + :on-press not-implemented/alert |
| 36 | + :accessibility-label :show-qr-code} |
| 37 | + {:icon :i/share |
| 38 | + :label (i18n/label :t/share-profile) |
| 39 | + :on-press not-implemented/alert |
| 40 | + :accessibility-label :share-profile} |
| 41 | + (when has-nickname? |
| 42 | + {:icon :i/delete |
| 43 | + :label (i18n/label :t/remove-nickname) |
| 44 | + :on-press on-remove-nickname |
| 45 | + :add-divider? true |
| 46 | + :accessibility-label :remove-nickname |
| 47 | + :danger? true}) |
| 48 | + {:icon :i/untrustworthy |
| 49 | + :label (i18n/label :t/mark-untrustworthy) |
| 50 | + :on-press not-implemented/alert |
| 51 | + :accessibility-label :mark-untrustworthy |
| 52 | + :add-divider? (when (not has-nickname?) true) |
| 53 | + :danger? true} |
| 54 | + {:icon :i/block |
| 55 | + :label (i18n/label :t/block-user) |
| 56 | + :on-press not-implemented/alert |
| 57 | + :accessibility-label :block-user |
| 58 | + :danger? true}]]])) |
0 commit comments