fix(lesson): scroll к вопросу вместо прыжка вверх
- LessonViewPage: scrollIntoView → window.scrollTo с расчётом позиции - App.tsx: skip глобального скролла на /lessons/* (GLOBAL_SCROLL_BREAKS_LESSON_NAV) - translations: 16 ключей lesson* × 4 языка (уже в предыдущем коммите)
This commit is contained in:
+6
-1
@@ -212,7 +212,12 @@ function AppContent() {
|
|||||||
// Оставляем глобальный сброс только при реальной смене route.
|
// Оставляем глобальный сброс только при реальной смене route.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Пропускаем, если мы на странице урока — там свой scrollIntoView.
|
// Пропускаем, если мы на странице урока — там свой scrollIntoView.
|
||||||
if (location.pathname.includes('/lessons/')) return;
|
// 🔧 ДИАГНОСТИКА (04.10.2026): логирование на 1 минуту для проверки.
|
||||||
|
if (location.pathname.includes('/lessons/')) {
|
||||||
|
console.log('[App] skip scroll for lesson route');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log('[App] scrolling to top for', location.pathname);
|
||||||
|
|
||||||
window.scrollTo(0, 0);
|
window.scrollTo(0, 0);
|
||||||
document.documentElement.scrollTop = 0;
|
document.documentElement.scrollTop = 0;
|
||||||
|
|||||||
@@ -134,18 +134,30 @@ const LessonViewPage: React.FC = () => {
|
|||||||
}
|
}
|
||||||
}, [lessonId, topicId]);
|
}, [lessonId, topicId]);
|
||||||
|
|
||||||
// 🔧 НОВОЕ (04.10.2026): при смене вопроса скроллим к блоку вопроса,
|
// 🔧 ФИКС (04.10.2026): SCROLL_TO_QUESTION_VIA_WINDOW —
|
||||||
// а не в начало страницы.
|
// scrollIntoView не работал при overflow:hidden на корне,
|
||||||
|
// потому что скроллил внутренний контейнер, а не window.
|
||||||
|
// Считаем позицию блока вручную и скроллим window.
|
||||||
|
// Задержка 100мс — ждём, пока браузер пересчитает layout после
|
||||||
|
// исчезновения explanation (страница становится короче).
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (questionBlockRef.current && !showIntermediate) {
|
if (showIntermediate || !questionBlockRef.current) return;
|
||||||
// requestAnimationFrame — даём React отрендерить новый контент
|
|
||||||
requestAnimationFrame(() => {
|
const timer = setTimeout(() => {
|
||||||
questionBlockRef.current?.scrollIntoView({
|
const el = questionBlockRef.current;
|
||||||
behavior: 'smooth',
|
if (!el) return;
|
||||||
block: 'center',
|
|
||||||
});
|
const rect = el.getBoundingClientRect();
|
||||||
|
const absoluteTop = window.scrollY + rect.top;
|
||||||
|
|
||||||
|
// Отступ 80px сверху — чтобы вопрос был виден, но не прилипал к краю
|
||||||
|
window.scrollTo({
|
||||||
|
top: Math.max(0, absoluteTop - 80),
|
||||||
|
behavior: 'smooth',
|
||||||
});
|
});
|
||||||
}
|
}, 100);
|
||||||
|
|
||||||
|
return () => clearTimeout(timer);
|
||||||
}, [currentQuestionIndex, retryMode, showIntermediate]);
|
}, [currentQuestionIndex, retryMode, showIntermediate]);
|
||||||
|
|
||||||
const saveAnswer = async (
|
const saveAnswer = async (
|
||||||
@@ -541,7 +553,11 @@ const LessonViewPage: React.FC = () => {
|
|||||||
minHeight: '100vh', background: bgColor, color: textColor,
|
minHeight: '100vh', background: bgColor, color: textColor,
|
||||||
fontFamily: fonts.main, padding: '24px',
|
fontFamily: fonts.main, padding: '24px',
|
||||||
display: 'flex', flexDirection: 'column',
|
display: 'flex', flexDirection: 'column',
|
||||||
position: 'relative', overflow: 'hidden',
|
position: 'relative',
|
||||||
|
// 🔧 ФИКС (04.10.2026): LESSON_OVERFLOW_HIDDEN_BREAKS_SCROLL —
|
||||||
|
// overflow:hidden на корне заставлял браузер сбрасывать скролл
|
||||||
|
// родителя к 0 при ре-рендере (когда explanation исчезал).
|
||||||
|
// Убрали — теперь scrollIntoView работает.
|
||||||
}}>
|
}}>
|
||||||
<div style={{ position: 'fixed', top: '-80px', right: '-60px', width: '260px', height: '260px', borderRadius: '50%', background: brandColor, opacity: 0.18, filter: 'blur(90px)', pointerEvents: 'none', zIndex: 0 }} />
|
<div style={{ position: 'fixed', top: '-80px', right: '-60px', width: '260px', height: '260px', borderRadius: '50%', background: brandColor, opacity: 0.18, filter: 'blur(90px)', pointerEvents: 'none', zIndex: 0 }} />
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user