|
3 | 3 | [dommy.core :as dom] |
4 | 4 | [frontend.commands :as commands :refer [*matched-commands]] |
5 | 5 | [frontend.components.file-based.datetime :as datetime-comp] |
6 | | - [frontend.components.search :as search] |
| 6 | + [frontend.components.icon :as icon-component] |
7 | 7 | [frontend.components.svg :as svg] |
8 | 8 | [frontend.config :as config] |
9 | 9 | [frontend.context.i18n :refer [t]] |
|
51 | 51 | (contains? #{"TASK STATUS" "TASK DATE" "PRIORITY"} (last item))))) commands) |
52 | 52 | commands)) |
53 | 53 |
|
| 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 | + |
54 | 96 | (rum/defcs commands < rum/reactive |
55 | 97 | (rum/local [] ::matched-commands) |
56 | 98 | [s id format] |
|
202 | 244 | :on-enter (fn [] |
203 | 245 | (page-handler/page-not-exists-handler input id q current-pos)) |
204 | 246 | :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?})) |
255 | 249 | :empty-placeholder [:div.text-gray-500.text-sm.px-4.py-2 (if db-tag? |
256 | 250 | "Search for a tag" |
257 | 251 | "Search for a node")] |
|
339 | 333 | {:on-chosen chosen-handler |
340 | 334 | :on-enter non-exist-block-handler |
341 | 335 | :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?})) |
348 | 339 | :class "ac-block-search"}))) |
349 | 340 |
|
350 | 341 | (rum/defcs block-search < rum/reactive |
|
0 commit comments