Browse Source

fix: list view

Tienson Qin 8 months ago
parent
commit
a8aa1daccc

+ 14 - 8
src/main/frontend/components/block.cljs

@@ -3389,13 +3389,7 @@
 
 (rum/defcs ^:large-vars/cleanup-todo block-container-inner < rum/reactive db-mixins/query
   {:init (fn [state]
-           (let [*ref (atom nil)
-                 args (:rum/args state)
-                 [_state _ config block] args
-                 block-id (:db/id block)
-                 repo (state/get-current-repo)]
-             (when-not (or (:table-view? config) (:property-block? config))
-               (db-async/<get-block repo block-id :children? true))
+           (let [*ref (atom nil)]
              (assoc state ::ref *ref)))}
   [state container-state repo config* block {:keys [navigating-block navigated?]}]
   (let [*ref (::ref state)
@@ -3633,7 +3627,7 @@
                                    (select-keys (first (:rum/args new-state)) config-compare-keys)))]
     (boolean result)))
 
-(rum/defcs block-container < rum/reactive db-mixins/query
+(rum/defcs loaded-block-container < rum/reactive db-mixins/query
   (rum/local false ::show-block-left-menu?)
   (rum/local false ::show-block-right-menu?)
   {:should-update config-block-should-update?}
@@ -3691,6 +3685,18 @@
               "-"
               (:block/uuid block)))))))
 
+(rum/defc block-container
+  [config block*]
+  (let [[block set-block!] (hooks/use-state (some-> (:db/id block*) db/entity))]
+    (when-not (:page-title? config)
+      (hooks/use-effect!
+       (fn []
+         (p/do!
+          (db-async/<get-block (state/get-current-repo) (:db/id block*))
+          (set-block! (some-> (:db/id block*) db/entity))))
+       []))
+    (loaded-block-container config block)))
+
 (defn divide-lists
   [[f & l]]
   (loop [l        l

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

@@ -748,7 +748,7 @@
                  page-uuid? (util/uuid-string? page-name')
                  *loading? (atom true)
                  page (db/get-page page-name')]
-             (when page (reset! *loading? false))
+             (when (:block.temp/fully-loaded? page) (reset! *loading? false))
              (p/let [page-block (db-async/<get-block (state/get-current-repo) page-name')]
                (reset! *loading? false)
                (when page-block
@@ -763,8 +763,9 @@
                    (state/set-state! :editor/virtualized-scroll-fn nil)
                    state)}
   [state option]
-  (when-not (rum/react (::loading? state))
-    (page-inner option)))
+  (let [loading? (rum/react (::loading? state))]
+    (when-not loading?
+      (page-inner option))))
 
 (rum/defcs page-cp
   [state option]

+ 1 - 18
src/main/frontend/components/property.cljs

@@ -579,28 +579,13 @@
                                    (:block/order (db/entity k)))) properties)]
       (ordered-properties block properties' opts))))
 
-(defn- async-load-classes!
-  [block]
-  (let [repo (state/get-current-repo)
-        classes (concat (:block/tags block) (outliner-property/get-classes-parents (:block/tags block)))]
-    (doseq [class classes]
-      (db-async/<get-block repo (:db/id class) :children? false))
-    (when (ldb/class? block)
-      (doseq [property (:logseq.property.class/properties block)]
-        (db-async/<get-block repo (:db/id property) :children? false)))
-    classes))
-
 (rum/defcs ^:large-vars/cleanup-todo properties-area < rum/reactive db-mixins/query
   {:init (fn [state]
            (let [target-block (first (:rum/args state))
                  block (resolve-linked-block-if-exists target-block)]
              (assoc state
                     ::id (str (random-uuid))
-                    ::block block
-                    ::classes (async-load-classes! block))))
-   :will-remount (fn [state]
-                   (let [block (db/entity (:db/id (::block state)))]
-                     (assoc state ::classes (async-load-classes! block))))}
+                    ::block block)))}
   [state _target-block {:keys [sidebar-properties?] :as opts}]
   (let [id (::id state)
         db-id (:db/id (::block state))
@@ -609,8 +594,6 @@
                                             (and show?
                                                  (or (= mode :global)
                                                      (and (set? ids) (contains? ids (:block/uuid block))))))
-        _ (doseq [class (::classes state)]
-            (db/sub-block (:db/id class)))
         class? (ldb/class? block)
         properties (:block/properties block)
         remove-built-in-or-other-position-properties

+ 5 - 14
src/main/frontend/components/reference.cljs

@@ -164,7 +164,7 @@
    (references* entity)))
 
 (rum/defcs unlinked-references-aux
-  [state page _n-ref]
+  [state page]
   (views/view
    {:view-parent page
     :view-feature-type :unlinked-references
@@ -172,17 +172,8 @@
     :foldable-options {:default-collapsed? true}}))
 
 (rum/defcs unlinked-references < rum/reactive
-  (rum/local nil ::n-ref)
   [state page]
-  (let [n-ref (get state ::n-ref)]
-    (when page
-      [:div.references.page-unlinked.mt-6.flex-1.flex-row.faster.fade-in
-       [:div.content.flex-1
-        (if (config/db-based-graph?)
-          (unlinked-references-aux page n-ref)
-          (ui/foldable
-           [:div.font-medium.opacity-50
-            (t :unlinked-references/reference-count @n-ref)]
-           (fn [] (unlinked-references-aux page n-ref))
-           {:default-collapsed? true
-            :title-trigger? true}))]])))
+  (when page
+    [:div.references.page-unlinked.mt-6.flex-1.flex-row.faster.fade-in
+     [:div.content.flex-1
+      (unlinked-references-aux page)]]))

