Răsfoiți Sursa

enhance: when depth level > 3, the breadcrumb displays an ellipsis

The default level is 9 when zoom into a block.

close #468
Tienson Qin 4 ani în urmă
părinte
comite
eaeca30e58

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

@@ -1939,13 +1939,19 @@
 (rum/defc breadcrumb-separator [] [:span.mx-2.opacity-50 "➤"])
 
 (defn block-parents
-  [config repo block-id {:keys [show-page? indent?]
-                                :or {show-page? true}}]
-  (let [parents (db/get-block-parents repo block-id 3)
+  [config repo block-id {:keys [show-page? indent? level-limit]
+                         :or {show-page? true
+                              level-limit 3}}]
+  (let [parents (db/get-block-parents repo block-id (inc level-limit))
         page (db/get-block-page repo block-id)
         page-name (:block/name page)
         page-original-name (:block/original-name page)
-        show? (or (seq parents) show-page? page-name)]
+        show? (or (seq parents) show-page? page-name)
+        parents (if (= page-name (:block/name (first parents)))
+                  (rest parents)
+                  parents)
+        more? (> (count parents) level-limit)
+        parents (if more? (take-last level-limit parents) parents)]
     (when show?
       (let [page-name-props (when show-page?
                               [:page
@@ -1956,9 +1962,12 @@
                                [block
                                 (->elem :span (map-inline config title))])))
             breadcrumb (->> (into [] parents-props)
-                            (concat [page-name-props])
+                            (concat [page-name-props] (when more? [:more]))
                             (filterv identity)
-                            (map (fn [[block label]] (breadcrumb-fragment config block label)))
+                            (map (fn [x] (if (vector? x)
+                                          (let [[block label] x]
+                                            (breadcrumb-fragment config block label))
+                                          [:span.opacity-70 "⋯"])))
                             (interpose (breadcrumb-separator)))]
         [:div.block-parents.flex-row.flex-1
          {:class (when (seq breadcrumb)

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

@@ -330,7 +330,7 @@
                (let [config {:id "block-parent"
                              :block? true}]
                  [:div.mb-4
-                  (block/block-parents config repo block-id {})]))
+                  (block/block-parents config repo block-id {:level-limit 3})]))
 
              ;; blocks
              (let [page (if block?