mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-01-23 00:56:23 +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 EmojiText from '../components/emoji-text';
|
||||
import LazyShazam from '../components/lazy-shazam';
|
||||
import Loader from '../components/loader';
|
||||
import Menu2 from '../components/menu2';
|
||||
import MenuConfirm from '../components/menu-confirm';
|
||||
|
@ -3128,20 +3129,22 @@ const QuoteStatuses = memo(({ id, instance, level = 0 }) => {
|
|||
|
||||
return uniqueQuotes.map((q) => {
|
||||
return (
|
||||
<Link
|
||||
key={q.instance + q.id}
|
||||
to={`${q.instance ? `/${q.instance}` : ''}/s/${q.id}`}
|
||||
class="status-card-link"
|
||||
data-read-more="Read more →"
|
||||
>
|
||||
<Status
|
||||
statusID={q.id}
|
||||
instance={q.instance}
|
||||
size="s"
|
||||
quoted={level + 1}
|
||||
enableCommentHint
|
||||
/>
|
||||
</Link>
|
||||
<LazyShazam>
|
||||
<Link
|
||||
key={q.instance + q.id}
|
||||
to={`${q.instance ? `/${q.instance}` : ''}/s/${q.id}`}
|
||||
class="status-card-link"
|
||||
data-read-more="Read more →"
|
||||
>
|
||||
<Status
|
||||
statusID={q.id}
|
||||
instance={q.instance}
|
||||
size="s"
|
||||
quoted={level + 1}
|
||||
enableCommentHint
|
||||
/>
|
||||
</Link>
|
||||
</LazyShazam>
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue