Просмотр исходного кода

Lazy loading journals and queries

Tienson Qin 3 лет назад
Родитель
Сommit
8c2e07275b

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

@@ -1403,6 +1403,7 @@
 (rum/defc block-children < rum/reactive
   [config children collapsed?]
   (let [ref? (:ref? config)
+        query? (:custom-query? config)
         children (and (coll? children) (filter map? children))]
     (when (and (coll? children)
                (seq children)
@@ -1418,8 +1419,8 @@
                             (-> config
                                 (assoc :block/uuid (:block/uuid child))
                                 (dissoc :breadcrumb-show? :embed-parent))
-                             ref?
-                             (assoc :ref-child? true))]
+                             (or ref? query?)
+                             (assoc :ref-query-child? true))]
                 (rum/with-key (block-container config child)
                   (:block/uuid child)))))]]))))
 
@@ -2081,7 +2082,8 @@
     (when show?
       (let [page-name-props (when show-page?
                               [page
-                               (or page-original-name page-name)])
+                               (page-cp config page)
+                               {:block/name (or page-original-name page-name)}])
             parents-props (doall
                            (for [{:block/keys [uuid name content] :as block} parents]
                              (when-not name ; not page
@@ -2333,7 +2335,6 @@
      (dnd-separator-wrapper block block-id slide? false false)]))
 
 (rum/defcs ^:large-vars/cleanup-todo block-container < rum/reactive
-  (rum/local false ::visible?)
   {:init (fn [state]
            (let [[config block] (:rum/args state)
                  block-id (:block/uuid block)]
@@ -2367,14 +2368,12 @@
         ref? (:ref? config)
         custom-query? (boolean (:custom-query? config))
         ref-or-custom-query? (or ref? custom-query?)]
-    (if (and ref-or-custom-query? (not (:ref-child? config)))
-      (let [*visible? (::visible? state)]
-        (ui/lazy-visible
-         *visible?
-        nil
-        (fn []
-          (block-container-inner state repo config block))
-        nil))
+    (if (and ref-or-custom-query? (not (:ref-query-child? config)))
+      (ui/lazy-visible
+       nil
+       (fn []
+         (block-container-inner state repo config block))
+       nil)
       (block-container-inner state repo config block))))
 
 (defn divide-lists
@@ -2701,7 +2700,10 @@
   [config q]
   (ui/catch-error
    (ui/block-error "Query Error:" {:content (:query q)})
-   (custom-query* config q)))
+   (ui/lazy-visible
+    "loading ..."
+    (fn [] (custom-query* config q))
+    nil)))
 
 (defn admonition
   [config type result]

+ 5 - 1
src/main/frontend/components/journal.cljs

@@ -21,7 +21,7 @@
   (when-let [page-e (db/pull [:block/name (util/page-name-sanity-lc page)])]
     (page/page-blocks-cp repo page-e {})))
 
-(rum/defc journal-cp < rum/reactive
+(rum/defc journal-cp-inner < rum/reactive
   [[title format]]
   (let [;; Don't edit the journal title
         page (string/lower-case title)
@@ -63,6 +63,10 @@
        (reference/references title false)
        (str title "-refs"))]))
 
+(rum/defc journal-cp
+  [journal]
+  (ui/lazy-visible nil (fn [] (journal-cp-inner journal)) nil))
+
 (rum/defc journals < rum/reactive
   [latest-journals]
   [:div#journals

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

@@ -165,14 +165,14 @@
              {:default-collapsed? default-collapsed?
               :title-trigger? true}))]]))))
 
-(rum/defcs references <
-  (rum/local false ::visible?)
-  [state page-name sidebar?]
+(rum/defc references
+  [page-name sidebar?]
   (ui/catch-error
    (ui/component-error "Linked References: Unexpected error")
    (ui/lazy-visible
-    (::visible? state)
-    (if sidebar? nil "loading references...")
+    (if (or sidebar? (gp-util/uuid-string? page-name))
+      nil
+      "loading references...")
     (fn []
       (references* page-name))
     nil)))

+ 5 - 4
src/main/frontend/handler/editor.cljs

@@ -453,11 +453,12 @@
 (declare save-current-block!)
 (defn outliner-insert-block!
   [config current-block new-block {:keys [sibling? keep-uuid? replace-empty-target?]}]
-  (let [ref-top-block? (and (:ref? config)
-                            (not (:ref-child? config)))
+  (let [ref-query-top-block? (and (:ref? config)
+                            (:custom-query? config)
+                            (not (:ref-or-query? config)))
         has-children? (db/has-children? (:block/uuid current-block))
         sibling? (cond
-                   ref-top-block?
+                   ref-query-top-block?
                    false
 
                    (boolean? sibling?)
@@ -3477,7 +3478,7 @@
   [block config]
   (or
    (and
-    (:ref? config)
+    (or (:ref? config) (:custom-query? config))
     (>= (inc (:block/level block))
         (state/get-ref-open-blocks-level))
     ;; has children

+ 8 - 6
src/main/frontend/ui.cljs

@@ -684,7 +684,7 @@
                         :margin-left -30}}
              (not title-trigger?)
              (assoc :on-mouse-down on-mouse-down))
-           [:span {:class (if @control? "control-show cursor-pointer" "control-hide")}
+           [:span {:class (if (or @control? @collapsed?) "control-show cursor-pointer" "control-hide")}
             (rotating-arrow @collapsed?)]])
         (if (fn? header)
           (header @collapsed?)
@@ -916,11 +916,13 @@
   [:div.lazy-visibility
    (if visible?
      (when (fn? content-fn) (content-fn))
-     (when loading-label (loading loading-label)))])
+     (when loading-label [:span.text-sm.font-medium
+                          loading-label]))])
 
-(rum/defc lazy-visible < rum/reactive
-  [*visible? loading-label content-fn sensor-opts]
-  (let [visible? (rum/react *visible?)]
+(rum/defcs lazy-visible <
+  (rum/local false ::visible?)
+  [state loading-label content-fn sensor-opts]
+  (let [*visible? (::visible? state)]
     (visibility-sensor
      (merge
       {:on-change #(reset! *visible? %)
@@ -928,4 +930,4 @@
        :offset {:top -300
                 :bottom -300}}
       sensor-opts)
-     (lazy-visible-inner visible? content-fn loading-label))))
+     (lazy-visible-inner @*visible? content-fn loading-label))))