scrolling fixes
This commit is contained in:
@@ -82,22 +82,31 @@ export default function KoFixtures({ teams, matches, dict, locale }: { teams: Te
|
||||
return upcoming?.id ?? null;
|
||||
}, [koMatches]);
|
||||
|
||||
const targetRef = useRef<HTMLDivElement>(null);
|
||||
// Scroll-Ziel: aktueller Tag (heute, oder nächster Spieltag bei Ruhetag)
|
||||
const targetDateKey = useMemo(() => {
|
||||
const todayKey = localDateKey(new Date().toISOString());
|
||||
const dayKeys = groups.map(([key]) => key);
|
||||
if (dayKeys.includes(todayKey)) return todayKey;
|
||||
const future = dayKeys.find(k => k >= todayKey);
|
||||
return future ?? dayKeys[dayKeys.length - 1] ?? null;
|
||||
}, [groups]);
|
||||
|
||||
const targetDateRef = useRef<HTMLHeadingElement>(null);
|
||||
const hasScrolledRef = useRef<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!mounted || !targetRef.current) return;
|
||||
if (targetMatchId === hasScrolledRef.current) return;
|
||||
const el = targetRef.current;
|
||||
if (!mounted || !targetDateRef.current) return;
|
||||
if (targetDateKey === hasScrolledRef.current) return;
|
||||
const el = targetDateRef.current;
|
||||
const raf = requestAnimationFrame(() => {
|
||||
const rect = el.getBoundingClientRect();
|
||||
const absoluteTop = rect.top + window.scrollY;
|
||||
const offset = 180;
|
||||
window.scrollTo({ top: Math.max(0, absoluteTop - offset), behavior: "smooth" });
|
||||
});
|
||||
hasScrolledRef.current = targetMatchId;
|
||||
hasScrolledRef.current = targetDateKey;
|
||||
return () => cancelAnimationFrame(raf);
|
||||
}, [mounted, targetMatchId, koMatches.length]);
|
||||
}, [mounted, targetDateKey, koMatches.length]);
|
||||
|
||||
const [showScrollTop, setShowScrollTop] = useState(false);
|
||||
useEffect(() => {
|
||||
@@ -116,7 +125,7 @@ export default function KoFixtures({ teams, matches, dict, locale }: { teams: Te
|
||||
<div>
|
||||
{groups.map(([date, groupMatches]) => (
|
||||
<div key={date} style={{ marginBottom: 24 }}>
|
||||
<h3 style={{
|
||||
<h3 ref={date === targetDateKey ? targetDateRef : undefined} style={{
|
||||
fontFamily: "var(--font-display)", fontSize: 13,
|
||||
textTransform: "uppercase", letterSpacing: "0.06em",
|
||||
color: "var(--ink-dim)", margin: "0 0 10px",
|
||||
@@ -140,7 +149,6 @@ export default function KoFixtures({ teams, matches, dict, locale }: { teams: Te
|
||||
return (
|
||||
<div
|
||||
key={m.id}
|
||||
ref={isTarget ? targetRef : undefined}
|
||||
style={{
|
||||
background: "var(--bg-card)",
|
||||
border: `${isTarget ? 2 : 1}px solid ${live ? "var(--turf)" : isTarget ? "var(--turf)" : "var(--line-soft)"}`,
|
||||
|
||||
@@ -60,6 +60,11 @@ export default function Home({ params }: { params: Promise<{ locale: string }> }
|
||||
setTab("groupfixtures");
|
||||
}, []);
|
||||
|
||||
// Tab-Wechsel: nach ganz oben scrollen
|
||||
useEffect(() => {
|
||||
window.scrollTo({ top: 0, behavior: "auto" });
|
||||
}, [tab]);
|
||||
|
||||
const anyLive = data?.matches.some(
|
||||
(m) => m.status === "LIVE" || m.status === "IN_PLAY" || m.status === "PAUSED",
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user