diff --git a/frontend/src/components/Comments.tsx b/frontend/src/components/Comments.tsx index e624741..fb1b40f 100644 --- a/frontend/src/components/Comments.tsx +++ b/frontend/src/components/Comments.tsx @@ -5,6 +5,7 @@ import { listComments, postComment, getSessionNickname, + rerollSessionNickname, getDeviceId, ApiError, } from "@/lib/api"; @@ -81,6 +82,15 @@ export default function Comments({ } } + async function reroll() { + try { + const n = await rerollSessionNickname(matchId); + setNickname(n); + } catch { + /* 무시 */ + } + } + async function submit() { const text = body.trim(); if (posting || !text) return; @@ -118,9 +128,18 @@ export default function Comments({ {/* 입력 */}
{nickname && ( -

+

⚽ {t.commentAs}{" "} {nickname} +

)}
diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts index b72b2ac..dad01d8 100644 --- a/frontend/src/lib/api.ts +++ b/frontend/src/lib/api.ts @@ -115,6 +115,19 @@ export async function getSessionNickname(matchId: string): Promise { return nickname; } +// 닉네임 새로 뽑기 — 서버에서 새 닉 받아 세션 캐시 갱신 +export async function rerollSessionNickname(matchId: string): Promise { + const { nickname } = await http<{ nickname: string }>( + `/matches/${matchId}/comments/nickname`, + ); + try { + sessionStorage.setItem(SESSION_NICK_KEY, nickname); + } catch { + /* noop */ + } + return nickname; +} + // 방문 기록 (하루 1기기 1회 집계). 실패는 무시(fire-and-forget). export function recordVisit(): void { void http(`/visit`, { diff --git a/frontend/src/lib/i18n.ts b/frontend/src/lib/i18n.ts index e0296b1..571bd99 100644 --- a/frontend/src/lib/i18n.ts +++ b/frontend/src/lib/i18n.ts @@ -103,6 +103,7 @@ type Dict = { commentsCount: (n: number) => string; commentPh: string; commentAs: string; + commentReroll: string; commentSubmit: string; commentMore: string; commentCollapse: string; @@ -185,6 +186,7 @@ export const DICT: Record = { commentsCount: (n) => `총 ${n}개`, commentPh: "응원 한마디 남기기...", commentAs: "이번 닉네임", + commentReroll: "닉네임 새로 뽑기", commentSubmit: "등록", commentMore: "댓글 더보기", commentCollapse: "접기", @@ -265,6 +267,7 @@ export const DICT: Record = { commentsCount: (n) => `${n} total`, commentPh: "Leave a comment...", commentAs: "Your name", + commentReroll: "Get a new name", commentSubmit: "Post", commentMore: "Show more", commentCollapse: "Collapse",