From 3122cb7ac3c63ac500d9a6147ce0afa9a623b8c5 Mon Sep 17 00:00:00 2001 From: alwx Date: Wed, 30 Nov 2016 21:30:57 +0300 Subject: [PATCH] Blue hashtags & new line fix (#491) --- src/status_im/components/drawer/view.cljs | 37 +++++++++++++++-------- src/status_im/profile/screen.cljs | 12 +++----- src/status_im/utils/utils.cljs | 2 +- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/status_im/components/drawer/view.cljs b/src/status_im/components/drawer/view.cljs index 55964a759d..4a8a7ebbb5 100644 --- a/src/status_im/components/drawer/view.cljs +++ b/src/status_im/components/drawer/view.cljs @@ -22,7 +22,8 @@ [status-im.components.react :refer [dismiss-keyboard!]] [clojure.string :as str] [cljs.spec :as s] - [status-im.components.chat-icon.screen :as ci])) + [status-im.components.chat-icon.screen :as ci] + [taoensso.timbre :as log])) (defonce drawer-atom (atom)) @@ -41,16 +42,24 @@ :font :default} name]]) +(defn- update-status [new-status] + (when-not (str/blank? new-status) + (dispatch [:check-status-change new-status]) + (dispatch [:account-update {:status new-status}]) + (dispatch [:set-in [:profile-edit :status] new-status]))) + (defn drawer-menu [] (let [account (subscribe [:get-current-account]) profile (subscribe [:get :profile-edit]) keyboard-height (subscribe [:get :keyboard-height]) placeholder (generate-gfy) - status-edit? (r/atom false)] + status-edit? (r/atom false) + status-text (r/atom nil)] (fn [] (let [{:keys [name photo-path status]} @account - {new-name :name new-status :status} @profile] + {new-name :name + new-status :status} @profile] [view st/drawer-menu [touchable-without-feedback {:on-press #(dismiss-keyboard!)} [view st/drawer-menu @@ -75,19 +84,21 @@ :editable true :multiline true :auto-focus true - :blur-on-submit true :focus status-edit? - :maxLength 140 + :max-length 140 :accessibility-label :input :placeholder (label :t/profile-no-status) - :on-change-text (fn [t] - (dispatch [:set-in [:profile-edit :status] (clean-text t)])) - :on-submit-editing (fn [] - (reset! status-edit? false) - (when (and new-status (not (str/blank? new-status))) - (dispatch [:check-status-change (clean-text new-status)]) - (dispatch [:account-update {:status (clean-text new-status)}]))) - :default-value status}] + :default-value status + :on-blur #(do + (reset! status-edit? false) + (update-status @status-text)) + :on-change-text #(let [status (clean-text %)] + (reset! status-text status) + (if (str/includes? % "\n") + (do + (reset! status-edit? false) + (update-status status)) + (dispatch [:set-in [:profile-edit :status] status])))}] [status-view {:style st/status-text :on-press #(reset! status-edit? true) :number-of-lines 3 diff --git a/src/status_im/profile/screen.cljs b/src/status_im/profile/screen.cljs index f80127f89a..2fc5a8ea52 100644 --- a/src/status_im/profile/screen.cljs +++ b/src/status_im/profile/screen.cljs @@ -32,8 +32,7 @@ [status-im.utils.random :refer [id]] [status-im.utils.utils :refer [clean-text]] [status-im.components.image-button.view :refer [show-qr-button]] - [status-im.i18n :refer [label]] - [taoensso.timbre :as log])) + [status-im.i18n :refer [label]])) (defn share [text dialog-title] (let [list-selection-fn (:list-selection-fn platform-specific)] @@ -102,15 +101,14 @@ :style (st/status-input (:height (r/state component))) :multiline true :editable true - :blur-on-submit true :on-content-size-change #(do (set-status-height %) (reset! just-opened? false)) :max-length 140 :placeholder (label :t/profile-no-status) - :on-change-text (fn [t] - (dispatch [:set-in [:profile-edit :status] (clean-text t)])) - :on-submit-editing (fn [] - (.blur @input-ref)) + :on-change-text #(let [status (clean-text %)] + (if (str/includes? % "\n") + (.blur @input-ref) + (dispatch [:set-in [:profile-edit :status] status]))) :default-value status}] [status-view {:style (st/status-text (:height (r/state component))) :status status}])])}))) diff --git a/src/status_im/utils/utils.cljs b/src/status_im/utils/utils.cljs index f79fd0b08e..5212c22f7e 100644 --- a/src/status_im/utils/utils.cljs +++ b/src/status_im/utils/utils.cljs @@ -57,7 +57,7 @@ (defn clean-text [s] (-> s - (str/replace #"\n" " ") + (str/replace #"\n" "") (str/replace #"\r" "") (str/trim)))