Skip to content

Commit a7c8212

Browse files
committed
enhance(ux): same node render for both reference and embed
also use icon-component/get-node-icon-cp when possible
1 parent 3b99f13 commit a7c8212

File tree

6 files changed

+58
-113
lines changed

6 files changed

+58
-113
lines changed

src/main/frontend/components/cmdk/core.cljs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[electron.ipc :as ipc]
55
[frontend.components.block :as block]
66
[frontend.components.cmdk.list-item :as list-item]
7+
[frontend.components.icon :as icon-component]
78
[frontend.config :as config]
89
[frontend.context.i18n :refer [t]]
910
[frontend.db :as db]
@@ -206,24 +207,12 @@
206207
;; Each result group has it's own load-results function
207208
(defmulti load-results (fn [group _state] group))
208209

209-
(defn get-page-icon
210-
[entity]
211-
(cond
212-
(ldb/class? entity)
213-
"hash"
214-
(ldb/property? entity)
215-
"letter-p"
216-
(ldb/whiteboard? entity)
217-
"writing"
218-
:else
219-
"file"))
220-
221210
(defmethod load-results :initial [_ state]
222211
(when-let [db (db/get-db)]
223212
(let [!results (::results state)
224213
recent-pages (map (fn [block]
225214
(let [text (block-handler/block-unique-title block)
226-
icon (get-page-icon block)]
215+
icon (icon-component/get-node-icon-cp block {})]
227216
{:icon icon
228217
:icon-theme :gray
229218
:text text
@@ -261,7 +250,7 @@
261250
(->> search-results
262251
(map (fn [block]
263252
(let [text (block-handler/block-unique-title block)
264-
icon (get-page-icon block)]
253+
icon (icon-component/get-node-icon-cp block {})]
265254
{:icon icon
266255
:icon-theme :gray
267256
:text text
@@ -289,7 +278,7 @@
289278
(let [entity (db/entity [:block/uuid (:block/uuid page)])
290279
source-page (or (model/get-alias-source-page repo (:db/id entity))
291280
(:alias page))
292-
icon (get-page-icon entity)
281+
icon (icon-component/get-node-icon-cp entity {})
293282
title (block-handler/block-unique-title (or entity page))
294283
title' (if source-page (str title " -> alias: " (:block/title source-page)) title)]
295284
(hash-map :icon icon
@@ -306,7 +295,7 @@
306295
[repo block current-page input]
307296
(let [id (:block/uuid block)
308297
text (block-handler/block-unique-title block)
309-
icon "letter-n"]
298+
icon (icon-component/get-node-icon-cp block {})]
310299
{:icon icon
311300
:icon-theme :gray
312301
:text (highlight-content-query text input)

src/main/frontend/components/cmdk/list_item.cljs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@
9292
(if highlighted "bg-accent-07-alpha" "bg-gray-05")
9393
" dark:text-white")
9494
(= icon-theme :gray) (str " bg-gray-05 dark:text-white"))}
95-
(shui/tabler-icon icon {:size "14" :class ""})]
95+
(if (string? icon)
96+
(shui/tabler-icon icon {:size "14" :class ""})
97+
icon)]
9698
[:div.flex.flex-1.flex-col
9799
(when title
98100
[:div.text-sm.pb-2.font-bold.text-gray-11 (highlight-query title)])

src/main/frontend/components/editor.cljs

Lines changed: 48 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[dommy.core :as dom]
44
[frontend.commands :as commands :refer [*matched-commands]]
55
[frontend.components.file-based.datetime :as datetime-comp]
6-
[frontend.components.search :as search]
6+
[frontend.components.icon :as icon-component]
77
[frontend.components.svg :as svg]
88
[frontend.config :as config]
99
[frontend.context.i18n :refer [t]]
@@ -51,6 +51,48 @@
5151
(contains? #{"TASK STATUS" "TASK DATE" "PRIORITY"} (last item))))) commands)
5252
commands))
5353

54+
(defn node-render
55+
[block q {:keys [db-tag? db-based?]}]
56+
(let [block' (if-let [id (:block/uuid block)]
57+
(if-let [e (db/entity [:block/uuid id])]
58+
(assoc e
59+
:block/title (or (:friendly-title block) (:block/title e) (:block/title block))
60+
:alias (:alias block))
61+
block)
62+
block)]
63+
(when-not (string/blank? (:block/title block'))
64+
[:div.flex.flex-col
65+
(when (and (:block/uuid block') (or (:block/parent block') (not (:page? block))))
66+
(when-let [breadcrumb (state/get-component :block/breadcrumb)]
67+
[:div.text-xs.opacity-70.mb-1 {:style {:margin-left 3}}
68+
(breadcrumb {:search? true} (state/get-current-repo) (:block/uuid block')
69+
{:disabled? true})]))
70+
[:div.flex.flex-row.items-start
71+
(when-not (or db-tag? (not db-based?))
72+
[:div.flex.items-center.h-5.mr-1.opacity-50
73+
(cond
74+
(:nlp-date? block')
75+
(ui/icon "calendar" {:size 14})
76+
77+
(or (string/starts-with? (str (:block/title block')) (t :new-tag))
78+
(string/starts-with? (str (:block/title block')) (t :new-page)))
79+
(ui/icon "plus" {:size 14})
80+
81+
:else
82+
(icon-component/get-node-icon-cp block' {}))])
83+
84+
(let [title (let [alias (get-in block' [:alias :block/title])
85+
title (if (and db-based? (not (ldb/built-in? block')))
86+
(block-handler/block-unique-title block')
87+
(:block/title block'))]
88+
(if alias
89+
(str title " -> alias: " alias)
90+
title))]
91+
(if (or (string/starts-with? title (t :new-tag))
92+
(string/starts-with? title (t :new-page)))
93+
title
94+
(search-handler/highlight-exact-query title q)))]])))
95+
5496
(rum/defcs commands < rum/reactive
5597
(rum/local [] ::matched-commands)
5698
[s id format]
@@ -202,56 +244,8 @@
202244
:on-enter (fn []
203245
(page-handler/page-not-exists-handler input id q current-pos))
204246
:item-render (fn [block _chosen?]
205-
(let [block' (if-let [id (:block/uuid block)]
206-
(if-let [e (db/entity [:block/uuid id])]
207-
(assoc e
208-
:block/title (or (:friendly-title block) (:block/title e) (:block/title block))
209-
:alias (:alias block))
210-
block)
211-
block)]
212-
[:div.flex.flex-col
213-
(when (and (:block/uuid block') (or (:block/parent block') (not (:page? block))))
214-
(when-let [breadcrumb (state/get-component :block/breadcrumb)]
215-
[:div.text-xs.opacity-70.mb-1 {:style {:margin-left 3}}
216-
(breadcrumb {:search? true} (state/get-current-repo) (:block/uuid block')
217-
{:disabled? true})]))
218-
[:div.flex.flex-row.items-start
219-
(when-not (or db-tag? (not db-based?))
220-
[:div.flex.items-center.h-5.mr-1.opacity-50
221-
(cond
222-
(:nlp-date? block')
223-
(ui/icon "calendar" {:size 14})
224-
225-
(ldb/class? block')
226-
(ui/icon "hash" {:size 14})
227-
228-
(ldb/property? block')
229-
(ui/icon "letter-p" {:size 14})
230-
231-
(db-model/whiteboard-page? block')
232-
(ui/icon "writing" {:size 14})
233-
234-
(or (ldb/page? block') (:page? block))
235-
(ui/icon "file" {:size 14})
236-
237-
(or (string/starts-with? (str (:block/title block')) (t :new-tag))
238-
(string/starts-with? (str (:block/title block')) (t :new-page)))
239-
(ui/icon "plus" {:size 14})
240-
241-
:else
242-
(ui/icon "letter-n" {:size 14}))])
243-
244-
(let [title (let [alias (get-in block' [:alias :block/title])
245-
title (if (and db-based? (not (ldb/built-in? block')))
246-
(block-handler/block-unique-title block')
247-
(:block/title block'))]
248-
(if alias
249-
(str title " -> alias: " alias)
250-
title))]
251-
(if (or (string/starts-with? title (t :new-tag))
252-
(string/starts-with? title (t :new-page)))
253-
title
254-
(search-handler/highlight-exact-query title q)))]]))
247+
(node-render block q {:db-tag? db-tag?
248+
:db-based? db-based?}))
255249
:empty-placeholder [:div.text-gray-500.text-sm.px-4.py-2 (if db-tag?
256250
"Search for a tag"
257251
"Search for a node")]
@@ -339,12 +333,9 @@
339333
{:on-chosen chosen-handler
340334
:on-enter non-exist-block-handler
341335
:empty-placeholder [:div.text-gray-500.text-sm.px-4.py-2 (t :editor/block-search)]
342-
:item-render (fn [{:block/keys [page uuid title]}]
343-
(let [page-entity (db/entity [:block/uuid page])
344-
repo (state/sub :git/current-repo)
345-
format (get page-entity :block/format :markdown)]
346-
(when-not (string/blank? title)
347-
[:.py-2 (search/block-search-result-item repo uuid format title q :block)])))
336+
:item-render (fn [block]
337+
(node-render block q {:db-tag? false
338+
:db-based? db?}))
348339
:class "ac-block-search"})))
349340

350341
(rum/defcs block-search < rum/reactive

src/main/frontend/components/property/value.cljs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -653,18 +653,6 @@
653653
:close-modal? false
654654
k f'))))
655655
656-
(defn- get-node-icon
657-
[node]
658-
(cond
659-
(ldb/class? node)
660-
"hash"
661-
(ldb/property? node)
662-
"letter-p"
663-
(entity-util/page? node)
664-
"page"
665-
:else
666-
"letter-n"))
667-
668656
(rum/defc ^:large-vars/cleanup-todo select-node < rum/static
669657
[property
670658
{:keys [block multiple-choices? dropdown? input-opts on-input add-new-choice! target] :as opts}
@@ -760,7 +748,7 @@
760748
(block-handler/block-unique-title node))]
761749
(let [title (subs node-title 0 256)
762750
node (or (db/entity id) node)
763-
icon (get-node-icon node)
751+
icon (icon-component/get-node-icon-cp node {})
764752
header (when-not (db/page? node)
765753
(when-let [breadcrumb (state/get-component :block/breadcrumb)]
766754
[:div.text-xs.opacity-70
@@ -769,7 +757,7 @@
769757
label [:div.flex.flex-row.items-center.gap-1
770758
(when-not (or (:logseq.property/classes property)
771759
(contains? #{:class :property} (:logseq.property/type property)))
772-
(ui/icon icon {:size 14}))
760+
icon)
773761
[:div title]]]
774762
[header label]))
775763
[nil (:block/title node)])]

src/main/frontend/components/search.cljs

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/main/frontend/handler/search.cljs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,9 @@
1313
[frontend.storage :as storage]
1414
[frontend.util :as util]
1515
[logseq.db :as ldb]
16-
[logseq.graph-parser.text :as text]
1716
[missionary.core :as m]
1817
[promesa.core :as p]))
1918

20-
(defn sanity-search-content
21-
"Convert a block to the display contents for searching"
22-
[format content]
23-
(text/remove-level-spaces content format (config/get-block-pattern format)))
24-
2519
(defn search
2620
"The aggretation of search results"
2721
([q]

0 commit comments

Comments
 (0)