From fb8cd6791733ddb2b82f38ae05c182f568ac6cc4 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Fri, 13 May 2022 10:50:47 +0800 Subject: [PATCH] fix: disable lazy loading for query blocks temporally --- src/main/frontend/components/block.cljs | 8 +++--- src/main/frontend/components/journal.cljs | 2 +- src/main/frontend/components/reference.cljs | 3 ++- src/main/frontend/ui.cljs | 30 ++++++++++++--------- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/main/frontend/components/block.cljs b/src/main/frontend/components/block.cljs index 6dac4212ed..feb0484807 100644 --- a/src/main/frontend/components/block.cljs +++ b/src/main/frontend/components/block.cljs @@ -2404,11 +2404,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-query-child? config))) + (if (and ref? (not custom-query?) (not (:ref-query-child? config))) (ui/lazy-visible (fn [] (block-container-inner state repo config block)) - nil) + nil + false) (block-container-inner state repo config block)))) (defn divide-lists @@ -2737,7 +2738,8 @@ (ui/block-error "Query Error:" {:content (:query q)}) (ui/lazy-visible (fn [] (custom-query* config q)) - nil))) + nil + true))) (defn admonition [config type result] diff --git a/src/main/frontend/components/journal.cljs b/src/main/frontend/components/journal.cljs index 4727bbcb30..40aea4e72c 100644 --- a/src/main/frontend/components/journal.cljs +++ b/src/main/frontend/components/journal.cljs @@ -65,7 +65,7 @@ (rum/defc journal-cp [journal] - (ui/lazy-visible (fn [] (journal-cp-inner journal)) nil)) + (ui/lazy-visible (fn [] (journal-cp-inner journal)) nil true)) (rum/defc journals < rum/reactive [latest-journals] diff --git a/src/main/frontend/components/reference.cljs b/src/main/frontend/components/reference.cljs index a053cdd776..cb6dfd1e1d 100644 --- a/src/main/frontend/components/reference.cljs +++ b/src/main/frontend/components/reference.cljs @@ -172,7 +172,8 @@ (ui/lazy-visible (fn [] (references* page-name)) - nil))) + nil + false))) (rum/defcs unlinked-references-aux < rum/reactive db-mixins/query diff --git a/src/main/frontend/ui.cljs b/src/main/frontend/ui.cljs index 1e6e41ffc0..ebaa8b77df 100644 --- a/src/main/frontend/ui.cljs +++ b/src/main/frontend/ui.cljs @@ -915,23 +915,25 @@ {:init (fn [state] (assoc state ::ref (atom nil) - ::height (atom 100))) + ::height (atom 26))) :did-mount (fn [state] - (let [observer (js/ResizeObserver. (fn [entries] - (let [entry (first entries) - *height (::height state) - height' (.-height (.-contentRect entry))] - (when (> height' @*height) - (reset! *height height')))))] - (.observe observer @(::ref state))) + (when (last (:rum/args state)) + (let [observer (js/ResizeObserver. (fn [entries] + (let [entry (first entries) + *height (::height state) + height' (.-height (.-contentRect entry))] + (when (and (> height' @*height) + (not= height' 64)) + (reset! *height height')))))] + (.observe observer @(::ref state)))) state)} - [state visible? content-fn] + [state visible? content-fn reset-height?] [:div.lazy-visibility {:ref #(reset! (::ref state) %) :style {:min-height @(::height state)}} (if visible? (when (fn? content-fn) (content-fn)) - [:div.shadow.rounded-md.p-4.w-full.mx-auto + [:div.shadow.rounded-md.p-4.w-full.mx-auto {:style {:height 64}} [:div.animate-pulse.flex.space-x-4 [:div.flex-1.space-y-3.py-1 [:div.h-2.bg-base-4.rounded] @@ -943,13 +945,15 @@ (rum/defcs lazy-visible < (rum/local false ::visible?) - [state content-fn sensor-opts] + [state content-fn sensor-opts reset-height?] (let [*visible? (::visible? state)] (visibility-sensor (merge {:on-change #(reset! *visible? %) :partialVisibility true :offset {:top -300 - :bottom -300}} + :bottom -300} + :scrollCheck true + :scrollThrottle 1} sensor-opts) - (lazy-visible-inner @*visible? content-fn)))) + (lazy-visible-inner @*visible? content-fn reset-height?))))