설정을 팝업으로: 방 안에서 설정을 열어도 방에서 나가지 않게 방 막대·헤더 계정 메뉴의 ⚙️ 설정을 화면 설정 팝업으로(설정 페이지와 같은 화면 설정 공용, 헤더 팝업에는 내 계정·기록 링크), e2e/settings.e2e.ts
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
67
apps/web/src/components/SettingsPopup.tsx
Normal file
67
apps/web/src/components/SettingsPopup.tsx
Normal file
@@ -0,0 +1,67 @@
|
||||
/** 화면 설정 (font size, colours, sound, vibration, tap-to-place), shared by the 설정 page and the 설정 popup. */
|
||||
import { Link } from 'react-router';
|
||||
import { useSession } from '../store/session';
|
||||
import { Sheet } from './ui';
|
||||
|
||||
function Seg<T extends string>({ value, options, onChange, label }: { value: T; options: [T, string][]; onChange: (v: T) => void; label: string }) {
|
||||
return (
|
||||
<div className="setting-row">
|
||||
<strong>{label}</strong>
|
||||
<div className="segmented" role="group" aria-label={label}>
|
||||
{options.map(([k, l]) => (
|
||||
<button key={k} type="button" aria-pressed={value === k} onClick={() => onChange(k)}>
|
||||
{l}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** The setting rows only; the caller adds the heading and the box. Changes apply and save at once. */
|
||||
export function DisplaySettings() {
|
||||
const settings = useSession((s) => s.settings);
|
||||
const updateSettings = useSession((s) => s.updateSettings);
|
||||
return (
|
||||
<>
|
||||
<Seg label="글자 크기" value={settings.fontScale} options={[['normal', '보통'], ['large', '크게'], ['xlarge', '아주 크게']]} onChange={(fontScale) => updateSettings({ fontScale })} />
|
||||
<Seg label="화면 색" value={settings.theme} options={[['auto', '자동'], ['light', '밝게'], ['dark', '어둡게']]} onChange={(theme) => updateSettings({ theme })} />
|
||||
<Seg label="소리" value={settings.sound ? 'on' : 'off'} options={[['on', '켜기'], ['off', '끄기']]} onChange={(v) => updateSettings({ sound: v === 'on' })} />
|
||||
<label className="stack" style={{ gap: 4 }}>
|
||||
<span style={{ fontWeight: 700 }}>
|
||||
소리 크기 <span className="muted">{settings.volume} (기본 50, 이 기기에만 저장)</span>
|
||||
</span>
|
||||
<input type="range" min={0} max={100} step={5} value={settings.volume} aria-label="소리 크기 (0~100)" style={{ accentColor: 'var(--primary)' }} onChange={(e) => updateSettings({ volume: Number(e.target.value) })} />
|
||||
</label>
|
||||
<Seg label="진동" value={settings.vibrate ? 'on' : 'off'} options={[['on', '켜기'], ['off', '끄기']]} onChange={(v) => updateSettings({ vibrate: v === 'on' })} />
|
||||
<Seg
|
||||
label="돌·카드 놓기"
|
||||
value={settings.tapConfirm ? 'on' : 'off'}
|
||||
options={[['on', '두 번 눌러 놓기'], ['off', '한 번에 놓기']]}
|
||||
onChange={(v) => updateSettings({ tapConfirm: v === 'on' })}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 설정 팝업: opens over the current page so a room stays open underneath (no navigation, no leave).
|
||||
* `account` adds a link to the full 설정 page (nickname, records, logout); rooms leave it out because following it leaves the room.
|
||||
* Pass a stable `onClose`: Sheet re-focuses itself whenever it changes.
|
||||
*/
|
||||
export function SettingsPopup({ onClose, account }: { onClose: () => void; account?: boolean }) {
|
||||
return (
|
||||
<Sheet onClose={onClose} label="설정">
|
||||
<h2>화면 설정</h2>
|
||||
<DisplaySettings />
|
||||
{account && (
|
||||
<Link className="btn btn-soft btn-block" to="/me" onClick={onClose}>
|
||||
👤 내 계정 · 기록 보기
|
||||
</Link>
|
||||
)}
|
||||
<button type="button" className="btn btn-secondary btn-block" onClick={onClose}>
|
||||
닫기
|
||||
</button>
|
||||
</Sheet>
|
||||
);
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
/** PC top menu (docs/07-ui-ux.md §3.2): 로고·메뉴, 오른쪽에 소리 크기·테마 버튼과 로그인/계정 메뉴. */
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { Link, NavLink, useNavigate } from 'react-router';
|
||||
import { api } from '../net/api';
|
||||
import { useSession } from '../store/session';
|
||||
import { Avatar, ConfirmSheet } from './ui';
|
||||
import { VolumeControl } from './VolumeControl';
|
||||
import { SettingsPopup } from './SettingsPopup';
|
||||
|
||||
export function SiteHeader() {
|
||||
const { me, siteName, role } = useSession();
|
||||
@@ -60,14 +61,17 @@ function ThemeToggle() {
|
||||
);
|
||||
}
|
||||
|
||||
/** 로그인한 뒤: 닉네임(디스코드 연결 시 디스코드 이름) → 누르면 [설정] ([관리자 메뉴]) [로그아웃] 메뉴. */
|
||||
/** 로그인한 뒤: 닉네임(디스코드 연결 시 디스코드 이름) → 누르면 [설정](팝업) ([관리자 메뉴]) [로그아웃] 메뉴. */
|
||||
function AccountMenu() {
|
||||
const me = useSession((s) => s.me)!;
|
||||
const role = useSession((s) => s.role);
|
||||
const nav = useNavigate();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [confirm, setConfirm] = useState(false);
|
||||
const [settings, setSettings] = useState(false);
|
||||
const closeSettings = useCallback(() => setSettings(false), []);
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
const btn = useRef<HTMLButtonElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
@@ -83,7 +87,7 @@ function AccountMenu() {
|
||||
|
||||
return (
|
||||
<div className="account-menu" ref={ref}>
|
||||
<button type="button" className="header-user" aria-haspopup="menu" aria-expanded={open} aria-label={`내 계정: ${me.nickname}`} onClick={() => setOpen((o) => !o)}>
|
||||
<button type="button" ref={btn} className="header-user" aria-haspopup="menu" aria-expanded={open} aria-label={`내 계정: ${me.nickname}`} onClick={() => setOpen((o) => !o)}>
|
||||
<Avatar user={me} size={36} />
|
||||
<span className="header-user-name">{me.nickname}</span>
|
||||
<span aria-hidden className="small muted">
|
||||
@@ -92,7 +96,8 @@ function AccountMenu() {
|
||||
</button>
|
||||
{open && (
|
||||
<div className="account-menu-list" role="menu" aria-label="내 계정">
|
||||
<button type="button" role="menuitem" onClick={() => (setOpen(false), nav('/me'))}>
|
||||
{/* A popup, not a page. The menu item is about to go away, so focus the account button first: the popup returns focus there. */}
|
||||
<button type="button" role="menuitem" aria-haspopup="dialog" onClick={() => (btn.current?.focus(), setOpen(false), setSettings(true))}>
|
||||
⚙️ 설정
|
||||
</button>
|
||||
{role !== 'user' && (
|
||||
@@ -105,6 +110,7 @@ function AccountMenu() {
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{settings && <SettingsPopup onClose={closeSettings} account />}
|
||||
{confirm && (
|
||||
<ConfirmSheet
|
||||
title="로그아웃할까요?"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* 로그인 페이지: 큰 [디스코드로 로그인] + 아래 [게스트로 시작하기].
|
||||
* 게스트를 고르면 /login/guest에서 계정 이름(닉네임)을 정한다. 설정은 로그인 뒤 헤더 계정 메뉴 → 설정(/me).
|
||||
* 게스트를 고르면 /login/guest에서 계정 이름(닉네임)을 정한다. 설정은 로그인 뒤 헤더 계정 메뉴 → 설정(팝업, 계정·기록은 /me).
|
||||
*/
|
||||
import { Link, Navigate, useMatch, useNavigate, useSearchParams } from 'react-router';
|
||||
import { TopBar } from '../components/ui';
|
||||
|
||||
@@ -1,33 +1,19 @@
|
||||
/** 설정(계정) 페이지 (docs/05 §7). 헤더 계정 메뉴 → 설정으로 들어와요. */
|
||||
/** 설정(계정) 페이지 (docs/05 §7). 헤더 계정 메뉴 → 설정 팝업 → [내 계정 · 기록 보기]로 들어와요. */
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Link, Navigate, useNavigate } from 'react-router';
|
||||
import { catalogById, nicknameError, normalizeNickname, type MyGameSummary } from '@bg/shared/lite';
|
||||
import { Avatar, ConfirmSheet, TopBar } from '../components/ui';
|
||||
import { GuestWarning } from '../components/NicknameForm';
|
||||
import { DisplaySettings } from '../components/SettingsPopup';
|
||||
import { resultLabel } from '../components/PlayerCard';
|
||||
import { gameName } from '../components/GameNotice';
|
||||
import { api, discordLoginUrl } from '../net/api';
|
||||
import { useSession } from '../store/session';
|
||||
import { toast } from '../store/toast';
|
||||
|
||||
function Seg<T extends string>({ value, options, onChange, label }: { value: T; options: [T, string][]; onChange: (v: T) => void; label: string }) {
|
||||
return (
|
||||
<div className="setting-row">
|
||||
<strong>{label}</strong>
|
||||
<div className="segmented" role="group" aria-label={label}>
|
||||
{options.map(([k, l]) => (
|
||||
<button key={k} type="button" aria-pressed={value === k} onClick={() => onChange(k)}>
|
||||
{l}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function MePage() {
|
||||
const nav = useNavigate();
|
||||
const { me, settings, discordEnabled, useAvatar, hasDiscordAvatar, updateSettings, role } = useSession();
|
||||
const { me, discordEnabled, useAvatar, hasDiscordAvatar, role } = useSession();
|
||||
const [editing, setEditing] = useState(false);
|
||||
const [nick, setNick] = useState(me?.nickname ?? '');
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
@@ -52,28 +38,6 @@ export default function MePage() {
|
||||
}
|
||||
};
|
||||
|
||||
const display = (
|
||||
<section className="card stack">
|
||||
<h2>화면 설정</h2>
|
||||
<Seg label="글자 크기" value={settings.fontScale} options={[['normal', '보통'], ['large', '크게'], ['xlarge', '아주 크게']]} onChange={(fontScale) => updateSettings({ fontScale })} />
|
||||
<Seg label="화면 색" value={settings.theme} options={[['auto', '자동'], ['light', '밝게'], ['dark', '어둡게']]} onChange={(theme) => updateSettings({ theme })} />
|
||||
<Seg label="소리" value={settings.sound ? 'on' : 'off'} options={[['on', '켜기'], ['off', '끄기']]} onChange={(v) => updateSettings({ sound: v === 'on' })} />
|
||||
<label className="stack" style={{ gap: 4 }}>
|
||||
<span style={{ fontWeight: 700 }}>
|
||||
소리 크기 <span className="muted">{settings.volume} (기본 50, 이 기기에만 저장)</span>
|
||||
</span>
|
||||
<input type="range" min={0} max={100} step={5} value={settings.volume} aria-label="소리 크기 (0~100)" style={{ accentColor: 'var(--primary)' }} onChange={(e) => updateSettings({ volume: Number(e.target.value) })} />
|
||||
</label>
|
||||
<Seg label="진동" value={settings.vibrate ? 'on' : 'off'} options={[['on', '켜기'], ['off', '끄기']]} onChange={(v) => updateSettings({ vibrate: v === 'on' })} />
|
||||
<Seg
|
||||
label="돌·카드 놓기"
|
||||
value={settings.tapConfirm ? 'on' : 'off'}
|
||||
options={[['on', '두 번 눌러 놓기'], ['off', '한 번에 놓기']]}
|
||||
onChange={(v) => updateSettings({ tapConfirm: v === 'on' })}
|
||||
/>
|
||||
</section>
|
||||
);
|
||||
|
||||
// 로그인 안 했으면 로그인 페이지로 (로그인 페이지에는 로그인만 있어요).
|
||||
if (!me) return <Navigate to="/login?next=/me" replace />;
|
||||
|
||||
@@ -149,7 +113,10 @@ export default function MePage() {
|
||||
</div>
|
||||
|
||||
<div className="me-main">
|
||||
{display}
|
||||
<section className="card stack">
|
||||
<h2>화면 설정</h2>
|
||||
<DisplaySettings />
|
||||
</section>
|
||||
|
||||
<section className="card stack">
|
||||
<h2>내 기록</h2>
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
/** 방: 대기실 ↔ 게임 ↔ 결과를 한 주소에서 전환 (docs/06 §5–§9). */
|
||||
import { useEffect, useLayoutEffect, useMemo, useRef, useState, type ReactNode } from 'react';
|
||||
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, type ReactNode } from 'react';
|
||||
import { Link, useNavigate, useParams } from 'react-router';
|
||||
import { BOT_BANDS, BOT_PICKS, BOT_PICK_LABEL, bandOf, botChatRequired, botsAllowed, formatRoomCode, isBotId, luckLabel, type PublicUser, type RoomView } from '@bg/shared/lite';
|
||||
import { Avatar, CodeLabel, ConfirmSheet, CopyButton, ShareButton, Sheet, TopBar } from '../components/ui';
|
||||
import { GuestWarning, NicknameForm } from '../components/NicknameForm';
|
||||
import { GameNotice, gameName } from '../components/GameNotice';
|
||||
import { QrModal } from '../components/QrModal';
|
||||
import { SettingsPopup } from '../components/SettingsPopup';
|
||||
import { api, type RoomPreview } from '../net/api';
|
||||
import { socket, useRoom } from '../net/socket';
|
||||
import { useSession } from '../store/session';
|
||||
@@ -94,6 +95,9 @@ function Room({ code, me }: { code: string; me: PublicUser }) {
|
||||
const [ui, setUi] = useState<GameUI | null>(null);
|
||||
const [leaveAsk, setLeaveAsk] = useState(false);
|
||||
const [chatOpen, setChatOpen] = useState(false);
|
||||
// 설정 opens as a popup over the room: going to /me would unmount the room and detach from it.
|
||||
const [settingsOpen, setSettingsOpen] = useState(false);
|
||||
const closeSettings = useCallback(() => setSettingsOpen(false), []);
|
||||
// [한 판 더] takes me back to this room's lobby after game N (kept per tab so a reload stays there).
|
||||
const lobbyKey = `bg:lobby:${code}`;
|
||||
const [lobbyAfter, setLobbyAfter] = useState<number | null>(() => Number(sessionStorage.getItem(lobbyKey)) || null);
|
||||
@@ -217,7 +221,7 @@ function Room({ code, me }: { code: string; me: PublicUser }) {
|
||||
<span className="rb-ico">📖</span>
|
||||
<span className="rb-lbl">규칙</span>
|
||||
</button>
|
||||
<button className="btn btn-ghost btn-sm rb-btn" onClick={() => nav('/me')} aria-label="글자 크기 · 소리 설정">
|
||||
<button className="btn btn-ghost btn-sm rb-btn" onClick={() => setSettingsOpen(true)} aria-haspopup="dialog" aria-label="글자 크기 · 소리 설정">
|
||||
<span className="rb-ico">⚙️</span>
|
||||
<span className="rb-lbl">설정</span>
|
||||
</button>
|
||||
@@ -242,6 +246,7 @@ function Room({ code, me }: { code: string; me: PublicUser }) {
|
||||
</button>
|
||||
</Sheet>
|
||||
)}
|
||||
{settingsOpen && <SettingsPopup onClose={closeSettings} />}
|
||||
{leaveAsk && (
|
||||
<ConfirmSheet
|
||||
title="방에서 나갈까요?"
|
||||
|
||||
Reference in New Issue
Block a user