Load all 12 groups' schedule (72 matches) + Naver-style schedule UI
Backend
- teams_data.py: 48-team data (ko/short/en), TLA→FIFA code remap
- config: schedule_all_groups, featured_group("A") — only featured group is votable/AI-predicted
- schedule_fetch: fetch all GROUP_STAGE matches from football-data, KST serialize
- schedule_sync: ingest all groups, unordered-pair match to avoid Group A dup, derive votable from group
- worker: AI generation limited to featured group; settle still covers all
- domain/predictions: is_votable() + MatchOut.votable; reject non-votable submits with 403 MATCH_NOT_VOTABLE
Frontend
- types: Match.votable
- ScheduleBoard: Naver-style date/group tabs + chips; votable(A) cards link to detail with AI split + 참여수, others display-only
Verified: 72 matches (12×6), Group A not duplicated, votable A=6/others=66; A submit 200, B submit 403
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
c9244bc42d
commit
deb1332440
10 files changed
+366
-99
No files matched your search
@@ -1,31 +1,28 @@
|
||||
import { useMemo, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { dateHeading, timeOnly } from "@/lib/format";
|
||||
import { type Lang, dict, teamShort, roundLabel as tRound } from "@/lib/i18n";
|
||||
import { timeOnly, dateKey } from "@/lib/format";
|
||||
import { type Lang, dict, teamShort, roundLabel as tRound, dayName, monthEn } from "@/lib/i18n";
|
||||
import type { Match, MatchPhase } from "@/lib/types";
|
||||
import { dateKey } from "@/lib/format";
|
||||
import TeamFlag from "./TeamFlag";
|
||||
|
||||
const STROKE = "#94FBE0"; // 일정 텍스트·선택 아웃라인 스트로크 컬러
|
||||
// 칩용 짧은 날짜: "6.12 (금)" / "Jun 12 (Fri)"
|
||||
function shortDate(iso: string, lang: Lang): string {
|
||||
const m = iso.match(/(\d{4})-(\d{2})-(\d{2})/);
|
||||
if (!m) return iso;
|
||||
const [, y, mo, d] = m;
|
||||
const dow = dayName(lang, new Date(Date.UTC(+y, +mo - 1, +d)).getUTCDay());
|
||||
return lang === "en" ? `${monthEn(+mo)} ${+d} (${dow})` : `${+mo}.${+d} (${dow})`;
|
||||
}
|
||||
|
||||
const PHASE_CLS: Record<MatchPhase, string> = {
|
||||
open: "border-[#94FBE0] text-[#94FBE0]",
|
||||
scheduled: "border-[var(--line-d)] text-[var(--ink-muted)]",
|
||||
locked: "border-[var(--line-d)] text-white/45", // 투표 종료 — 비활성 톤
|
||||
live: "border-[#FF5B5B] text-[#FF5B5B]", // 경기중 — 라이브 강조
|
||||
locked: "border-[var(--line-d)] text-white/45",
|
||||
live: "border-[#FF5B5B] text-[#FF5B5B]",
|
||||
finished: "border-white/15 text-white/55",
|
||||
};
|
||||
|
||||
// 날짜별로 묶고 킥오프 오름차순 정렬 (백엔드가 이미 정렬 반환)
|
||||
function groupByDate(matches: Match[]): { date: string; matches: Match[] }[] {
|
||||
const groups: { date: string; matches: Match[] }[] = [];
|
||||
for (const m of matches) {
|
||||
const key = dateKey(m.kickoffKst);
|
||||
const last = groups[groups.length - 1];
|
||||
if (last && last.date === key) last.matches.push(m);
|
||||
else groups.push({ date: key, matches: [m] });
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
type Tab = "date" | "group";
|
||||
|
||||
export default function ScheduleBoard({
|
||||
matches,
|
||||
@@ -35,66 +32,137 @@ export default function ScheduleBoard({
|
||||
lang?: Lang;
|
||||
}) {
|
||||
const t = dict(lang);
|
||||
const groups = groupByDate(matches);
|
||||
const [tab, setTab] = useState<Tab>("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조
|
||||
const todayKey = useMemo(() => new Date().toISOString().slice(0, 10), []);
|
||||
const [selDate, setSelDate] = useState(
|
||||
() => (dates.includes(todayKey) ? todayKey : dates[0]) ?? "",
|
||||
);
|
||||
const [selGroup, setSelGroup] = useState(
|
||||
() => (groups.includes("A") ? "A" : groups[0]) ?? "",
|
||||
);
|
||||
|
||||
const shown = useMemo(() => {
|
||||
const list =
|
||||
tab === "date"
|
||||
? matches.filter((m) => dateKey(m.kickoffKst) === selDate)
|
||||
: matches.filter((m) => m.group === selGroup);
|
||||
return [...list].sort(
|
||||
(a, b) => new Date(a.kickoffKst).getTime() - new Date(b.kickoffKst).getTime(),
|
||||
);
|
||||
}, [matches, tab, selDate, selGroup]);
|
||||
|
||||
const tabLabel = (k: Tab) =>
|
||||
k === "date" ? (lang === "en" ? "By date" : "날짜별") : lang === "en" ? "Groups" : "조별리그";
|
||||
|
||||
return (
|
||||
<section className="mt-6">
|
||||
<div className="mb-3 flex items-baseline gap-2.5">
|
||||
<h2 className="shrink-0 text-[22px] font-extrabold">{t.schedTitle}</h2>
|
||||
<span className="whitespace-nowrap text-[12px] text-white/55">
|
||||
{t.schedGuide}
|
||||
</span>
|
||||
<span className="whitespace-nowrap text-[12px] text-white/55">{t.schedGuide}</span>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-5">
|
||||
{groups.map((g) => (
|
||||
<div key={g.date}>
|
||||
<div className="mb-2 text-[13px] font-bold" style={{ color: STROKE }}>
|
||||
{dateHeading(g.date, lang)}
|
||||
</div>
|
||||
<div className="flex flex-col gap-2.5">
|
||||
{g.matches.map((m) => (
|
||||
<MatchCard key={m.matchId} match={m} lang={lang} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
{/* 탭: 날짜별 / 조별리그 */}
|
||||
<div className="mb-3 flex gap-5 border-b border-[var(--line-d)]">
|
||||
{(["date", "group"] as Tab[]).map((k) => (
|
||||
<button
|
||||
key={k}
|
||||
onClick={() => setTab(k)}
|
||||
className={`-mb-px border-b-2 pb-2 text-[15px] font-bold transition ${
|
||||
tab === k
|
||||
? "border-[var(--green)] text-white"
|
||||
: "border-transparent text-white/45"
|
||||
}`}
|
||||
>
|
||||
{tabLabel(k)}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* 칩: 날짜 또는 조 */}
|
||||
<div className="mb-4 flex gap-2 overflow-x-auto pb-1 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden">
|
||||
{tab === "date"
|
||||
? dates.map((d) => (
|
||||
<Chip key={d} active={d === selDate} onClick={() => setSelDate(d)}>
|
||||
{shortDate(d, lang)}
|
||||
</Chip>
|
||||
))
|
||||
: groups.map((g) => (
|
||||
<Chip key={g} active={g === selGroup} onClick={() => setSelGroup(g)}>
|
||||
{lang === "en" ? `Group ${g}` : `${g}조`}
|
||||
</Chip>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* 경기 카드 */}
|
||||
<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" : "경기가 없습니다"}
|
||||
</p>
|
||||
)}
|
||||
{shown.map((m) => (
|
||||
<MatchCard key={m.matchId} match={m} lang={lang} />
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function Chip({
|
||||
active,
|
||||
onClick,
|
||||
children,
|
||||
}: {
|
||||
active: boolean;
|
||||
onClick: () => void;
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<button
|
||||
onClick={onClick}
|
||||
className={`shrink-0 whitespace-nowrap rounded-full border px-3.5 py-1.5 text-[13px] font-bold transition ${
|
||||
active
|
||||
? "border-[#94FBE0] text-[#94FBE0]"
|
||||
: "border-[var(--line-d)] text-white/55"
|
||||
}`}
|
||||
>
|
||||
{children}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
function MatchCard({ match, lang }: { match: Match; lang: Lang }) {
|
||||
const t = dict(lang);
|
||||
const phase = match.phase;
|
||||
const preds = match.predictions;
|
||||
const crowdTotal = match.crowd?.total ?? 0;
|
||||
const finished = !!match.result;
|
||||
|
||||
// AI 픽 갈림 요약
|
||||
const tally = { a: 0, d: 0, b: 0 };
|
||||
for (const p of preds) {
|
||||
if (p.outcome === "TEAM_A_WIN") tally.a++;
|
||||
else if (p.outcome === "DRAW") tally.d++;
|
||||
else tally.b++;
|
||||
}
|
||||
const split: string[] = [];
|
||||
if (tally.a) split.push(`${teamShort(match.teamA, lang)} ${tally.a}`);
|
||||
if (tally.d) split.push(`${t.draw} ${tally.d}`);
|
||||
if (tally.b) split.push(`${teamShort(match.teamB, lang)} ${tally.b}`);
|
||||
|
||||
const href = `/match/${match.matchId}${lang === "en" ? "?lang=en" : ""}`;
|
||||
|
||||
return (
|
||||
<Link
|
||||
to={href}
|
||||
className="block rounded-2xl border-2 border-[#94FBE0]/45 bg-[#171b21] p-4 transition active:scale-[0.99] hover:border-[#94FBE0]"
|
||||
>
|
||||
// 비투표(타 조)는 클릭 비활성, 투표 가능 조(A)는 상세로 이동
|
||||
const inner = (
|
||||
<>
|
||||
<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> ·{" "}
|
||||
{tRound(match.roundLabel, lang)}
|
||||
{timeOnly(match.kickoffKst)} <span className="text-white/40">KST</span>
|
||||
{match.roundLabel ? <> · {tRound(match.roundLabel, lang)}</> : null}
|
||||
</span>
|
||||
<span className={`rounded-md border px-2 py-0.5 font-semibold ${PHASE_CLS[phase]}`}>
|
||||
{t.phase[phase]}
|
||||
<span className="flex items-center gap-1.5">
|
||||
<span className="text-[11px] font-bold text-white/45">
|
||||
{lang === "en" ? `Group ${match.group}` : `${match.group}조`}
|
||||
</span>
|
||||
<span className={`rounded-md border px-2 py-0.5 font-semibold ${PHASE_CLS[phase]}`}>
|
||||
{t.phase[phase]}
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -104,7 +172,6 @@ function MatchCard({ match, lang }: { match: Match; lang: Lang }) {
|
||||
<span className="truncate text-[15px] font-extrabold">{teamShort(match.teamA, lang)}</span>
|
||||
</div>
|
||||
{match.result ? (
|
||||
// 종료된 경기 — 최종 스코어 (예: 3 : 2)
|
||||
<span className="whitespace-nowrap font-mono text-[18px] font-extrabold tabular-nums text-white">
|
||||
{match.result.scoreA}
|
||||
<span className="px-1.5 text-white/40">:</span>
|
||||
@@ -119,15 +186,55 @@ function MatchCard({ match, lang }: { match: Match; lang: Lang }) {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mt-3 flex items-center justify-between text-[11px] font-bold text-[#F4F3FE]">
|
||||
<span>
|
||||
<span className="font-semibold text-white/55">{t.aiPicks}</span> {split.join(" · ")}
|
||||
</span>
|
||||
<span className="flex items-center gap-2">
|
||||
<span>{t.joined(crowdTotal.toLocaleString())}</span>
|
||||
<span className="text-[#94FBE0]">→</span>
|
||||
</span>
|
||||
</div>
|
||||
</Link>
|
||||
{/* 투표 가능 조만: AI 픽 갈림 + 참여수 + 이동 화살표 */}
|
||||
{match.votable && (
|
||||
<div className="mt-3 flex items-center justify-between text-[11px] font-bold text-[#F4F3FE]">
|
||||
<span>
|
||||
<span className="font-semibold text-white/55">{t.aiPicks}</span>{" "}
|
||||
{aiSplit(match, lang).join(" · ")}
|
||||
</span>
|
||||
<span className="flex items-center gap-2">
|
||||
<span>{t.joined((match.crowd?.total ?? 0).toLocaleString())}</span>
|
||||
<span className="text-[#94FBE0]">→</span>
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
|
||||
const base = "block rounded-2xl border-2 bg-[#171b21] p-4";
|
||||
if (match.votable && !finished) {
|
||||
return (
|
||||
<Link
|
||||
to={`/match/${match.matchId}${lang === "en" ? "?lang=en" : ""}`}
|
||||
className={`${base} border-[#94FBE0]/45 transition active:scale-[0.99] hover:border-[#94FBE0]`}
|
||||
>
|
||||
{inner}
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
// 종료된 투표 경기는 결과 보기로, 비투표 경기는 표시 전용(클릭 시 상세=결과)
|
||||
if (match.votable) {
|
||||
return (
|
||||
<Link to={`/match/${match.matchId}${lang === "en" ? "?lang=en" : ""}`} className={`${base} border-white/12`}>
|
||||
{inner}
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
return <div className={`${base} border-[var(--line-d)]`}>{inner}</div>;
|
||||
}
|
||||
|
||||
function aiSplit(match: Match, lang: Lang): string[] {
|
||||
const t = dict(lang);
|
||||
const tally = { a: 0, d: 0, b: 0 };
|
||||
for (const p of match.predictions) {
|
||||
if (p.outcome === "TEAM_A_WIN") tally.a++;
|
||||
else if (p.outcome === "DRAW") tally.d++;
|
||||
else tally.b++;
|
||||
}
|
||||
const out: string[] = [];
|
||||
if (tally.a) out.push(`${teamShort(match.teamA, lang)} ${tally.a}`);
|
||||
if (tally.d) out.push(`${t.draw} ${tally.d}`);
|
||||
if (tally.b) out.push(`${teamShort(match.teamB, lang)} ${tally.b}`);
|
||||
return out.length ? out : ["-"];
|
||||
}
|
||||
Reference in new issue
Block a user