From 7c1319e96600d14e6e1dfa4905226a68c64defe0 Mon Sep 17 00:00:00 2001 From: Alexander Pantyukhov Date: Tue, 22 Nov 2016 16:38:15 +0300 Subject: [PATCH] Fixes for discover search input field (#478) --- src/status_im/components/main_tabs.cljs | 2 +- src/status_im/components/toolbar/view.cljs | 2 +- src/status_im/discovery/handlers.cljs | 1 + src/status_im/discovery/screen.cljs | 31 ++++++++++--------- src/status_im/discovery/styles.cljs | 11 +++---- .../discovery/views/popular_list.cljs | 2 +- src/status_im/translations/en.cljs | 2 +- 7 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/status_im/components/main_tabs.cljs b/src/status_im/components/main_tabs.cljs index 2749c6d52a..dab9d45e0c 100644 --- a/src/status_im/components/main_tabs.cljs +++ b/src/status_im/components/main_tabs.cljs @@ -104,7 +104,7 @@ :ref #(reset! main-swiper %) :on-momentum-scroll-end (on-scroll-end swiped?)}) [chats-list] - [discovery] + [discovery (= @view-id :discovery)] [contact-list]] [tabs {:selected-view-id @view-id :prev-view-id @prev-view-id diff --git a/src/status_im/components/toolbar/view.cljs b/src/status_im/components/toolbar/view.cljs index 5136dd4b00..824d029232 100644 --- a/src/status_im/components/toolbar/view.cljs +++ b/src/status_im/components/toolbar/view.cljs @@ -38,7 +38,7 @@ [text {:style st/toolbar-title-text :font :toolbar-title} title]]) - [view (st/toolbar-actions-container (count actions) (or custom-content custom-action)) + [view (st/toolbar-actions-container (count actions) custom-action) (if actions (for [{action-image :image action-handler :handler} actions] diff --git a/src/status_im/discovery/handlers.cljs b/src/status_im/discovery/handlers.cljs index 40b094eaf7..82c9b89f71 100644 --- a/src/status_im/discovery/handlers.cljs +++ b/src/status_im/discovery/handlers.cljs @@ -25,6 +25,7 @@ (defmethod nav/preload-data! :discovery [db _] + (dispatch [:set :discovery-show-search? false]) (-> db (assoc :tags (discoveries/get-all-tags)) (assoc :discoveries (->> (discoveries/get-all :desc) diff --git a/src/status_im/discovery/screen.cljs b/src/status_im/discovery/screen.cljs index c0be799897..95cd5c311e 100644 --- a/src/status_im/discovery/screen.cljs +++ b/src/status_im/discovery/screen.cljs @@ -17,7 +17,8 @@ [status-im.discovery.views.popular-list :refer [discovery-popular-list]] [status-im.discovery.views.discovery-list-item :refer [discovery-list-item]] [status-im.contacts.styles :as contacts-styles] - [status-im.utils.platform :refer [platform-specific]])) + [status-im.utils.platform :refer [platform-specific]] + [reagent.core :as r])) (defn get-hashtags [status] (let [hashtags (map #(str/lower-case (str/replace % #"#" "")) (re-seq #"[^ !?,;:.]+" status))] @@ -26,21 +27,23 @@ (defn title-content [show-search?] [view st/discovery-toolbar-content (if show-search? - [text-input {:style st/discovery-search-input - :autoFocus true - :placeholder (label :t/search-tags) - :onSubmitEditing (fn [e] - (let [search (aget e "nativeEvent" "text") - hashtags (get-hashtags search)] - (dispatch [:set :discovery-search-tags hashtags]) - (dispatch [:navigate-to :discovery-search-results])))}] + [text-input {:style st/discovery-search-input + :auto-focus true + :placeholder (label :t/search-tags) + :on-blur (fn [e] + (dispatch [:set :discovery-show-search? false])) + :on-submit-editing (fn [e] + (let [search (aget e "nativeEvent" "text") + hashtags (get-hashtags search)] + (dispatch [:set :discovery-search-tags hashtags]) + (dispatch [:navigate-to :discovery-search-results])))}] [view [text {:style st/discovery-title :font :toolbar-title} (label :t/discovery)]])]) (defn toogle-search [current-value] - (dispatch [:set ::show-search? (not current-value)])) + (dispatch [:set :discovery-show-search? (not current-value)])) (defn discovery-toolbar [show-search?] [toolbar @@ -83,18 +86,18 @@ [view st/recent-list (let [discoveries (map-indexed vector discoveries)] (for [[i {:keys [message-id] :as message}] discoveries] - ^{:key (str "message-" message-id)} + ^{:key (str "message-recent-" message-id)} [discovery-list-item {:message message :show-separator? (not= (inc i) (count discoveries)) :current-account current-account}]))]])) -(defview discovery [] - [show-search? [:get ::show-search?] +(defview discovery [current-view?] + [show-search? [:get :discovery-show-search?] contacts [:get :contacts] current-account [:get-current-account] discoveries [:get-recent-discoveries]] [view st/discovery-container - [discovery-toolbar show-search?] + [discovery-toolbar (and current-view? show-search?)] (if discoveries [scroll-view st/scroll-view-container [discovery-popular {:contacts contacts diff --git a/src/status_im/discovery/styles.cljs b/src/status_im/discovery/styles.cljs index 3fce84917e..9f31f70bff 100644 --- a/src/status_im/discovery/styles.cljs +++ b/src/status_im/discovery/styles.cljs @@ -34,12 +34,11 @@ :elevation 0}) (def discovery-search-input - {:flex 1 - :align-self "stretch" - :margin-left 18 - :line-height 42 - :font-size 14 - :color "#7099e6"}) + {:flex 1 + :align-self "stretch" + :margin-left 18 + :font-size 14 + :color "#7099e6"}) (def discovery-title {:color "#000000de" diff --git a/src/status_im/discovery/views/popular_list.cljs b/src/status_im/discovery/views/popular_list.cljs index 72fd268386..68098697ca 100644 --- a/src/status_im/discovery/views/popular_list.cljs +++ b/src/status_im/discovery/views/popular_list.cljs @@ -30,7 +30,7 @@ (:total discoveries)]]] (let [discoveries (map-indexed vector (:discoveries discoveries))] (for [[i {:keys [message-id] :as discovery}] discoveries] - ^{:key (str "message-" message-id)} + ^{:key (str "message-popular-" message-id)} [discovery-list-item {:message discovery :show-separator? (not= (inc i) (count discoveries)) :current-account current-account}]))]) diff --git a/src/status_im/translations/en.cljs b/src/status_im/translations/en.cljs index 5b6180a567..4e83199c8b 100644 --- a/src/status_im/translations/en.cljs +++ b/src/status_im/translations/en.cljs @@ -101,7 +101,7 @@ :new-group-chat "New group chat" ;discover - :discovery "Discovery" + :discovery "Discover" :none "None" :search-tags "Type your search tags here" :popular-tags "Popular tags"