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

View File

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