댓글 닉네임 새로고침 버튼 추가

develop
jwkim 2026-06-17 15:38:20 +09:00
parent b62bedc665
commit bac505fa99
3 changed files with 36 additions and 1 deletions

View File

@ -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({
{/* 입력 */}
<div className="mt-3 space-y-2">
{nickname && (
<p className="text-[12px] font-bold text-white/45">
<p className="flex items-center gap-1.5 text-[12px] font-bold text-white/45">
{t.commentAs}{" "}
<span className="text-[var(--green)]">{nickname}</span>
<button
type="button"
onClick={reroll}
title={t.commentReroll}
aria-label={t.commentReroll}
className="grid h-5 w-5 place-items-center rounded-full text-[13px] leading-none text-white/45 transition hover:text-white active:rotate-180"
>
</button>
</p>
)}
<div className="flex items-end gap-2">

View File

@ -115,6 +115,19 @@ export async function getSessionNickname(matchId: string): Promise<string> {
return nickname;
}
// 닉네임 새로 뽑기 — 서버에서 새 닉 받아 세션 캐시 갱신
export async function rerollSessionNickname(matchId: string): Promise<string> {
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`, {

View File

@ -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<Lang, Dict> = {
commentsCount: (n) => `${n}`,
commentPh: "응원 한마디 남기기...",
commentAs: "이번 닉네임",
commentReroll: "닉네임 새로 뽑기",
commentSubmit: "등록",
commentMore: "댓글 더보기",
commentCollapse: "접기",
@ -265,6 +267,7 @@ export const DICT: Record<Lang, Dict> = {
commentsCount: (n) => `${n} total`,
commentPh: "Leave a comment...",
commentAs: "Your name",
commentReroll: "Get a new name",
commentSubmit: "Post",
commentMore: "Show more",
commentCollapse: "Collapse",