방: 나가기 버튼을 막대로 빼고 ← 홈도 나가기로, 이름 눌러 기록 카드, 게스트 경고, 관리자 계정별 기록

- 방 막대에 [🚪 나가기]를 두고 메뉴에서는 뺀다. [← 홈]도 같은 동작. 한 번 누르면 바로 나가고,
  게임 중에 자리에 앉아 있을 때만 기권 확인을 묻는다. 휴대폰은 방 링크 복사를 메뉴로 옮겨 한 줄에 맞춘다.
- 자리·관전자·결과 화면의 이름을 누르면 기록 카드(이 게임 판·승·패·무·승률, 이 방 전적, 전체 합계).
  GET /api/users/:id/stats (로그인 필요).
- 게스트 경고: 이름 정하기, 로그인 페이지, /me, 게스트가 있는 대기실.
- 관리자 사용자 상세: 전체 기록, 게임별 기록 표, 최근 게임(GET /api/admin/users/:id/games). 목록에 전적 열(PC).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-08 11:34:08 +09:00
parent f93ff4f656
commit 43156a9f63
17 changed files with 462 additions and 39 deletions

View File

@@ -3,7 +3,7 @@ import { useEffect, useMemo, useRef, useState } from 'react';
import { Link, useNavigate, useParams } from 'react-router';
import { botsAllowed, formatRoomCode, isBotId, type PublicUser, type RoomView } from '@bg/shared/lite';
import { Avatar, CodeLabel, ConfirmSheet, CopyButton, ShareButton, Sheet, TopBar } from '../components/ui';
import { NicknameForm } from '../components/NicknameForm';
import { GuestWarning, NicknameForm } from '../components/NicknameForm';
import { GameNotice, gameName } from '../components/GameNotice';
import { QrModal } from '../components/QrModal';
import { api, type RoomPreview } from '../net/api';
@@ -15,6 +15,7 @@ import { sounds } from '../lib/feedback';
import { ChatPanel, EmoteBubbles, useChatSeen } from '../components/ChatPanel';
import { useWide } from '../lib/media';
import { GameHelp } from '../components/GameHelp';
import { PlayerName } from '../components/PlayerCard';
export default function RoomPage() {
const { code = '' } = useParams();
@@ -146,6 +147,9 @@ function Room({ code, me }: { code: string; me: PublicUser }) {
socket.leave();
nav('/');
};
// Leaving mid-game forfeits, so only that case asks first; otherwise one tap leaves.
const forfeits = room.status === 'playing' && room.seats.some((s) => s?.user.id === me.id);
const askLeave = () => (forfeits ? setLeaveAsk(true) : doLeave());
return (
<>
@@ -154,13 +158,17 @@ function Room({ code, me }: { code: string; me: PublicUser }) {
{g.nameKo} 방 {formatRoomCode(code)}
</h1>
<div className="room-bar-inner">
<button className="btn btn-ghost btn-sm" onClick={() => nav('/')} aria-label="홈으로">
{/* ← 홈 leaves the room, same as [나가기]. */}
<button className="btn btn-ghost btn-sm" onClick={askLeave} aria-label="방 나가고 홈으로">
← 홈
</button>
<strong className="rb-game" style={{ fontSize: '1.1rem' }}>
{g.nameKo}
</strong>
<CopyButton text={`${location.origin}/r/${code}`} label={<>방 <CodeLabel code={code} /> 🔗</>} done="링크 복사됨 ✓" className="btn btn-ghost btn-sm" />
{/* On phones the link sits in the menu so ← 홈 · 채팅 · 🚪 나가기 · 메뉴 fit on one line. */}
<span className="wide-only">
<CopyButton text={`${location.origin}/r/${code}`} label={<>방 <CodeLabel code={code} /> 🔗</>} done="링크 복사됨 ✓" className="btn btn-ghost btn-sm" />
</span>
<span style={{ flex: 1 }} />
{!roomChatClosed && (
<span className="phone-only">
@@ -170,6 +178,9 @@ function Room({ code, me }: { code: string; me: PublicUser }) {
<button className="btn btn-ghost btn-sm wide-only" onClick={() => nav(`/rules/${room.gameId}`)}>
📖 규칙
</button>
<button className="btn btn-danger btn-sm" onClick={askLeave}>
🚪 나가기
</button>
<button className="btn btn-secondary btn-sm" onClick={() => setMenu(true)} aria-label="메뉴">
⋯ 메뉴
</button>
@@ -201,6 +212,9 @@ function Room({ code, me }: { code: string; me: PublicUser }) {
{menu && (
<Sheet onClose={() => setMenu(false)} label="메뉴">
<h2>메뉴</h2>
<span className="phone-only">
<CopyButton text={`${location.origin}/r/${code}`} label={<>🔗 방 <CodeLabel code={code} /> 링크 복사</>} done="링크 복사됨 ✓" className="btn btn-secondary btn-block" />
</span>
<button className="btn btn-secondary btn-block" onClick={() => nav(`/rules/${room.gameId}`)}>
📖 규칙 보기
</button>
@@ -212,15 +226,12 @@ function Room({ code, me }: { code: string; me: PublicUser }) {
게임 끝내기(무효)
</button>
)}
<button className="btn btn-danger btn-block" onClick={() => (setMenu(false), setLeaveAsk(true))}>
🚪 방 나가기
</button>
</Sheet>
)}
{leaveAsk && (
<ConfirmSheet
title="방에서 나갈까요?"
body={room.status === 'playing' && room.seats.some((s) => s?.user.id === me.id) ? '게임 중에 나가면 기권으로 처리돼요.' : undefined}
body="게임 중에 나가면 기권으로 처리돼요."
confirm="나가기"
danger
onConfirm={doLeave}
@@ -322,7 +333,7 @@ function Lobby({ room, ui, me }: { room: RoomView; ui: GameUI; me: PublicUser })
<div style={{ flex: 1, minWidth: 0 }}>
<div style={{ fontWeight: 700, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
{room.hostId === s.user.id && <span aria-label="방장">👑 </span>}
{s.user.nickname}
<PlayerName user={s.user} gameId={room.gameId} session={room.sessionStats[s.user.id]} />
{s.user.id === me.id && <span className="muted small"> (나)</span>}
</div>
<div className="row small" style={{ gap: 6 }}>
@@ -347,7 +358,17 @@ function Lobby({ room, ui, me }: { room: RoomView; ui: GameUI; me: PublicUser })
),
)}
</div>
{room.spectators.length > 0 && <p className="muted small">관전 {room.spectators.length}명: {room.spectators.map((u) => u.nickname).join(', ')}</p>}
{room.spectators.length > 0 && (
<p className="muted small">
관전 {room.spectators.length}명:{' '}
{room.spectators.map((u, i) => (
<span key={u.id}>
{i > 0 && ', '}
<PlayerName user={u} gameId={room.gameId} />
</span>
))}
</p>
)}
{mySeat >= 0 && room.allowSpectators && (
<button className="btn btn-ghost" style={{ alignSelf: 'flex-start' }} onClick={() => socket.send({ t: 'unseat' })}>
관전으로 바꾸기
@@ -370,6 +391,7 @@ function Lobby({ room, ui, me }: { room: RoomView; ui: GameUI; me: PublicUser })
</div>
<p className="muted small">{room.visibility === 'public' ? '공개 방 (누구나 들어올 수 있어요)' : '친구만 (코드·링크로만 들어와요)'}</p>
{practice && <p className="small">🤖 연습 게임이에요. 기록에는 남지 않아요.</p>}
{me.kind === 'guest' && !practice && <GuestWarning />}
{room.lockedOptions.length > 0 && <p className="muted small">🔒 일부 규칙은 관리자가 정해 두어서 바꿀 수 없어요.</p>}
<GameNotice gameId={room.gameId} />
{isHost && wide && <SettingsForm room={room} ui={ui} inline />}
@@ -643,7 +665,7 @@ function ResultPanel({ room, me, players, onLeave }: { room: RoomView; me: Publi
<div key={u} className="row">
<strong style={{ width: 40 }}>{i + 1}등</strong>
{players[u] && <Avatar user={players[u]!} size={28} />}
<span>{players[u]?.nickname ?? '나간 사람'}</span>
<span style={{ minWidth: 0 }}>{players[u] ? <PlayerName user={players[u]!} gameId={room.gameId} session={room.sessionStats[u]} /> : '나간 사람'}</span>
<span className="muted small" style={{ marginLeft: 'auto' }}>
이 방에서 {room.sessionStats[u]?.wins ?? 0}승 / {room.sessionStats[u]?.played ?? 0}판
</span>