설정을 팝업으로: 방 안에서 설정을 열어도 방에서 나가지 않게 방 막대·헤더 계정 메뉴의 ⚙️ 설정을 화면 설정 팝업으로(설정 페이지와 같은 화면 설정 공용, 헤더 팝업에는 내 계정·기록 링크), e2e/settings.e2e.ts

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-14 04:15:08 +09:00
parent 73b929739d
commit 18f0530237
9 changed files with 254 additions and 49 deletions

View 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>
);
}

View File

@@ -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="로그아웃할까요?"