Просмотр исходного кода

fix: don't show new page when search result is not ready

Tienson Qin 5 лет назад
Родитель
Сommit
dff669b903
1 измененных файлов с 8 добавлено и 6 удалено
  1. 8 6
      src/main/frontend/components/search.cljs

+ 8 - 6
src/main/frontend/components/search.cljs

@@ -124,8 +124,10 @@
   (when-let [input (gdom/getElement "search_field")]
   (when-let [input (gdom/getElement "search_field")]
     (.blur input)))
     (.blur input)))
 
 
+(defonce search-timeout (atom nil))
+
 (rum/defc search-auto-complete
 (rum/defc search-auto-complete
-  [{:keys [pages files blocks]} search-q]
+  [{:keys [pages files blocks] :as result} search-q]
   (rum/with-context [[t] i18n/*tongue-context*]
   (rum/with-context [[t] i18n/*tongue-context*]
     (let [new-file (when-let [ext (util/get-file-ext search-q)]
     (let [new-file (when-let [ext (util/get-file-ext search-q)]
                      (when (contains? config/mldoc-support-formats (keyword (string/lower-case ext)))
                      (when (contains? config/mldoc-support-formats (keyword (string/lower-case ext)))
@@ -133,9 +135,11 @@
           pages (map (fn [page] {:type :page :data page}) pages)
           pages (map (fn [page] {:type :page :data page}) pages)
           files (map (fn [file] {:type :file :data file}) files)
           files (map (fn [file] {:type :file :data file}) files)
           blocks (map (fn [block] {:type :block :data block}) blocks)
           blocks (map (fn [block] {:type :block :data block}) blocks)
-          new-page (if (and (seq pages)
-                            (= (string/lower-case search-q)
-                               (string/lower-case (:data (first pages)))))
+          new-page (if (or
+                        (and (seq pages)
+                             (= (string/lower-case search-q)
+                                (string/lower-case (:data (first pages)))))
+                        (nil? result))
                      []
                      []
                      [{:type :new-page}])
                      [{:type :new-page}])
           result (if config/publishing?
           result (if config/publishing?
@@ -225,8 +229,6 @@
 
 
                           nil))})])))
                           nil))})])))
 
 
-(defonce search-timeout (atom nil))
-
 (rum/defc search < rum/reactive
 (rum/defc search < rum/reactive
   (mixins/event-mixin
   (mixins/event-mixin
    (fn [state]
    (fn [state]