fix: disable lazy loading for query blocks temporally

pull/5292/head
Tienson Qin 2022-05-13 10:50:47 +08:00
parent 4d4ade5c96
commit fb8cd67917
4 changed files with 25 additions and 18 deletions

View File

@ -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]

View File

@ -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]

View File

@ -172,7 +172,8 @@
(ui/lazy-visible
(fn []
(references* page-name))
nil)))
nil
false)))
(rum/defcs unlinked-references-aux
< rum/reactive db-mixins/query

View File

@ -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?))))