Add "my past predictions" (email-based, no login) + cleanup
- New lib/myPredictions.ts: typed contract (fetch/save/remember/recall) with localStorage demo impl; backend dev swaps the two bodies for Firebase callables (getMyPredictions / submitPrediction) - Arena: recall email on revisit, show my picks sorted newest-first, prefill + highlight the current match, upsert per match - Fold list to 1 row by default with 더보기/접기 toggle (handles 10s of votes) - Result badges: hit = purple (--share), miss = gray; date until scored - Remove unused orange --claude token (orange-ban rule; logo image stays) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
cbe0e8e01d
commit
b69b1dbe97
4 files changed
+237
-11
No files matched your search
+15
@@ -94,6 +94,11 @@ type Dict = {
|
||||
ado2Cta: string;
|
||||
genLabel: string;
|
||||
moreMatches: string;
|
||||
myVotesTitle: string;
|
||||
myVotesSub: string;
|
||||
thisMatch: string;
|
||||
showMore: (n: number) => string;
|
||||
showLess: string;
|
||||
};
|
||||
|
||||
export const DICT: Record<Lang, Dict> = {
|
||||
@@ -152,6 +157,11 @@ export const DICT: Record<Lang, Dict> = {
|
||||
hook: (a, b) => `${a} vs ${b}, AI의 선택은 갈렸다`,
|
||||
genLabel: "예측 기준",
|
||||
moreMatches: "다른 경기 투표하기",
|
||||
myVotesTitle: "내 지난 예측",
|
||||
myVotesSub: "이메일 기준 · 최신순",
|
||||
thisMatch: "이번 경기",
|
||||
showMore: (n) => `더보기 +${n}`,
|
||||
showLess: "접기",
|
||||
adLabel: "광고",
|
||||
ado2Tagline: "AI 마케팅 자동화 플랫폼",
|
||||
ado2Sub: "AI Marketing Automation Platform →",
|
||||
@@ -212,6 +222,11 @@ export const DICT: Record<Lang, Dict> = {
|
||||
hook: (a, b) => `AI is split on ${a} vs ${b}`,
|
||||
genLabel: "As of",
|
||||
moreMatches: "Vote on another match",
|
||||
myVotesTitle: "Your past predictions",
|
||||
myVotesSub: "By email · newest first",
|
||||
thisMatch: "This match",
|
||||
showMore: (n) => `Show ${n} more`,
|
||||
showLess: "Show less",
|
||||
adLabel: "AD",
|
||||
ado2Tagline: "AI Marketing Automation Platform",
|
||||
ado2Sub: "Visit ado2.o2osolution.ai →",
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
// 내 지난 예측 — 로그인 없이 이메일 기준 조회/저장
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
// UI(Arena.tsx)는 아래 4개 함수의 "시그니처(입출력 타입)"에만 의존한다.
|
||||
// 백엔드 개발자는 fetchMyPredictions / saveMyPrediction 의 *본문만*
|
||||
// Firebase 콜러블 함수(getMyPredictions / submitPrediction) 호출로 교체하면
|
||||
// UI 코드는 수정할 필요가 없다. (rememberEmail/recallEmail 은 그대로 클라 보관)
|
||||
//
|
||||
// 현재 구현: 데모용 localStorage (기기 1대 기준). 운영에서는 Firestore
|
||||
// user_predictions 를 이메일로 조회하는 콜러블로 대체 → 기기 간 동기화.
|
||||
import type { Outcome } from "./types";
|
||||
|
||||
/** 이메일 기준으로 조회되는 1건의 사용자 예측 (표시·정렬용 필드 포함) */
|
||||
export type MyPrediction = {
|
||||
matchId: string;
|
||||
teamAShort: string; // "멕시코"
|
||||
teamBShort: string; // "한국"
|
||||
kickoffKst: string; // ISO — 정렬/표시용
|
||||
outcome: Outcome;
|
||||
scoreA: number;
|
||||
scoreB: number;
|
||||
submittedAt: string; // ISO — 제출 시각(최신순 정렬 기준)
|
||||
/** 경기 종료 시 백엔드가 채움. 미종료면 undefined */
|
||||
result?: { outcome: Outcome; scoreA: number; scoreB: number; hitOutcome: boolean };
|
||||
};
|
||||
|
||||
const STORE_KEY = "tp_my_predictions_v1"; // { [emailLower]: MyPrediction[] }
|
||||
const EMAIL_KEY = "tp_email_v1";
|
||||
|
||||
const normEmail = (email: string) => email.trim().toLowerCase();
|
||||
|
||||
function readStore(): Record<string, MyPrediction[]> {
|
||||
if (typeof window === "undefined") return {};
|
||||
try {
|
||||
return JSON.parse(window.localStorage.getItem(STORE_KEY) || "{}");
|
||||
} catch {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
function writeStore(store: Record<string, MyPrediction[]>) {
|
||||
if (typeof window === "undefined") return;
|
||||
window.localStorage.setItem(STORE_KEY, JSON.stringify(store));
|
||||
}
|
||||
|
||||
/* ============================================================
|
||||
* 백엔드 연동 지점 ① — 내 예측 목록 조회
|
||||
* 개발자: 본문을 getMyPredictions 콜러블 호출로 교체.
|
||||
* const { fns } = getFirebase();
|
||||
* const res = await httpsCallable(fns, "getMyPredictions")({ email });
|
||||
* return res.data as MyPrediction[]; // 최신순 정렬 보장
|
||||
* ============================================================ */
|
||||
export async function fetchMyPredictions(email: string): Promise<MyPrediction[]> {
|
||||
if (!email) return [];
|
||||
const list = readStore()[normEmail(email)] ?? [];
|
||||
// 최신 제출순(내림차순)
|
||||
return [...list].sort((a, b) => b.submittedAt.localeCompare(a.submittedAt));
|
||||
}
|
||||
|
||||
/* ============================================================
|
||||
* 백엔드 연동 지점 ② — 내 예측 제출/갱신
|
||||
* 개발자: 본문을 submitPrediction 콜러블 호출로 교체(서버에서 crowd_stats
|
||||
* 원자적 증분 + PII 보호). 경기당 1건(matchId 기준 upsert).
|
||||
* ============================================================ */
|
||||
export async function saveMyPrediction(email: string, rec: MyPrediction): Promise<void> {
|
||||
if (!email) return;
|
||||
const key = normEmail(email);
|
||||
const store = readStore();
|
||||
const list = store[key] ?? [];
|
||||
const next = list.filter((p) => p.matchId !== rec.matchId); // 같은 경기는 최신 픽으로 교체
|
||||
next.push(rec);
|
||||
store[key] = next;
|
||||
writeStore(store);
|
||||
}
|
||||
|
||||
/** 마지막 사용 이메일 기억 (재방문 시 자동 복원 — 로그인 대체) */
|
||||
export function rememberEmail(email: string) {
|
||||
if (typeof window === "undefined" || !email) return;
|
||||
window.localStorage.setItem(EMAIL_KEY, normEmail(email));
|
||||
}
|
||||
|
||||
/** 기억된 이메일 불러오기 (없으면 "") */
|
||||
export function recallEmail(): string {
|
||||
if (typeof window === "undefined") return "";
|
||||
return window.localStorage.getItem(EMAIL_KEY) || "";
|
||||
}
|
||||
Reference in new issue
Block a user