Further utilize lazy shazam
This commit is contained in:
parent
30382d088b
commit
2ad9706304
|
@ -30,8 +30,12 @@ export default function LazyShazam({ children }) {
|
||||||
if (!containerRef.current) return;
|
if (!containerRef.current) return;
|
||||||
const rect = containerRef.current.getBoundingClientRect();
|
const rect = containerRef.current.getBoundingClientRect();
|
||||||
if (rect.bottom > TOP) {
|
if (rect.bottom > TOP) {
|
||||||
|
if (rect.top < window.innerHeight) {
|
||||||
|
setVisible(true);
|
||||||
|
} else {
|
||||||
setVisibleStart(true);
|
setVisibleStart(true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
if (visibleStart) return children;
|
if (visibleStart) return children;
|
||||||
|
|
|
@ -10,6 +10,7 @@ import localeCode2Text from '../utils/localeCode2Text';
|
||||||
import pmem from '../utils/pmem';
|
import pmem from '../utils/pmem';
|
||||||
|
|
||||||
import Icon from './icon';
|
import Icon from './icon';
|
||||||
|
import LazyShazam from './lazy-shazam';
|
||||||
import Loader from './loader';
|
import Loader from './loader';
|
||||||
|
|
||||||
const { PHANPY_LINGVA_INSTANCES } = import.meta.env;
|
const { PHANPY_LINGVA_INSTANCES } = import.meta.env;
|
||||||
|
@ -142,8 +143,7 @@ function TranslationBlock({
|
||||||
detectedLang !== targetLangText
|
detectedLang !== targetLangText
|
||||||
) {
|
) {
|
||||||
return (
|
return (
|
||||||
<div class="shazam-container">
|
<LazyShazam>
|
||||||
<div class="shazam-container-inner">
|
|
||||||
<div class="status-translation-block-mini">
|
<div class="status-translation-block-mini">
|
||||||
<Icon
|
<Icon
|
||||||
icon="translate"
|
icon="translate"
|
||||||
|
@ -157,8 +157,7 @@ function TranslationBlock({
|
||||||
{translatedContent}
|
{translatedContent}
|
||||||
</output>
|
</output>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</LazyShazam>
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in a new issue