enhance(ux): add icon and tags for page reference search

pull/11433/head
Tienson Qin 2024-07-24 14:24:07 +08:00
parent 84c6799c3e
commit 8fc6fdf368
2 changed files with 42 additions and 24 deletions

View File

@ -143,13 +143,7 @@
[q])
(let [matched-pages (when-not (string/blank? q)
;; reorder, shortest and starts-with first.
(let [matched-pages
(->> matched-pages
(sort-by
(fn [block]
(let [m (:block/title block)]
[(not (gstring/caseInsensitiveStartsWith m q)) (count m) m]))))
matched-pages-with-new-page
(let [matched-pages-with-new-page
(fn [partial-matched-pages]
(if (or (db/page-exists? q)
(some (fn [p] (= (string/lower-case q)
@ -172,9 +166,29 @@
:on-enter (fn []
(page-handler/page-not-exists-handler input id q current-pos))
:item-render (fn [block _chosen?]
[:div.flex
(when (db-model/whiteboard-page? block) [:span.mr-1 (ui/icon "whiteboard" {:extension? true})])
(search-handler/highlight-exact-query (:block/title block) q)])
[:div.flex.flex-row.items-center.gap-1
(cond
(db-model/whiteboard-page? block)
[:div (ui/icon "whiteboard" {:extension? true})]
(db/page? block)
[:div (ui/icon "page" {:extension? true})]
(seq (:block/tags block))
[:div.flex (ui/icon "topology-star" {:size 14})]
(or (string/starts-with? (:block/title block) (t :new-class))
(string/starts-with? (:block/title block) (t :new-page)))
nil
:else
[:div (ui/icon "block" {:extension? true})])
(let [title (str (:block/title block)
" "
(string/join
", "
(keep (fn [block]
(when-let [title (:block/title block)]
(str "#" title)))
(:block/tags block))))]
(search-handler/highlight-exact-query title q))])
:empty-placeholder [:div.text-gray-500.text-sm.px-4.py-2 (if db-tag?
"Search for a class or a page"
"Search for a block")]

View File

@ -274,20 +274,24 @@
" title match ? order by rank limit ?")
matched-result (search-blocks-aux search-db match-sql match-input page limit enable-snippet?)
fuzzy-result (when-not page (fuzzy-search repo @conn q option))]
(->> (concat fuzzy-result matched-result)
(common-util/distinct-by :id)
(keep (fn [result]
(let [{:keys [id page title snippet]} result
block-id (uuid id)]
(when-let [block (d/entity @conn [:block/uuid block-id])]
(when-not (and (not built-in?) (ldb/built-in? block))
{:block/uuid block-id
:block/title (or snippet title)
:block/page (if (common-util/uuid-string? page)
(uuid page)
nil)
:block/tags (map :db/id (:block/tags block))
:page? (ldb/page? block)})))))))))
(let [result (->> (concat fuzzy-result matched-result)
(common-util/distinct-by :id)
(keep (fn [result]
(let [{:keys [id page title snippet]} result
block-id (uuid id)]
(when-let [block (d/entity @conn [:block/uuid block-id])]
(when-not (and (not built-in?) (ldb/built-in? block))
{:block/uuid block-id
:block/title (or snippet title)
:block/page (if (common-util/uuid-string? page)
(uuid page)
nil)
:block/tags (seq (map :db/id (:block/tags block)))
:page? (ldb/page? block)}))))))]
(->>
(concat (filter (fn [b] (or (:page? b) (:block/tags result))) result)
(remove (fn [b] (or (:page? b) (:block/tags result))) result))
(common-util/distinct-by :block/uuid))))))
(defn truncate-table!
[db]