mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-03-21 21:29:20 +01:00
Test this lazy shazam
This commit is contained in:
parent
438b520970
commit
67a05450cf
2 changed files with 63 additions and 14 deletions
46
src/components/lazy-shazam.jsx
Normal file
46
src/components/lazy-shazam.jsx
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
/*
|
||||||
|
Rendered but hidden. Only show when visible
|
||||||
|
*/
|
||||||
|
import { useLayoutEffect, useRef, useState } from 'preact/hooks';
|
||||||
|
import { useInView } from 'react-intersection-observer';
|
||||||
|
|
||||||
|
export default function LazyShazam({ children }) {
|
||||||
|
const containerRef = useRef();
|
||||||
|
const [visible, setVisible] = useState(false);
|
||||||
|
const [visibleStart, setVisibleStart] = useState(false);
|
||||||
|
|
||||||
|
const { ref } = useInView({
|
||||||
|
root: null,
|
||||||
|
trackVisibility: true,
|
||||||
|
delay: 1000,
|
||||||
|
onChange: (inView) => {
|
||||||
|
if (inView) {
|
||||||
|
setVisible(true);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
triggerOnce: true,
|
||||||
|
skip: visibleStart || visible,
|
||||||
|
});
|
||||||
|
|
||||||
|
useLayoutEffect(() => {
|
||||||
|
if (!containerRef.current) return;
|
||||||
|
const rect = containerRef.current.getBoundingClientRect();
|
||||||
|
if (rect.bottom > 0) {
|
||||||
|
setVisibleStart(true);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
if (visibleStart) return children;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
ref={containerRef}
|
||||||
|
class="shazam-container no-animation"
|
||||||
|
hidden={!visible}
|
||||||
|
>
|
||||||
|
<div ref={ref} class="shazam-container-inner">
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
|
@ -26,6 +26,7 @@ import { useSnapshot } from 'valtio';
|
||||||
|
|
||||||
import CustomEmoji from '../components/custom-emoji';
|
import CustomEmoji from '../components/custom-emoji';
|
||||||
import EmojiText from '../components/emoji-text';
|
import EmojiText from '../components/emoji-text';
|
||||||
|
import LazyShazam from '../components/lazy-shazam';
|
||||||
import Loader from '../components/loader';
|
import Loader from '../components/loader';
|
||||||
import Menu2 from '../components/menu2';
|
import Menu2 from '../components/menu2';
|
||||||
import MenuConfirm from '../components/menu-confirm';
|
import MenuConfirm from '../components/menu-confirm';
|
||||||
|
@ -3128,6 +3129,7 @@ const QuoteStatuses = memo(({ id, instance, level = 0 }) => {
|
||||||
|
|
||||||
return uniqueQuotes.map((q) => {
|
return uniqueQuotes.map((q) => {
|
||||||
return (
|
return (
|
||||||
|
<LazyShazam>
|
||||||
<Link
|
<Link
|
||||||
key={q.instance + q.id}
|
key={q.instance + q.id}
|
||||||
to={`${q.instance ? `/${q.instance}` : ''}/s/${q.id}`}
|
to={`${q.instance ? `/${q.instance}` : ''}/s/${q.id}`}
|
||||||
|
@ -3142,6 +3144,7 @@ const QuoteStatuses = memo(({ id, instance, level = 0 }) => {
|
||||||
enableCommentHint
|
enableCommentHint
|
||||||
/>
|
/>
|
||||||
</Link>
|
</Link>
|
||||||
|
</LazyShazam>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue