This commit is contained in:
eric
2026-03-07 21:11:28 -06:00
parent cc1c93a9db
commit 613b3a2f6e

View File

@@ -16,9 +16,10 @@ function getPb() {
const LazyChunk = React.memo(({ html, estimatedHeight, forceVisible }) => { const LazyChunk = React.memo(({ html, estimatedHeight, forceVisible }) => {
const [visible, setVisible] = useState(forceVisible); const [visible, setVisible] = useState(forceVisible);
const ref = useRef(null); const ref = useRef(null);
const show = forceVisible || visible;
useEffect(() => { useEffect(() => {
if (forceVisible) { setVisible(true); return; } if (forceVisible) return;
if (visible) return; if (visible) return;
const el = ref.current; const el = ref.current;
if (!el) return; if (!el) return;
@@ -35,7 +36,7 @@ const LazyChunk = React.memo(({ html, estimatedHeight, forceVisible }) => {
return () => observer.disconnect(); return () => observer.disconnect();
}, [forceVisible, visible]); }, [forceVisible, visible]);
if (visible) { if (show) {
return <div className="chunk-enter" dangerouslySetInnerHTML={{ __html: html }} />; return <div className="chunk-enter" dangerouslySetInnerHTML={{ __html: html }} />;
} }
return <div ref={ref} className="chunk-placeholder" style={{ minHeight: estimatedHeight }} />; return <div ref={ref} className="chunk-placeholder" style={{ minHeight: estimatedHeight }} />;
@@ -195,18 +196,29 @@ const Book = () => {
}; };
}, [contentLoading]); }, [contentLoading]);
const handleJump = useCallback((text) => { const handleJump = useCallback((index) => {
setForceShowAll(true); setForceShowAll(true);
setTimeout(() => { setshow(false);
if (!contentRef.current) return;
const h1s = contentRef.current.querySelectorAll("h1"); const run = () => {
for (let h1 of h1s) { const root = contentRef.current;
if (h1.textContent.trim() === text.trim()) { if (!root) return;
h1.scrollIntoView({ behavior: "smooth" }); const h1s = root.querySelectorAll("h1");
break; const el = h1s[index];
if (el) {
try {
el.scrollIntoView({ behavior: "smooth", block: "start" });
} catch (_) {
const top = el.getBoundingClientRect().top + (window.pageYOffset || document.documentElement.scrollTop) - 60;
window.scrollTo({ top: Math.max(0, top), behavior: "smooth" });
} }
} }
}, 200); };
run();
setTimeout(run, 100);
setTimeout(run, 300);
setTimeout(run, 600);
}, []); }, []);
const submitPayForm = (xorpayUrl, xorpayParams) => { const submitPayForm = (xorpayUrl, xorpayParams) => {
@@ -284,7 +296,7 @@ const Book = () => {
show={show} show={show}
mask mask
items={activeHeaders} items={activeHeaders}
onItemClick={(index) => handleJump(activeHeaders[index])} onItemClick={(index) => handleJump(index)}
onClose={() => setshow(false)} onClose={() => setshow(false)}
/> />