diff --git a/frontend/src/components/ScheduleBoard.tsx b/frontend/src/components/ScheduleBoard.tsx index 45bfb27..4393bad 100644 --- a/frontend/src/components/ScheduleBoard.tsx +++ b/frontend/src/components/ScheduleBoard.tsx @@ -36,10 +36,6 @@ export default function ScheduleBoard({ lang?: Lang; }) { const t = dict(lang); - const [tab, setTab] = useState(() => { - const saved = sessionStorage.getItem("tp.sched.tab"); - return saved === "group" || saved === "tournament" ? saved : "date"; - }); // 날짜 목록 (정렬) const dates = useMemo( @@ -56,8 +52,24 @@ export default function ScheduleBoard({ const set = new Set(matches.map((m) => m.roundLabel).filter(Boolean)); return KO_ROUND_ORDER.filter((r) => set.has(r)); }, [matches]); + // 현재 진행 라운드: 아직 종료되지 않은 경기가 있는 가장 이른 라운드. + // (8강 진행 중이면 8강, 8강이 다 끝나 4강 대진이 뜨면 4강.) 전부 종료면 가장 진행된 라운드. + const currentRound = useMemo(() => { + for (const r of rounds) { + if (matches.some((m) => m.roundLabel === r && !m.result)) return r; + } + return rounds[rounds.length - 1] ?? ""; + }, [matches, rounds]); - // 기본 선택: 오늘(없으면 첫 날짜) / A조 / 첫 라운드. + // 시작 탭: 토너먼트가 시작됐으면 '토너먼트', 아니면 '날짜별'. + // 단, 직전 세션 선택이 있으면 우선(상세 진입 후 뒤로가기 복원). + const [tab, setTab] = useState(() => { + const saved = sessionStorage.getItem("tp.sched.tab"); + if (saved === "date" || saved === "group" || saved === "tournament") return saved; + return rounds.length > 0 ? "tournament" : "date"; + }); + + // 기본 선택: 오늘(없으면 첫 날짜) / A조 / 현재 진행 라운드. // 단, 직전 세션 선택을 sessionStorage 에 보관 → 상세 진입 후 뒤로가기 시 그대로 복원(오늘로 초기화 X). const todayKey = useMemo(() => new Date().toISOString().slice(0, 10), []); const [selDate, setSelDate] = useState(() => { @@ -72,8 +84,8 @@ export default function ScheduleBoard({ }); const [selRound, setSelRound] = useState(() => { const saved = sessionStorage.getItem("tp.sched.round"); - if (saved && KO_ROUND_ORDER.includes(saved)) return saved; - return rounds[0] ?? ""; + if (saved && rounds.includes(saved)) return saved; + return currentRound; }); // 선택 변경 시 보관(다음 진입/뒤로가기에서 복원)