토너먼트 대진 추가
This commit is contained in:
1 parent
59db1c4e9a
commit
6815540ae6
6 files changed
+161
-50
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import type { Match } from "@/lib/types";
|
||||
import { kickoffDisplay } from "@/lib/format";
|
||||
import { type Lang, dict, teamShort } from "@/lib/i18n";
|
||||
import { type Lang, dict, teamShort, roundLabel as tRound } from "@/lib/i18n";
|
||||
import BallIcon from "./BallIcon";
|
||||
import TeamFlag from "./TeamFlag";
|
||||
import WaveStrip from "./WaveStrip";
|
||||
@@ -37,7 +37,8 @@ export default function MatchupHUD({ match, lang = "ko" }: { match: Match; lang?
|
||||
{teamShort(right, lang)}
|
||||
</div>
|
||||
<div className="mt-1 text-[15px] font-bold text-[var(--green)]">
|
||||
{kickoffDisplay(match.kickoffKst, lang)} · {t.group(group)}
|
||||
{kickoffDisplay(match.kickoffKst, lang)} ·{" "}
|
||||
{group ? t.group(group) : tRound(match.roundLabel, lang)}
|
||||
</div>
|
||||
<div className="mt-0.5 text-[12px] text-white/65">{match.venue}</div>
|
||||
</div>
|
||||
|
||||
@@ -22,7 +22,11 @@ const PHASE_CLS: Record<MatchPhase, string> = {
|
||||
finished: "border-white/15 text-white/55",
|
||||
};
|
||||
|
||||
type Tab = "date" | "group";
|
||||
// 토너먼트 탭 라운드 칩 정렬(대진 순서)
|
||||
const KO_ROUND_ORDER = ["32강", "16강", "8강", "4강", "3·4위전", "결승"];
|
||||
const isGroupLetter = (s: string) => /^[A-Z]$/.test(s);
|
||||
|
||||
type Tab = "date" | "group" | "tournament";
|
||||
|
||||
export default function ScheduleBoard({
|
||||
matches,
|
||||
@@ -32,21 +36,28 @@ export default function ScheduleBoard({
|
||||
lang?: Lang;
|
||||
}) {
|
||||
const t = dict(lang);
|
||||
const [tab, setTab] = useState<Tab>(() =>
|
||||
sessionStorage.getItem("tp.sched.tab") === "group" ? "group" : "date",
|
||||
);
|
||||
const [tab, setTab] = useState<Tab>(() => {
|
||||
const saved = sessionStorage.getItem("tp.sched.tab");
|
||||
return saved === "group" || saved === "tournament" ? saved : "date";
|
||||
});
|
||||
|
||||
// 날짜·조 목록 (정렬)
|
||||
// 날짜 목록 (정렬)
|
||||
const dates = useMemo(
|
||||
() => Array.from(new Set(matches.map((m) => dateKey(m.kickoffKst)))).sort(),
|
||||
[matches],
|
||||
);
|
||||
const groups = useMemo(
|
||||
() => Array.from(new Set(matches.map((m) => m.group))).sort(),
|
||||
[matches],
|
||||
);
|
||||
// 조별리그 탭 칩: 조 문자(A~L)
|
||||
const groups = useMemo(() => {
|
||||
const set = new Set(matches.map((m) => m.group).filter(Boolean));
|
||||
return [...set].filter(isGroupLetter).sort();
|
||||
}, [matches]);
|
||||
// 토너먼트 탭 칩: 등장한 라운드(32강~결승), 대진 순서
|
||||
const rounds = useMemo(() => {
|
||||
const set = new Set(matches.map((m) => m.roundLabel).filter(Boolean));
|
||||
return KO_ROUND_ORDER.filter((r) => set.has(r));
|
||||
}, [matches]);
|
||||
|
||||
// 기본 선택: 오늘(없으면 첫 날짜) / A조.
|
||||
// 기본 선택: 오늘(없으면 첫 날짜) / A조 / 첫 라운드.
|
||||
// 단, 직전 세션 선택을 sessionStorage 에 보관 → 상세 진입 후 뒤로가기 시 그대로 복원(오늘로 초기화 X).
|
||||
const todayKey = useMemo(() => new Date().toISOString().slice(0, 10), []);
|
||||
const [selDate, setSelDate] = useState(() => {
|
||||
@@ -56,9 +67,14 @@ export default function ScheduleBoard({
|
||||
});
|
||||
const [selGroup, setSelGroup] = useState(() => {
|
||||
const saved = sessionStorage.getItem("tp.sched.group");
|
||||
if (saved && groups.includes(saved)) return saved;
|
||||
if (saved && isGroupLetter(saved)) return saved;
|
||||
return (groups.includes("A") ? "A" : groups[0]) ?? "";
|
||||
});
|
||||
const [selRound, setSelRound] = useState(() => {
|
||||
const saved = sessionStorage.getItem("tp.sched.round");
|
||||
if (saved && KO_ROUND_ORDER.includes(saved)) return saved;
|
||||
return rounds[0] ?? "";
|
||||
});
|
||||
|
||||
// 선택 변경 시 보관(다음 진입/뒤로가기에서 복원)
|
||||
useEffect(() => {
|
||||
@@ -67,22 +83,35 @@ export default function ScheduleBoard({
|
||||
useEffect(() => {
|
||||
if (selGroup) sessionStorage.setItem("tp.sched.group", selGroup);
|
||||
}, [selGroup]);
|
||||
useEffect(() => {
|
||||
if (selRound) sessionStorage.setItem("tp.sched.round", selRound);
|
||||
}, [selRound]);
|
||||
useEffect(() => {
|
||||
sessionStorage.setItem("tp.sched.tab", tab);
|
||||
}, [tab]);
|
||||
|
||||
const shown = useMemo(() => {
|
||||
const list =
|
||||
tab === "date"
|
||||
? matches.filter((m) => dateKey(m.kickoffKst) === selDate)
|
||||
: matches.filter((m) => m.group === selGroup);
|
||||
let list: Match[];
|
||||
if (tab === "date") list = matches.filter((m) => dateKey(m.kickoffKst) === selDate);
|
||||
else if (tab === "group") list = matches.filter((m) => !!m.group && m.group === selGroup);
|
||||
else list = matches.filter((m) => m.roundLabel === selRound); // 토너먼트
|
||||
return [...list].sort(
|
||||
(a, b) => new Date(a.kickoffKst).getTime() - new Date(b.kickoffKst).getTime(),
|
||||
);
|
||||
}, [matches, tab, selDate, selGroup]);
|
||||
}, [matches, tab, selDate, selGroup, selRound]);
|
||||
|
||||
const tabLabel = (k: Tab) =>
|
||||
k === "date" ? (lang === "en" ? "By date" : "날짜별") : lang === "en" ? "Groups" : "조별리그";
|
||||
k === "date"
|
||||
? lang === "en"
|
||||
? "By date"
|
||||
: "날짜별"
|
||||
: k === "group"
|
||||
? lang === "en"
|
||||
? "Groups"
|
||||
: "조별리그"
|
||||
: lang === "en"
|
||||
? "Tournament"
|
||||
: "토너먼트";
|
||||
|
||||
return (
|
||||
<section className="mt-6">
|
||||
@@ -91,9 +120,9 @@ export default function ScheduleBoard({
|
||||
<span className="whitespace-nowrap text-[12px] text-white/55">{t.schedGuide}</span>
|
||||
</div>
|
||||
|
||||
{/* 탭: 날짜별 / 조별리그 */}
|
||||
{/* 탭: 날짜별 / 조별리그 / 토너먼트 */}
|
||||
<div className="mb-3 flex gap-5 border-b border-[var(--line-d)]">
|
||||
{(["date", "group"] as Tab[]).map((k) => (
|
||||
{(["date", "group", "tournament"] as Tab[]).map((k) => (
|
||||
<button
|
||||
key={k}
|
||||
onClick={() => setTab(k)}
|
||||
@@ -108,7 +137,7 @@ export default function ScheduleBoard({
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* 칩: 날짜 또는 조 — 단일 줄 가로 스크롤 + 양 끝 화살표(PC에서 마우스로 넘김, 끝 도달 시 숨김) */}
|
||||
{/* 칩: 날짜 / 조 / 라운드 — 단일 줄 가로 스크롤 + 양 끝 화살표(PC에서 마우스로 넘김, 끝 도달 시 숨김) */}
|
||||
<ChipScroller resetKey={tab}>
|
||||
{tab === "date"
|
||||
? dates.map((d) => (
|
||||
@@ -116,18 +145,30 @@ export default function ScheduleBoard({
|
||||
{shortDate(d, lang)}
|
||||
</Chip>
|
||||
))
|
||||
: groups.map((g) => (
|
||||
<Chip key={g} active={g === selGroup} onClick={() => setSelGroup(g)}>
|
||||
{lang === "en" ? `Group ${g}` : `${g}조`}
|
||||
</Chip>
|
||||
))}
|
||||
: tab === "group"
|
||||
? groups.map((g) => (
|
||||
<Chip key={g} active={g === selGroup} onClick={() => setSelGroup(g)}>
|
||||
{lang === "en" ? `Group ${g}` : `${g}조`}
|
||||
</Chip>
|
||||
))
|
||||
: rounds.map((r) => (
|
||||
<Chip key={r} active={r === selRound} onClick={() => setSelRound(r)}>
|
||||
{tRound(r, lang)}
|
||||
</Chip>
|
||||
))}
|
||||
</ChipScroller>
|
||||
|
||||
{/* 경기 카드 */}
|
||||
<div className="flex flex-col gap-2.5">
|
||||
{shown.length === 0 && (
|
||||
<p className="py-6 text-center text-[13px] text-white/45">
|
||||
{lang === "en" ? "No matches" : "경기가 없습니다"}
|
||||
{tab === "tournament"
|
||||
? lang === "en"
|
||||
? "Bracket is set after the group stage."
|
||||
: "토너먼트 대진은 조별리그 종료 후 확정됩니다"
|
||||
: lang === "en"
|
||||
? "No matches"
|
||||
: "경기가 없습니다"}
|
||||
</p>
|
||||
)}
|
||||
{shown.map((m) => (
|
||||
@@ -265,11 +306,16 @@ function MatchCard({ match, lang }: { match: Match; lang: Lang }) {
|
||||
<div className="flex items-center justify-between text-[11px]">
|
||||
<span className="font-mono font-bold text-white/70">
|
||||
{timeOnly(match.kickoffKst)} <span className="text-white/40">KST</span>
|
||||
{match.roundLabel ? <> · {tRound(match.roundLabel, lang)}</> : null}
|
||||
{/* 조별리그 seed 의 부가 라벨(예: 개막전)만 여기에. 녹아웃 라운드는 우측에 표시. */}
|
||||
{match.group && match.roundLabel ? <> · {tRound(match.roundLabel, lang)}</> : null}
|
||||
</span>
|
||||
<span className="flex items-center gap-1.5">
|
||||
<span className="text-[11px] font-bold text-white/45">
|
||||
{lang === "en" ? `Group ${match.group}` : `${match.group}조`}
|
||||
{match.group
|
||||
? lang === "en"
|
||||
? `Group ${match.group}`
|
||||
: `${match.group}조`
|
||||
: tRound(match.roundLabel, lang)}
|
||||
</span>
|
||||
<span className={`rounded-md border px-2 py-0.5 font-semibold ${PHASE_CLS[phase]}`}>
|
||||
{t.phase[phase]}
|
||||
|
||||
@@ -31,9 +31,20 @@ export function monthEn(m: number): string {
|
||||
return MONTHS_EN[m - 1];
|
||||
}
|
||||
|
||||
// 녹아웃 라운드 라벨(한글) → 영문
|
||||
const ROUND_EN: Record<string, string> = {
|
||||
"32강": "Round of 32",
|
||||
"16강": "Round of 16",
|
||||
"8강": "Quarter-final",
|
||||
"4강": "Semi-final",
|
||||
"3·4위전": "3rd-place",
|
||||
"결승": "Final",
|
||||
};
|
||||
|
||||
// roundLabel 안의 한국어 토막 번역
|
||||
export function roundLabel(label: string, lang: Lang): string {
|
||||
if (lang === "ko") return label;
|
||||
if (ROUND_EN[label]) return ROUND_EN[label];
|
||||
return label.replace("개막전", "Opener");
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user