Browse Source

fix(regression): "icon::" property doesn't work for file graphs

fixed https://github.com/logseq/db-test/issues/378
Tienson Qin 4 months ago
parent
commit
4caa79a227

+ 98 - 96
src/main/frontend/components/container.cljs

@@ -81,101 +81,104 @@
        [:span.b (or more (ui/icon "chevron-right" {:class "more" :size 15}))]]
       (when child [:div.bd child])]]))
 
-(rum/defc page-name
-  [page icon recent?]
-  (let [repo (state/get-current-repo)
-        db-based? (config/db-based-graph? repo)
-        title (:block/title page)
-        untitled? (db-model/untitled-page? title)
-        name (:block/name page)
-        file-rpath (when (util/electron?) (page-util/get-page-file-rpath name))
-        ctx-icon #(shui/tabler-icon %1 {:class "scale-90 pr-1 opacity-80"})
-        open-in-sidebar #(state/sidebar-add-block!
-                          (state/get-current-repo)
-                          (:db/id page)
-                          :page)
-        x-menu-content (fn []
-                         (let [x-menu-item shui/dropdown-menu-item
-                               x-menu-shortcut shui/dropdown-menu-shortcut]
-                           [:<>
-                            (when-not recent?
+(rum/defc page-name < rum/reactive db-mixins/query
+  [page recent?]
+  (when-let [id (:db/id page)]
+    (let [page (db/sub-block id)
+          repo (state/get-current-repo)
+          db-based? (config/db-based-graph? repo)
+          icon (icon/get-node-icon-cp page {:size 16})
+          title (:block/title page)
+          untitled? (db-model/untitled-page? title)
+          name (:block/name page)
+          file-rpath (when (util/electron?) (page-util/get-page-file-rpath name))
+          ctx-icon #(shui/tabler-icon %1 {:class "scale-90 pr-1 opacity-80"})
+          open-in-sidebar #(state/sidebar-add-block!
+                            (state/get-current-repo)
+                            (:db/id page)
+                            :page)
+          x-menu-content (fn []
+                           (let [x-menu-item shui/dropdown-menu-item
+                                 x-menu-shortcut shui/dropdown-menu-shortcut]
+                             [:<>
+                              (when-not recent?
+                                (x-menu-item
+                                 {:key "unfavorite"
+                                  :on-click #(page-handler/<unfavorite-page! (if db-based? (str (:block/uuid page)) title))}
+                                 (ctx-icon "star-off")
+                                 (t :page/unfavorite)
+                                 (x-menu-shortcut (when-let [binding (shortcut-dh/shortcut-binding :command/toggle-favorite)]
+                                                    (some-> binding
+                                                            (first)
+                                                            (shortcut-utils/decorate-binding))))))
+                              (when-let [page-fpath (and (util/electron?) file-rpath
+                                                         (config/get-repo-fpath (state/get-current-repo) file-rpath))]
+                                [:<>
+                                 (x-menu-item
+                                  {:key "open-in-folder"
+                                   :on-click #(ipc/ipc :openFileInFolder page-fpath)}
+                                  (ctx-icon "folder")
+                                  (t :page/open-in-finder))
+
+                                 (x-menu-item
+                                  {:key "open with default app"
+                                   :on-click #(js/window.apis.openPath page-fpath)}
+                                  (ctx-icon "file")
+                                  (t :page/open-with-default-app))])
                               (x-menu-item
-                               {:key "unfavorite"
-                                :on-click #(page-handler/<unfavorite-page! (if db-based? (str (:block/uuid page)) title))}
-                               (ctx-icon "star-off")
-                               (t :page/unfavorite)
-                               (x-menu-shortcut (when-let [binding (shortcut-dh/shortcut-binding :command/toggle-favorite)]
-                                                  (some-> binding
-                                                          (first)
-                                                          (shortcut-utils/decorate-binding))))))
-                            (when-let [page-fpath (and (util/electron?) file-rpath
-                                                       (config/get-repo-fpath (state/get-current-repo) file-rpath))]
-                              [:<>
-                               (x-menu-item
-                                {:key "open-in-folder"
-                                 :on-click #(ipc/ipc :openFileInFolder page-fpath)}
-                                (ctx-icon "folder")
-                                (t :page/open-in-finder))
-
-                               (x-menu-item
-                                {:key "open with default app"
-                                 :on-click #(js/window.apis.openPath page-fpath)}
-                                (ctx-icon "file")
-                                (t :page/open-with-default-app))])
-                            (x-menu-item
-                             {:key "open in sidebar"
-                              :on-click open-in-sidebar}
-                             (ctx-icon "layout-sidebar-right")
-                             (t :content/open-in-sidebar)
-                             (x-menu-shortcut (shortcut-utils/decorate-binding "shift+click")))]))]
+                               {:key "open in sidebar"
+                                :on-click open-in-sidebar}
+                               (ctx-icon "layout-sidebar-right")
+                               (t :content/open-in-sidebar)
+                               (x-menu-shortcut (shortcut-utils/decorate-binding "shift+click")))]))]
 
     ;; TODO: move to standalone component
-    [:a.link-item.group
-     (cond->
-      {:on-click
-       (fn [e]
-         (if (gobj/get e "shiftKey")
-           (open-in-sidebar)
-           (route-handler/redirect-to-page! (:block/uuid page) {:click-from-recent? recent?})))
-       :on-context-menu (fn [^js e]
-                          (shui/popup-show! e (x-menu-content)
-                                            {:as-dropdown? true
-                                             :content-props {:on-click (fn [] (shui/popup-hide!))
-                                                             :class "w-60"}})
-                          (util/stop e))}
-       (ldb/object? page)
-       (assoc :title (block-handler/block-unique-title page)))
-     [:span.page-icon {:key "page-icon"} icon]
-     [:span.page-title {:key "title"
-                        :class (when untitled? "opacity-50")
-                        :style {:display "ruby"}}
-      (cond
-        (not (db/page? page))
-        (block/inline-text :markdown (:block/title page))
-        untitled? (t :untitled)
-        :else (let [title' (pdf-utils/fix-local-asset-pagename title)
-                    parent (:block/parent page)]
-                (if (and parent
-                         (not (or (ldb/class? page)
-                                  (and (:logseq.property/built-in? parent)
-                                       (= (:block/title parent)
-                                          common-config/library-page-name)))))
-                  (str (:block/title parent) ns-util/parent-char title')
-                  title')))]
+      [:a.link-item.group
+       (cond->
+        {:on-click
+         (fn [e]
+           (if (gobj/get e "shiftKey")
+             (open-in-sidebar)
+             (route-handler/redirect-to-page! (:block/uuid page) {:click-from-recent? recent?})))
+         :on-context-menu (fn [^js e]
+                            (shui/popup-show! e (x-menu-content)
+                                              {:as-dropdown? true
+                                               :content-props {:on-click (fn [] (shui/popup-hide!))
+                                                               :class "w-60"}})
+                            (util/stop e))}
+         (ldb/object? page)
+         (assoc :title (block-handler/block-unique-title page)))
+       [:span.page-icon {:key "page-icon"} icon]
+       [:span.page-title {:key "title"
+                          :class (when untitled? "opacity-50")
+                          :style {:display "ruby"}}
+        (cond
+          (not (db/page? page))
+          (block/inline-text :markdown (:block/title page))
+          untitled? (t :untitled)
+          :else (let [title' (pdf-utils/fix-local-asset-pagename title)
+                      parent (:block/parent page)]
+                  (if (and parent
+                           (not (or (ldb/class? page)
+                                    (and (:logseq.property/built-in? parent)
+                                         (= (:block/title parent)
+                                            common-config/library-page-name)))))
+                    (str (:block/title parent) ns-util/parent-char title')
+                    title')))]
 
      ;; dots trigger
-     (shui/button
-      {:key "more actions"
-       :size :sm
-       :variant :ghost
-       :class "absolute !bg-transparent right-0 top-0 px-1.5 scale-75 opacity-40 hidden group-hover:block hover:opacity-80 active:opacity-100"
-       :on-click #(do
-                    (shui/popup-show! (.-target %) (x-menu-content)
-                                      {:as-dropdown? true
-                                       :content-props {:on-click (fn [] (shui/popup-hide!))
-                                                       :class "w-60"}})
-                    (util/stop %))}
-      [:i.relative {:style {:top "4px"}} (shui/tabler-icon "dots")])]))
+       (shui/button
+        {:key "more actions"
+         :size :sm
+         :variant :ghost
+         :class "absolute !bg-transparent right-0 top-0 px-1.5 scale-75 opacity-40 hidden group-hover:block hover:opacity-80 active:opacity-100"
+         :on-click #(do
+                      (shui/popup-show! (.-target %) (x-menu-content)
+                                        {:as-dropdown? true
+                                         :content-props {:on-click (fn [] (shui/popup-hide!))
+                                                         :class "w-60"}})
+                      (util/stop %))}
+        [:i.relative {:style {:top "4px"}} (shui/tabler-icon "dots")])])))
 
 (defn sidebar-item
   [{:keys [on-click-handler class title icon icon-extension? active href shortcut more]}]
@@ -352,10 +355,9 @@
      (when (seq favorite-entities)
        (let [favorite-items (map
                              (fn [e]
-                               (let [icon (icon/get-node-icon-cp e {:size 16})]
-                                 {:id (str (:db/id e))
-                                  :value (:block/uuid e)
-                                  :content [:li.favorite-item.font-medium (page-name e icon false)]}))
+                               {:id (str (:db/id e))
+                                :value (:block/uuid e)
+                                :content [:li.favorite-item.font-medium (page-name e false)]})
                              favorite-entities)]
          (dnd-component/items favorite-items
                               {:on-drag-end (fn [favorites']
@@ -376,7 +378,7 @@
         [:li.recent-item.select-none.font-medium
          {:key (str "recent-" (:db/id page))
           :title (block-handler/block-unique-title page)}
-         (page-name page (icon/get-node-icon-cp page {:size 16}) true)])])))
+         (page-name page true)])])))
 
 (defn get-default-home-if-valid
   []
@@ -467,7 +469,7 @@
        [:div.sidebar-header-container
         ;; sidebar graphs
         (when (not config/publishing?)
-         (sidebar-graphs))
+          (sidebar-graphs))
 
         ;; sidebar sticky navigations
         (sidebar-navigations

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

@@ -35,7 +35,10 @@
                                   opts)]]
 
                (and (= :tabler-icon (:type icon')) (:id icon'))
-               (ui/icon (:id icon') opts))]
+               (ui/icon (:id icon') opts)
+
+               :else
+               icon')]
     (if color?
       [:span.inline-flex.items-center.ls-icon-color-wrap
        {:style {:color (or (some-> icon' :color) "inherit")}} item]
@@ -65,13 +68,18 @@
 (defn get-node-icon-cp
   [node-entity opts]
   (let [opts' (merge {:size 14} opts)
-        node-icon (cond
-                    (:own-icon? opts)
-                    (get node-entity (pu/get-pid :logseq.property/icon))
-                    (:link? opts)
-                    "arrow-narrow-right"
-                    :else
-                    (get-node-icon node-entity))]
+        node-icon* (cond
+                     (:own-icon? opts)
+                     (get node-entity (pu/get-pid :logseq.property/icon))
+                     (:link? opts)
+                     "arrow-narrow-right"
+                     :else
+                     (get-node-icon node-entity))
+        node-icon (if (config/db-based-graph?)
+                    node-icon*
+                    (or (when-let [icon' (get-in node-entity [:block/properties :icon])]
+                          [:span icon'])
+                        node-icon*))]
     (when-not (or (string/blank? node-icon) (and (contains? #{"letter-n" "file"} node-icon) (:not-text-or-page? opts)))
       [:div.icon-cp-container.flex.items-center
        (merge {:style {:color (or (:color node-icon) "inherit")}}

+ 4 - 0
src/main/frontend/components/page.cljs

@@ -8,6 +8,7 @@
             [frontend.components.db-based.page :as db-page]
             [frontend.components.editor :as editor]
             [frontend.components.file-based.hierarchy :as hierarchy]
+            [frontend.components.icon :as icon-component]
             [frontend.components.library :as library]
             [frontend.components.objects :as objects]
             [frontend.components.plugins :as plugins]
@@ -342,6 +343,9 @@
                                         (not (ldb/built-in? page)))
                                (reset! *input-value (if untitled? "" old-name))
                                (reset! *edit? true)))))}
+            (when-not (config/db-based-graph?)
+              (when (get-in page [:block/properties :icon])
+                (icon-component/get-node-icon-cp page {})))
 
             (if @*edit?
               (page-title-editor page {:*title-value *title-value