Fix missing ref on search input

Fixes #10833

Cleanup search on blur if no chat found

Signed-off-by: Gheorghe Pinzaru <feross95@gmail.com>
This commit is contained in:
Gheorghe Pinzaru 2020-06-17 15:05:07 +03:00
parent e986f9e3db
commit 9ce6fea6d5
No known key found for this signature in database
GPG Key ID: C9A094959935A952
2 changed files with 11 additions and 6 deletions

View File

@ -7,11 +7,11 @@
(defn search-input [{:keys [search-active?]}]
(let [input-ref (atom nil)
search-active? (or search-active? (reagent/atom nil))]
(fn [{:keys [on-focus on-change on-cancel search-filter auto-focus]}]
(fn [{:keys [on-focus on-change on-blur on-cancel search-filter auto-focus]}]
[quo/text-input {:placeholder (i18n/label :t/search)
:blur-on-submit true
:multiline false
:ref #(reset! input-ref %)
:get-ref #(reset! input-ref %)
:default-value search-filter
:auto-focus auto-focus
:on-cancel on-cancel
@ -23,13 +23,16 @@
:padding-bottom 2}
:before {:icon :main-icons/search
:style {:padding-horizontal 8}
:on-press #(.focus ^js @input-ref)
:on-press #(some-> ^js @input-ref (.focus))
:icon-opts {:color (:icon-02 @colors/theme)}}
:on-focus #(do
(when on-focus
(on-focus search-filter))
(reset! search-active? true))
:on-blur #(reset! search-active? false)
:on-blur #(do
(when on-blur
(on-blur))
(reset! search-active? false))
:on-change (fn [e]
(let [^js native-event (.-nativeEvent ^js e)
text (.-text native-event)]

View File

@ -85,13 +85,15 @@
(defonce search-active? (reagent/atom false))
(defn search-input-wrapper [search-filter]
(defn search-input-wrapper [search-filter chats]
[react/view {:padding-horizontal 16
:padding-vertical 10}
[search-input/search-input
{:search-active? search-active?
:search-filter search-filter
:on-cancel #(re-frame/dispatch [:search/home-filter-changed nil])
:on-blur #(when-not (seq chats)
(re-frame/dispatch [:search/home-filter-changed nil]))
:on-focus (fn [search-filter]
(when-not search-filter
(re-frame/dispatch [:search/home-filter-changed ""])))
@ -116,7 +118,7 @@
:data chats
:render-fn (fn [home-item] [inner-item/home-list-item home-item])
:header (when (or (seq chats) @search-active?)
[search-input-wrapper search-filter])
[search-input-wrapper search-filter chats])
:footer (if (and (not hide-home-tooltip?) (not @search-active?))
[home-tooltip-view]
[react/view {:height 68}])}]))))