feat: KBO/MLB 운영 안정화 — 순위 탭·라이브 개선·취소/더블헤더 지원·야구 점수제
AI 예측 - 생성 시점을 킥오프 22시간 전으로 변경(선발투수 예고 이후), 잡 매시간 실행 - 경기 시작 후 생성 금지(사후 예측 방지), 경기 단위 커밋으로 중단 시 진행분 보존 일정·라이브 UI - 야구 일정에 순위 탭 추가 (KBO 단일 순위표 · MLB 6개 디비전, /api/standings 신설) - 경기중 카드에 현재 이닝·실시간 스코어 표시 (30s 폴링, 서버 15s 캐시) - MLB 선발 누락 수정: statsapi 날짜 파라미터 미국 날짜 기준 보정(-1일) - 라이브 대기타석 스크롤바 다크 테마 처리 운영 견고성 - 우천취소: 경기 삭제 → cancelled 상태 보존 (투표·예측 기록 유지, 정산/투표/AI 제외) - 더블헤더: 시작시각순 seq로 1·2차전 분리 등록 (match_id _2, 정산·라이브·프리뷰 매핑) - 축구 데이터 수집을 wc 리그로 한정 (야구 팀을 축구 API에 검색하던 쿼터 낭비 수정) 점수제 - 야구 판정 완화: 근접=득실차 ±1, 부분=한 팀 득점 ±1 (등급·배점은 리그 공통 유지) - 채점 판정을 _grade_of() 단일 함수로 통합, 종료된 야구 경기 재채점 - 배점 안내 모달 야구 문구 분리, docs/SCORING.md 갱신 기타 - 야구 전용 댓글 닉네임 풀 (종목별 세션 캐시 분리) - 리더보드 리그별 조회 연동 (?league=)
This commit is contained in:
1 parent
bfaf621949
commit
4e1ebc8989
46 files changed
+2560
-188
No files matched your search
@@ -0,0 +1,295 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import type { Lang } from "@/lib/i18n";
|
||||
import { timeOnly } from "@/lib/format";
|
||||
import { getLive, type LiveData } from "@/lib/api";
|
||||
import type { Match } from "@/lib/types";
|
||||
|
||||
// 라이브 필드 뷰 — 수비 배치 다이아몬드 + 현재 타자/투수 + B/S/O + 주자 + 대기타석.
|
||||
// phase === "live" 일 때 20초 폴링. (?debugLive=1 로 종료 경기에서도 강제 표시)
|
||||
|
||||
// 포지션 → 필드 위 좌표(%) — left/top (SVG viewBox 100×70 과 동일 비율)
|
||||
const POS_XY: Record<string, [number, number]> = {
|
||||
포수: [50, 90],
|
||||
"1루수": [71, 55],
|
||||
"2루수": [61, 39],
|
||||
유격수: [39, 39],
|
||||
"3루수": [29, 55],
|
||||
좌익수: [20, 26],
|
||||
중견수: [50, 14],
|
||||
우익수: [80, 26],
|
||||
};
|
||||
|
||||
// 필드 SVG 상 베이스 좌표 (viewBox 0 0 100 70) — 1루·2루·3루
|
||||
const BASE_XY: [number, number][] = [
|
||||
[63.5, 42.5],
|
||||
[50, 29],
|
||||
[36.5, 42.5],
|
||||
];
|
||||
|
||||
function NameChip({
|
||||
name,
|
||||
sub,
|
||||
accent = false,
|
||||
x,
|
||||
y,
|
||||
}: {
|
||||
name: string;
|
||||
sub?: string;
|
||||
accent?: boolean;
|
||||
x: number;
|
||||
y: number;
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
className="absolute -translate-x-1/2 -translate-y-1/2 text-center"
|
||||
style={{ left: `${x}%`, top: `${y}%` }}
|
||||
>
|
||||
<div
|
||||
className={`whitespace-nowrap rounded-full px-2.5 py-1 text-[11px] font-bold shadow-[0_1px_3px_rgba(0,0,0,0.25)] ${
|
||||
accent ? "bg-[#d94141] text-white" : "bg-white text-[#222]"
|
||||
}`}
|
||||
>
|
||||
{name}
|
||||
</div>
|
||||
{sub && (
|
||||
<div className="mt-0.5 text-[9px] font-bold text-[#245c2a]/80">{sub}</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Dot({ on, color }: { on: boolean; color: string }) {
|
||||
return (
|
||||
<span
|
||||
className="inline-block h-2.5 w-2.5 rounded-full"
|
||||
style={{ background: on ? color : "rgba(255,255,255,0.14)" }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
// 구장 SVG — 부채꼴 외야 + 파울라인 + 흙 내야 + 마운드 + 베이스(주자 점등).
|
||||
// 경기 전(빈 구장)·경기 중·종료 스냅샷 모두 공용.
|
||||
function BallparkSvg({ bases }: { bases?: boolean[] }) {
|
||||
return (
|
||||
<svg
|
||||
viewBox="0 0 100 70"
|
||||
preserveAspectRatio="none"
|
||||
className="absolute inset-0 h-full w-full"
|
||||
>
|
||||
<rect width="100" height="70" fill="#4e8a48" />
|
||||
<path
|
||||
d="M50,62 L8,20 A60,60 0 0 1 92,20 Z"
|
||||
fill="#6cb163"
|
||||
stroke="rgba(255,255,255,0.85)"
|
||||
strokeWidth="0.5"
|
||||
/>
|
||||
<polygon points="50,20 73,43 50,66 27,43" fill="#cd9f63" />
|
||||
<polygon
|
||||
points="50,29 63.5,42.5 50,56 36.5,42.5"
|
||||
fill="#6cb163"
|
||||
stroke="rgba(255,255,255,0.4)"
|
||||
strokeWidth="0.4"
|
||||
/>
|
||||
<circle cx="50" cy="43" r="3.2" fill="#cd9f63" />
|
||||
<circle cx="50" cy="60.5" r="4.2" fill="#cd9f63" />
|
||||
{BASE_XY.map(([cx, cy], i) => (
|
||||
<rect
|
||||
key={i}
|
||||
x={cx - 1.5}
|
||||
y={cy - 1.5}
|
||||
width="3"
|
||||
height="3"
|
||||
rx="0.5"
|
||||
transform={`rotate(45 ${cx} ${cy})`}
|
||||
fill={bases?.[i] ? "#ffd23e" : "#ffffff"}
|
||||
stroke="rgba(0,0,0,0.15)"
|
||||
strokeWidth="0.3"
|
||||
/>
|
||||
))}
|
||||
<rect x="48.8" y="59.3" width="2.4" height="2.4" rx="0.4" fill="#ffffff" />
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
export default function LiveField({ match, lang = "ko" }: { match: Match; lang?: Lang }) {
|
||||
const isLive = match.phase === "live";
|
||||
// 경기 중엔 20초 폴링, 그 외(경기 전·종료)는 1회 로드.
|
||||
// 경기 전엔 중계 미게시(available=false)라도 빈 구장 + "경기 전"으로 표시.
|
||||
const [data, setData] = useState<LiveData | null>(null);
|
||||
|
||||
const isBaseball = match.league === "kbo" || match.league === "mlb";
|
||||
|
||||
useEffect(() => {
|
||||
if (!isBaseball) return;
|
||||
let alive = true;
|
||||
const load = () =>
|
||||
getLive(match.matchId)
|
||||
.then((d) => alive && setData(d))
|
||||
.catch(() => {});
|
||||
load();
|
||||
if (!isLive) return () => { alive = false; };
|
||||
const id = setInterval(load, 20_000);
|
||||
return () => {
|
||||
alive = false;
|
||||
clearInterval(id);
|
||||
};
|
||||
}, [isBaseball, isLive, match.matchId]);
|
||||
|
||||
// 야구 전용 위젯 — 축구(월드컵)에서는 렌더하지 않음
|
||||
if (!isBaseball) return null;
|
||||
|
||||
// 중계 데이터 없음 (경기 전 또는 시작 직후) — 빈 구장 + 상태 라벨
|
||||
if (!data?.available) {
|
||||
if (match.phase === "finished") return null; // 종료인데 기록 없음 — 표시할 것 없음
|
||||
return (
|
||||
<section className="mt-4">
|
||||
<div className="rounded-3xl border border-white/10 bg-[#171b21] p-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-[13px] font-extrabold text-white/45">
|
||||
{lang === "en" ? "FIELD" : "필드"}
|
||||
</span>
|
||||
<span className="font-mono text-[13px] font-bold text-white/55">
|
||||
{timeOnly(match.kickoffKst)} KST
|
||||
</span>
|
||||
</div>
|
||||
<div className="relative mt-3 aspect-[10/7] overflow-hidden rounded-2xl">
|
||||
<BallparkSvg />
|
||||
<div className="absolute inset-0 grid place-items-center">
|
||||
<span className="rounded-full bg-black/50 px-4 py-1.5 text-[13px] font-extrabold text-white/95">
|
||||
{isLive
|
||||
? lang === "en"
|
||||
? "Starting soon…"
|
||||
: "경기 시작 대기 중"
|
||||
: lang === "en"
|
||||
? "Pre-game · lineups TBA"
|
||||
: "경기 전 · 라인업 발표 전"}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
const half = data.half === "B" ? (lang === "en" ? "Bot" : "말") : lang === "en" ? "Top" : "초";
|
||||
const battingTeam = data.half === "B" ? match.teamB : match.teamA;
|
||||
const num = (v: unknown) => Number(v ?? 0) || 0;
|
||||
|
||||
return (
|
||||
<section className="mt-4">
|
||||
<div className="rounded-3xl border border-white/10 bg-[#171b21] p-4">
|
||||
{/* 헤더: 이닝·스코어·B/S/O */}
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
{isLive ? (
|
||||
<>
|
||||
<span className="flex h-2 w-2">
|
||||
<span className="absolute inline-flex h-2 w-2 animate-ping rounded-full bg-[#FF5B5B] opacity-60" />
|
||||
<span className="relative inline-flex h-2 w-2 rounded-full bg-[#FF5B5B]" />
|
||||
</span>
|
||||
<span className="text-[13px] font-extrabold text-[#FF5B5B]">
|
||||
LIVE · {data.inn}
|
||||
{lang === "en" ? ` (${half})` : `회${half}`}
|
||||
</span>
|
||||
</>
|
||||
) : (
|
||||
<span className="text-[13px] font-extrabold text-white/45">
|
||||
{lang === "en" ? "FINAL" : "경기 종료"} · {data.inn}
|
||||
{lang === "en" ? ` (${half})` : `회${half}`}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<span className="font-mono text-[18px] font-extrabold tabular-nums">
|
||||
{match.teamA.shortName} {num(data.score?.away)}
|
||||
<span className="px-1 text-white/40">:</span>
|
||||
{num(data.score?.home)} {match.teamB.shortName}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* B/S/O + 주자 다이아몬드 */}
|
||||
<div className="mt-3 flex items-center justify-between rounded-2xl bg-white/[0.04] px-3 py-2">
|
||||
<div className="space-y-1 text-[10px] font-bold text-white/50">
|
||||
<div className="flex items-center gap-1.5">
|
||||
B{" "}
|
||||
{[0, 1, 2].map((i) => (
|
||||
<Dot key={i} on={num(data.bso?.b) > i} color="#4ade80" />
|
||||
))}
|
||||
</div>
|
||||
<div className="flex items-center gap-1.5">
|
||||
S{" "}
|
||||
{[0, 1].map((i) => (
|
||||
<Dot key={i} on={num(data.bso?.s) > i} color="#facc15" />
|
||||
))}
|
||||
</div>
|
||||
<div className="flex items-center gap-1.5">
|
||||
O{" "}
|
||||
{[0, 1].map((i) => (
|
||||
<Dot key={i} on={num(data.bso?.o) > i} color="#f87171" />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="text-right text-[11px] font-semibold text-white/55">
|
||||
<div>
|
||||
{lang === "en" ? "AB" : "타석"}{" "}
|
||||
<span className="font-extrabold text-white/90">{battingTeam.shortName}</span>
|
||||
</div>
|
||||
{data.vsRecord && <div className="mt-0.5 text-[10px] text-white/35">{data.vsRecord}</div>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 필드: 구장 SVG + 수비 배치/투수/타자 칩 */}
|
||||
<div className="relative mt-3 aspect-[10/7] overflow-hidden rounded-2xl">
|
||||
<BallparkSvg bases={data.bases} />
|
||||
{data.defense?.map((f) => {
|
||||
const xy = POS_XY[f.pos ?? ""];
|
||||
if (!xy) return null;
|
||||
return <NameChip key={f.pos} name={f.name} sub={f.pos} x={xy[0]} y={xy[1]} />;
|
||||
})}
|
||||
{data.pitcher && (
|
||||
<NameChip
|
||||
name={data.pitcher.name}
|
||||
sub={`${lang === "en" ? "P" : "투구수"} ${num(data.pitcher.ballCount)}`}
|
||||
x={50}
|
||||
y={61}
|
||||
/>
|
||||
)}
|
||||
{data.batter && (
|
||||
<NameChip
|
||||
name={`${data.batter.order ?? ""}. ${data.batter.name}`}
|
||||
accent
|
||||
x={50}
|
||||
y={79}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 대기타석 */}
|
||||
{data.batter && data.offenseLineup && (
|
||||
<div className="mt-3 flex items-center gap-2 overflow-x-auto pb-1 text-[11px] font-semibold text-white/55 [scrollbar-width:thin] [scrollbar-color:rgba(255,255,255,.22)_transparent] [&::-webkit-scrollbar]:h-1.5 [&::-webkit-scrollbar-track]:bg-transparent [&::-webkit-scrollbar-thumb]:rounded-full [&::-webkit-scrollbar-thumb]:bg-white/20">
|
||||
<span className="shrink-0 text-white/35">{lang === "en" ? "Next" : "대기타석"}</span>
|
||||
{data.offenseLineup
|
||||
.filter((b) => {
|
||||
const cur = data.batter!.order ?? 0;
|
||||
const diff = ((b.order ?? 0) - cur + 9) % 9;
|
||||
return diff >= 1 && diff <= 3;
|
||||
})
|
||||
.sort((a, b) => {
|
||||
const cur = data.batter!.order ?? 0;
|
||||
return (((a.order ?? 0) - cur + 9) % 9) - (((b.order ?? 0) - cur + 9) % 9);
|
||||
})
|
||||
.map((b) => (
|
||||
<span
|
||||
key={b.order}
|
||||
className="shrink-0 rounded-full border border-white/10 px-2 py-0.5"
|
||||
>
|
||||
{b.order}. {b.name}
|
||||
{b.sub ? " ↺" : ""}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user