+ 19 - 15
src/main/frontend/components/views.cljs

@@ -1142,21 +1142,25 @@
 
 (rum/defc list-view < rum/static
   [{:keys [config view-feature-type]} view-entity result]
-  (when-let [->hiccup (state/get-component :block/->hiccup)]
-    (let [group-by-page? (not (every? db/page? result))
-          result (if group-by-page?
-                   (-> (group-by :block/page result)
-                       (update-vals ldb/sort-by-order))
-                   result)
-          config' (cond-> (assoc config
-                                 :current-block (:db/id view-entity)
-                                 :query (:block/title view-entity)
-                                 :breadcrumb-show? (if group-by-page? true false)
-                                 :group-by-page? group-by-page?
-                                 :ref? true)
-                    (= view-feature-type :query-result)
-                    (assoc :query (:block/title view-entity)))]
-      (->hiccup result config'))))
+  (for [id result]
+    [:div
+     (block-container {} {:db/id id} {})])
+  ;; (when-let [->hiccup (state/get-component :block/->hiccup)]
+  ;;   (let [group-by-page? (not (every? db/page? result))
+  ;;         result (if group-by-page?
+  ;;                  (-> (group-by :block/page result)
+  ;;                      (update-vals ldb/sort-by-order))
+  ;;                  result)
+  ;;         config' (cond-> (assoc config
+  ;;                                :current-block (:db/id view-entity)
+  ;;                                :query (:block/title view-entity)
+  ;;                                :breadcrumb-show? (if group-by-page? true false)
+  ;;                                :group-by-page? group-by-page?
+  ;;                                :ref? true)
+  ;;                   (= view-feature-type :query-result)
+  ;;                   (assoc :query (:block/title view-entity)))]
+  ;;     (->hiccup result config')))
+  )
 
 (rum/defc gallery-card-item
   [table view-entity block config]

+ 1 - 0
src/main/frontend/db/async.cljs

@@ -117,6 +117,7 @@
                             :or {children? true}
                             :as opts}]
   (let [name' (str id-uuid-or-name)
+        opts (assoc opts :children? children?)
         cache-key [id-uuid-or-name opts]
         cached-response (when (cache/has? @*block-cache cache-key)
                           (reset! *block-cache (cache/hit @*block-cache cache-key))