+ Не удалось получить актуальное расписание с официального сайта.
+ Показаны данные из кэша {cacheAge !== undefined && `(возраст: ${formatCacheAge(cacheAge)})`}.
+ Расписание может быть устаревшим. Попробуйте обновить страницу позже.
+
+
+
+
+
+ )
+ }
React.useEffect(() => {
if (hasScrolledRef.current || typeof window === 'undefined') return
@@ -37,8 +129,10 @@ export function Schedule({
})
if (todayDay) {
- // Небольшая задержка для завершения рендеринга
- const timeoutId = setTimeout(() => {
+ // Увеличиваем задержку, если используется кэш (баннер может рендериться позже)
+ const delay = isFromCache ? 300 : 100
+
+ const scrollToToday = () => {
const elementId = getDayOfWeek(todayDay.date)
const element = document.getElementById(elementId)
@@ -53,33 +147,88 @@ export function Schedule({
behavior: 'smooth'
})
hasScrolledRef.current = true
+ return true
}
- }, 100)
+ return false
+ }
- return () => clearTimeout(timeoutId)
+ // Используем requestAnimationFrame для более точного ожидания рендеринга
+ let timeoutId: NodeJS.Timeout | null = null
+ let retryTimeoutId: NodeJS.Timeout | null = null
+
+ const frameId = requestAnimationFrame(() => {
+ timeoutId = setTimeout(() => {
+ if (!scrollToToday() && isFromCache) {
+ // Если не удалось найти элемент и используется кэш, пробуем еще раз через небольшую задержку
+ retryTimeoutId = setTimeout(scrollToToday, 100)
+ }
+ }, delay)
+ })
+
+ return () => {
+ cancelAnimationFrame(frameId)
+ if (timeoutId) clearTimeout(timeoutId)
+ if (retryTimeoutId) clearTimeout(retryTimeoutId)
+ }
}
- }, [days])
+ }, [days, isFromCache])
+
+ // Проверка на пустое расписание
+ const isEmpty = days.length === 0 || days.every(day => day.lessons.length === 0)
return (
-