Przeglądaj źródła

fix: pages not resolved until visited

related to https://github.com/logseq/db-test/issues/291
Tienson Qin 7 miesięcy temu
rodzic
commit
9cf01cecdf

+ 9 - 4
deps/db/src/logseq/db/common/initial_data.cljs

@@ -200,10 +200,15 @@
    0))
 
 (defn ^:large-vars/cleanup-todo get-block-and-children
-  [db id {:keys [children? children-only? nested-children? properties children-props]}]
-  (let [block (d/entity db (if (uuid? id)
-                             [:block/uuid id]
-                             id))
+  [db id-or-page-name {:keys [children? children-only? nested-children? properties children-props]}]
+  (let [block (let [eid (cond (uuid? id-or-page-name) [:block/uuid id-or-page-name] (integer? id-or-page-name) id-or-page-name :else nil)]
+                (cond
+                  eid
+                  (d/entity db eid)
+                  (string? id-or-page-name)
+                  (d/entity db (get-first-page-by-name db (name id-or-page-name)))
+                  :else
+                  nil))
         block-refs-count? (some #{:block.temp/refs-count} properties)
         whiteboard? (common-entity-util/whiteboard? block)]
     (when block

+ 15 - 13
src/main/frontend/components/editor.cljs

@@ -9,6 +9,7 @@
             [frontend.context.i18n :refer [t]]
             [frontend.date :as date]
             [frontend.db :as db]
+            [frontend.db.async :as db-async]
             [frontend.db.model :as db-model]
             [frontend.extensions.zotero :as zotero]
             [frontend.handler.block :as block-handler]
@@ -153,12 +154,13 @@
         [matched-pages set-matched-pages!] (rum/use-state nil)
         search-f (fn []
                    (when-not (string/blank? q)
-                     (p/let [result (if db-tag?
-                                      (editor-handler/get-matched-classes q)
-                                      (p/let [result (editor-handler/<get-matched-blocks q {:nlp-pages? true
-                                                                                            :page-only? (not db-based?)})]
-                                        (reverse (sort-by (fn [result] (:page? result)) result))))]
-                       (set-matched-pages! result))))]
+                     (p/do!
+                      (db-async/<get-block (state/get-current-repo) q {:children? false})
+                      (p/let [result (if db-tag?
+                                       (editor-handler/get-matched-classes q)
+                                       (editor-handler/<get-matched-blocks q {:nlp-pages? true
+                                                                              :page-only? (not db-based?)}))]
+                        (set-matched-pages! result)))))]
     (hooks/use-effect! search-f [(hooks/use-debounced-value q 150)])
 
     (let [matched-pages' (if (string/blank? q)
@@ -219,13 +221,13 @@
                                  :else
                                  (ui/icon "letter-n" {:size 14}))])
 
-                            (let [title (if db-tag?
-                                          (let [target (first (:block/_alias block'))
-                                                title (:block/title block)]
-                                            (if (ldb/class? target)
-                                              (str title " -> alias: " (:block/title target))
-                                              title))
-                                          (block-handler/block-unique-title block'))]
+                            (let [title (let [target (first (:block/_alias block'))
+                                              title (if (and db-based? (not (ldb/built-in? block')))
+                                                      (block-handler/block-unique-title block')
+                                                      (:block/title block'))]
+                                          (if target
+                                            (str title " -> alias: " (:block/title target))
+                                            title))]
                               (if (or (string/starts-with? title (t :new-tag))
                                       (string/starts-with? title (t :new-page)))
                                 title

+ 7 - 6
src/main/frontend/handler/editor.cljs

@@ -1601,12 +1601,13 @@
           result (search/block-search (state/get-current-repo) q {:built-in? false
                                                                   :enable-snippet? false
                                                                   :page-only? page-only?})
-          matched (remove (fn [b] (= (:block/uuid b) (:block/uuid block))) result)]
-    (-> (concat matched
-                (when nlp-pages?
-                  (map (fn [title] {:block/title title :nlp-date? true})
-                       date/nlp-pages)))
-        (search/fuzzy-search q {:extract-fn :block/title :limit 50}))))
+          matched (remove (fn [b] (= (:block/uuid b) (:block/uuid block))) result)
+          result' (-> (concat matched
+                              (when nlp-pages?
+                                (map (fn [title] {:block/title title :nlp-date? true :page? true})
+                                     date/nlp-pages)))
+                      (search/fuzzy-search q {:extract-fn :block/title :limit 50}))]
+    (sort-by (complement :page?) result')))
 
 (defn <get-matched-templates
   [q]