Browse Source

enhance: show node icon for linked block

Tienson Qin 1 year ago
parent
commit
7852a6f0f6

+ 11 - 15
src/main/frontend/components/block.cljs

@@ -1896,10 +1896,6 @@
 
      (every? #(= % ["Horizontal_Rule"]) ast-body))))
 
-(defn- get-block-icon
-  [block]
-  (some :logseq.property/icon (cons block (:block/tags block))))
-
 (rum/defcs block-control < rum/reactive
   [state config block {:keys [uuid block-id collapsed? *control-show? edit? selected?]}]
   (let [doc-mode?          (state/sub :document/mode?)
@@ -1953,15 +1949,14 @@
                                      " hide-inner-bullet")
                                    (when order-list? " as-order-list typed-list"))}
 
-                      (let [icon (get-block-icon block)
-                            page? (db/page? block)]
+                      (let [icon (icon-component/get-node-icon-cp block {:size 16 :color? true})]
                         (cond
-                          link?
-                          (ui/icon "link" {:size 15})
-                          page?
-                          (ui/icon "page" {:size 15})
+                          (and (some? icon)
+                               (or (db/page? block)
+                                   (:logseq.property/icon block)
+                                   link?))
                           icon
-                          (icon-component/icon icon {:size 16 :color? true})
+
                           :else
                           [:span.bullet (cond->
                                          {:blockid (str uuid)}
@@ -3170,8 +3165,9 @@
         (when (and @*show-left-menu? (not in-whiteboard?) (not table?))
           (block-left-menu config block))
 
-        (let [icon' (get block (pu/get-pid :logseq.property/icon))]
-          (when-let [icon (and (ldb/page? block)
+        (when (:page-title? config)
+          (let [icon' (get block (pu/get-pid :logseq.property/icon))]
+            (when-let [icon (and (ldb/page? block)
                                (or icon'
                                    (some :logseq.property/icon (:block/tags block))
                                    (when (ldb/class? block)
@@ -3180,7 +3176,7 @@
                                    (when (ldb/property? block)
                                          {:type :tabler-icon
                                           :id "letter-p"})))]
-            [:div.ls-page-icon.flex.self-start
+            [:div.ls-page-icon.flex.self-start3
              (icon-component/icon-picker icon
                                          {:on-chosen (fn [_e icon]
                                                        (if icon
@@ -3195,7 +3191,7 @@
                                           :del-btn? (boolean icon')
                                           :icon-props {:style {:width "1lh"
                                                                :height "1lh"
-                                                               :font-size (if (:page-title? config) 38 18)}}})]))
+                                                               :font-size (if (:page-title? config) 38 18)}}})])))
 
         (if whiteboard-block?
           (block-reference {} (str uuid) nil)

+ 2 - 2
src/main/frontend/components/container.cljs

@@ -176,7 +176,7 @@
      (when (seq favorite-entities)
        (let [favorite-items (map
                              (fn [e]
-                               (let [icon (icon/get-node-icon e {})]
+                               (let [icon (icon/get-node-icon-cp e {})]
                                  {:id (str (:db/id e))
                                   :value (:block/uuid e)
                                   :content [:li.favorite-item (page-name e icon false)]}))
@@ -206,7 +206,7 @@
           :draggable true
           :on-drag-start (fn [event] (editor-handler/block->data-transfer! (:block/name page) event true))
           :data-ref name}
-         (page-name page (icon/get-node-icon page {}) true)])])))
+         (page-name page (icon/get-node-icon-cp page {}) true)])])))
 
 (rum/defcs flashcards < db-mixins/query rum/reactive
   {:did-mount (fn [state]

+ 16 - 10
src/main/frontend/components/icon.cljs

@@ -38,8 +38,8 @@
       item)))
 
 (defn get-node-icon
-  [node-entity opts]
-  (let [first-tag-icon (some :logseq.property/icon (:block/tags node-entity))
+  [node-entity]
+  (let [first-tag-icon (some :logseq.property/icon (sort-by :db/id (:block/tags node-entity)))
         default-icon-id (cond
                           (some? first-tag-icon)
                           first-tag-icon
@@ -52,13 +52,17 @@
                           (ldb/page? node-entity)
                           "page"
                           :else
-                          "letter-n")
-        opts' (assoc opts :size 14)
-        node-icon (or (get node-entity (pu/get-pid :logseq.property/icon))
-                    default-icon-id)]
+                          "letter-n")]
+    (or (get node-entity (pu/get-pid :logseq.property/icon))
+        default-icon-id)))
+
+(defn get-node-icon-cp
+  [node-entity opts]
+  (let [opts' (assoc opts :size 14)
+        node-icon (get-node-icon node-entity)]
     (when-not (string/blank? node-icon)
       [:span.flex (merge {:style {:color (or (:color node-icon) "inherit")}}
-                    (select-keys opts [:class]))
+                         (select-keys opts [:class]))
        (icon node-icon opts')])))
 
 (defn- search-emojis
@@ -455,7 +459,7 @@
      [initial-open?])
 
     ;; trigger
-    (let [has-icon? (not (nil? icon-value))]
+    (let [has-icon? (some? icon-value)]
       (shui/button
        {:ref *trigger-ref
         :variant (if has-icon? :ghost :text)
@@ -470,6 +474,8 @@
                                           :content-props {:class "ls-icon-picker"
                                                           :onEscapeKeyDown #(.preventDefault %)}}
                                          popup-opts))))}
-       (if has-icon?
-         (icon icon-value (merge {:color? true} icon-props))
+        (if has-icon?
+         (if (vector? icon-value)       ; hiccup
+           icon-value
+           (icon icon-value (merge {:color? true} icon-props)))
          (or empty-label "Empty"))))))

+ 1 - 1
src/main/frontend/components/right_sidebar.cljs

@@ -101,7 +101,7 @@
           page (db/entity repo lookup)]
       (if (ldb/page? page)
         [[:.flex.items-center.page-title
-          (icon/get-node-icon page {:class "text-md mr-2"})
+          (icon/get-node-icon-cp page {:class "text-md mr-2"})
           [:span.overflow-hidden.text-ellipsis (:block/title page)]]
          (page-cp repo (str (:block/uuid page)))]
         (block-with-breadcrumb repo page idx [repo db-id block-type] false)))