내 지난 얘측 보기 기능 추가, 한국 멕시코 경기 응원가 1곡 추가

This commit is contained in:
JinwooKim committed 2026-06-18 15:41:39 +09:00
1 parent 0e5a63a28b
commit b4fc96f299
12 files changed
+257 -8

No files matched your search

+118 -2
View File
@@ -7,14 +7,28 @@ import type {
ModelName,
Match,
AIPrediction,
MyPrediction,
Team,
} from "@/lib/types";
import { ApiError, getDeviceId, getRecentEmails, rememberEmail, submitPrediction } from "@/lib/api";
import {
ApiError,
fetchMyPredictions,
getDeviceId,
getRecentEmails,
rememberEmail,
submitPrediction,
} from "@/lib/api";
import Countdown from "./Countdown";
import TeamFlag from "./TeamFlag";
type Step = "form" | "done";
// 제출 시각 ISO → "6.18" (내 예측 목록 우측 라벨)
function fmtSubmitted(iso: string): string {
const m = iso.match(/\d{4}-(\d{2})-(\d{2})/);
return m ? `${+m[1]}.${+m[2]}` : "";
}
const MODEL_ICON: Record<ModelName, string> = {
GPT: "/icons/gpt.png",
Claude: "/icons/claude.jpg",
@@ -51,6 +65,8 @@ export default function Arena({
const [submitting, setSubmitting] = useState(false);
const [error, setError] = useState<string | null>(null);
const [showRules, setShowRules] = useState(false);
const [myPreds, setMyPreds] = useState<MyPrediction[]>([]);
const [votesExpanded, setVotesExpanded] = useState(false);
// 점수 선택 시 승/무/패 자동 선택 (스코어가 결과의 소스)
useEffect(() => {
@@ -59,6 +75,25 @@ export default function Arena({
);
}, [scoreA, scoreB]);
// 재방문 시: 가장 최근 사용 이메일로 내 지난 예측 자동 로드 (로그인 대체).
// 이메일 칸은 비워둠 — develop UX(포커스 시 datalist 자동완성)를 유지.
useEffect(() => {
const last = getRecentEmails()[0];
if (last) fetchMyPredictions(last).then(setMyPreds).catch(() => {});
}, []);
// 이 경기에 대한 내 기존 픽 (있으면 스코어 프리필 + 목록에서 강조)
const myThisMatch = useMemo(
() => myPreds.find((p) => p.matchId === match.matchId),
[myPreds, match.matchId],
);
useEffect(() => {
if (myThisMatch) {
setScoreA(myThisMatch.scoreA);
setScoreB(myThisMatch.scoreB);
}
}, [myThisMatch]);
// 투표 가능 여부는 백엔드 계산(votingOpen, demo 반영) + phase 라벨.
const finished = !!match.result;
const disabled = finished || !match.votingOpen;
@@ -98,6 +133,8 @@ export default function Arena({
setCrowd(res.crowd); // 서버 권위 분포로 갱신
rememberEmail(email.trim()); // 다음 투표 자동완성용으로 기억
setRecentEmails(getRecentEmails());
// 방금 제출 포함해 내 지난 예측 갱신(이번 경기 강조/upsert 반영)
fetchMyPredictions(email.trim()).then(setMyPreds).catch(() => {});
setStep("done");
} catch (e) {
const msg =
@@ -304,7 +341,13 @@ export default function Arena({
list="tp-email-suggestions"
autoComplete="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
onChange={(e) => {
const v = e.target.value;
setEmail(v);
// 유효 이메일이면 그 즉시 내 지난 예측 조회(다른 기기/세션 흔적까지 표시)
if (EMAIL_RE.test(v.trim()))
fetchMyPredictions(v.trim()).then(setMyPreds).catch(() => {});
}}
placeholder={t.emailPh}
className="w-full rounded-2xl border border-[var(--share)] bg-[#0f1217] px-4 py-3 text-[16px] text-white shadow-[0_0_0_2px_rgba(166,94,255,0.12)] outline-none focus:shadow-[0_0_0_2px_rgba(166,94,255,0.3)]"
/>
@@ -366,6 +409,79 @@ export default function Arena({
</div>
)}
{/* ===== 내 지난 예측 (이메일 기준, 로그인 없음) ===== */}
{myPreds.length > 0 && (
<section className="mt-5 rounded-2xl border border-[var(--line-d)] bg-[var(--bg2)] p-4">
<div className="mb-3 flex items-baseline justify-between gap-2">
<h3 className="text-[16px] font-extrabold">{t.myVotesTitle}</h3>
<span className="shrink-0 text-[12px] text-[var(--ink-muted)]">
{t.myVotesSub}
</span>
</div>
<ul className="flex flex-col gap-2">
{(votesExpanded ? myPreds : myPreds.slice(0, 1)).map((p) => {
const isThis = p.matchId === match.matchId;
const pA = teamShort(p.teamA, lang);
const pB = teamShort(p.teamB, lang);
const pickTxt =
p.outcome === "TEAM_A_WIN"
? `${pA} ${t.win}`
: p.outcome === "TEAM_B_WIN"
? `${pB} ${t.win}`
: t.drawLabel;
return (
<li
key={p.matchId}
className={`flex items-center justify-between gap-3 rounded-xl border px-3 py-2.5 ${
isThis
? "border-[var(--share)] bg-[rgba(166,94,255,0.1)]"
: "border-[var(--line-d)]"
}`}
>
<div className="min-w-0">
<div className="text-[15px] font-bold text-white">
{pA} {p.scoreA}-{p.scoreB} {pB}
</div>
<div className="mt-0.5 text-[12px] text-[var(--ink-muted)]">
{pickTxt}
{isThis && (
<span className="text-[var(--share)]"> · {t.thisMatch}</span>
)}
</div>
</div>
{p.result ? (
<span
className={`shrink-0 text-[13px] font-bold ${
p.result.hitOutcome
? "text-[var(--share)]"
: "text-[var(--ink-muted)]"
}`}
>
{p.result.hitOutcome ? t.hit : t.miss}
</span>
) : (
<span className="shrink-0 text-[11px] text-[var(--ink-muted)]">
{fmtSubmitted(p.submittedAt)}
</span>
)}
</li>
);
})}
</ul>
{myPreds.length > 1 && (
<button
onClick={() => setVotesExpanded((v) => !v)}
className="mt-3 flex w-full items-center justify-center gap-1 rounded-xl border border-[var(--line-d)] py-2.5 text-[13px] font-bold text-[var(--ink-muted)] transition active:scale-[0.99]"
>
{votesExpanded
? t.myVotesShowLess
: t.myVotesShowMore(myPreds.length - 1)}
<span aria-hidden>{votesExpanded ? "▲" : "▼"}</span>
</button>
)}
</section>
)}
{/* ===== 골드 상금 (003) ===== */}
<section className="gold-card mt-5 rounded-2xl p-5">
<div className="flex items-center justify-between gap-3">
+1 -1
View File
@@ -180,7 +180,7 @@ export default function Comments({
) : (
<ul
className={`mt-4 divide-y divide-[var(--line-d)] ${
expanded ? "max-h-[360px] overflow-y-auto pr-1" : ""
expanded ? "max-h-[360px] overflow-y-auto pr-1 scroll-dark" : ""
}`}
>
{visible.map((c, i) => (