feat(kbo): 라이브 필드에 문자중계 추가 — 네이버 relay 전 이닝

- relay 응답에서 버리던 textRelays 를 타석 단위 그룹으로 서빙 (한국어 원문 그대로)
- 기본 응답은 현재 이닝만 담아, 지난 이닝은 ?inning=N 병렬 조회 후 캐시
  (현재·직전 이닝은 매번 재조회 — 이닝 전환 직후 마지막 타석 누락 방지)
- 득점 하이라이트는 텍스트 패턴이 아니라 currentGameState 점수 합 변화로 판정
  (홈런·적시타뿐 아니라 홈인·폭투/실책 득점·밀어내기까지 정확)
- 네이버 type 코드는 kind(pitch/result/run/sub/note)로 변환해 UI 에 노출하지 않음
- 진행 중엔 최근 40타석, 종료 후엔 전 경기 중계(다시보기)
- 프론트: 투구 접기/펼치기 토글 · 이닝 구분선 · 득점 강조

MLB 는 소스(feed/live allPlays)가 영문이라 별도 작업 — 이번 커밋은 KBO 만.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
JinwooKimandClaude Opus 5 committed 2026-08-14 13:57:02 +09:00
1 parent 74de57fc1c
commit 0415ab7636
3 files changed
+235 -8

No files matched your search

+89 -1
View File
@@ -1,7 +1,7 @@
import { useEffect, useState } from "react";
import type { Lang } from "@/lib/i18n";
import { timeOnly } from "@/lib/format";
import { getLive, type LiveData } from "@/lib/api";
import { getLive, type LiveData, type RelayEvent, type RelayGroup } from "@/lib/api";
import type { Match } from "@/lib/types";
// 라이브 필드 뷰 — 수비 배치 다이아몬드 + 현재 타자/투수 + B/S/O + 주자 + 대기타석.
@@ -111,6 +111,91 @@ function BallparkSvg({ bases }: { bases?: boolean[] }) {
);
}
// 이벤트 종류별 텍스트 스타일 — 투구는 흐리게, 타석 결과는 강조.
const RELAY_STYLE: Record<RelayEvent["kind"], string> = {
pitch: "text-white/35",
result: "font-extrabold text-white/90",
run: "text-[#8FD3FF]",
sub: "text-white/45",
note: "text-white/40",
inning: "text-white/60",
batter: "text-white/60",
end: "font-bold text-white/70",
};
// 문자중계 — 타석 단위 그룹(최신순). events 가 비면 이닝 구분 헤더.
// 원문이 한국어(네이버)라 영문 모드에서도 그대로 노출한다.
function RelayFeed({ groups, lang }: { groups: RelayGroup[]; lang: Lang }) {
const [showPitches, setShowPitches] = useState(true);
return (
<div className="mt-3 border-t border-white/10 pt-2.5">
<div className="mb-1.5 flex items-baseline justify-between">
<span className="text-[10px] font-bold text-white/35">
{lang === "en" ? "PLAY-BY-PLAY" : "문자중계"}
</span>
<div className="flex items-baseline gap-2">
<button
onClick={() => setShowPitches((v) => !v)}
className="text-[10px] font-bold text-white/45 transition active:scale-95"
>
{showPitches
? lang === "en" ? "Hide pitches" : "투구 접기"
: lang === "en" ? "Show pitches" : "투구 펼치기"}
</button>
<span className="text-[9px] text-white/25">NAVER</span>
</div>
</div>
<ul className="max-h-[260px] space-y-2 overflow-y-auto pr-1 [scrollbar-width:thin] [scrollbar-color:rgba(255,255,255,.22)_transparent] [&::-webkit-scrollbar]:w-1.5 [&::-webkit-scrollbar-track]:bg-transparent [&::-webkit-scrollbar-thumb]:rounded-full [&::-webkit-scrollbar-thumb]:bg-white/20">
{groups.map((g) => {
const events = showPitches ? g.events : g.events.filter((e) => e.kind !== "pitch");
// 이닝 구분 헤더 (내용 없는 그룹)
if (g.events.length === 0) {
return (
<li key={g.no} className="flex items-center gap-2 pt-1">
<span className="h-px flex-1 bg-white/10" />
<span className="text-[10px] font-extrabold text-white/40">{g.title}</span>
<span className="h-px flex-1 bg-white/10" />
</li>
);
}
if (events.length === 0) return null; // 투구만 있던 타석 — 접기 모드에선 숨김
return (
<li key={g.no}>
{g.title && (
<div className="flex items-baseline gap-1.5">
{g.inn != null && (
<span className="shrink-0 font-mono text-[10px] font-bold text-white/30">
{g.inn}
{g.half === "B" ? "말" : "초"}
</span>
)}
<span className="text-[11px] font-extrabold text-white/75">{g.title}</span>
</div>
)}
<ul className="mt-0.5 space-y-px pl-1.5 text-[11px] leading-snug">
{events.map((e, i) => (
<li
key={i}
className={
e.score
? "rounded-lg border border-[#94FBE0]/30 bg-[#94FBE0]/10 px-1.5 py-1 font-extrabold text-[#94FBE0]"
: RELAY_STYLE[e.kind]
}
>
{e.text}
</li>
))}
</ul>
</li>
);
})}
</ul>
</div>
);
}
export default function LiveField({ match, lang = "ko" }: { match: Match; lang?: Lang }) {
const isLive = match.phase === "live";
// 경기 중엔 20초 폴링, 그 외(경기 전·종료)는 1회 로드.
@@ -289,6 +374,9 @@ export default function LiveField({ match, lang = "ko" }: { match: Match; lang?:
))}
</div>
)}
{/* 문자중계 (KBO 만 — MLB 는 소스 미연동) */}
{(data.relay?.length ?? 0) > 0 && <RelayFeed groups={data.relay!} lang={lang} />}
</div>
</section>
);