v1.6.0: 사이트 '내 정보'(표시 이름 · 색 · 라이엇 ID · 녹음 제외) · 관리 페이지
- 사이트 오른쪽 위 내 이름 → 내 정보: 표시 이름 바꾸기/되돌리기, 색, 라이엇 ID, 녹음 제외, 로그아웃 - 관리 페이지 /admin (관리자): 게임 PC 상태 · 앱 새 버전 안내, 유저별 표시 이름 · 색 · 라이엇 ID · 녹음 제외, 앱 등록 · 역할 · 해제(최고 관리자). /site/admin/* 는 /app/admin/* 와 같은 처리 - 서버: 표시 이름 검사(길이 · 보이지 않는 글자 · 다른 사람과 겹침), 지우면 디스코드 이름으로 되돌림, 바뀌면 게임 PC 앱에 바로 보냄 (PUT /api/internal/names) - 앱: PATCH /api/users/:id (본인 또는 관리자, 남의 라이엇 ID 는 관리자만), PUT /api/internal/names - 테스트: 앱 user-settings 3개, 사이트 서버 profile-admin 3개 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,7 +6,8 @@ import { settings, useSettings, type SfxKind } from '../store/settings';
|
||||
import { sfx, SFX_LABEL } from '../lib/sfx';
|
||||
import { resumeAudio } from '../lib/audio';
|
||||
import { Avatar, Brand } from './common';
|
||||
import { IGear, ILogout, ISearch } from './Icons';
|
||||
import { IGear, ISearch } from './Icons';
|
||||
import { ProfilePopover } from './UserEdit';
|
||||
import { GAME_NAME, liveGameLine, liveGameRows } from '@gvr/shared';
|
||||
|
||||
function SettingsPopover({ onClose }: { onClose: () => void }) {
|
||||
@@ -165,10 +166,11 @@ export function SearchBox() {
|
||||
}
|
||||
|
||||
export function Header() {
|
||||
const { auth, logout } = useAuth();
|
||||
const { overview } = useData();
|
||||
const { auth } = useAuth();
|
||||
const { overview, userById } = useData();
|
||||
const { device, locked, conn } = useStatus();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [profile, setProfile] = useState(false);
|
||||
const me = auth.status === 'ok' ? auth.me.user : null;
|
||||
const rec = overview?.recording;
|
||||
const nav = [
|
||||
@@ -178,6 +180,7 @@ export function Header() {
|
||||
['/users', '유저'],
|
||||
['/dictionary', '단어사전'],
|
||||
['/culprit', '🔍 범인찾기'],
|
||||
...(auth.status === 'ok' && auth.me.canViewLogs ? ([['/admin', '🛡️ 관리']] as const) : []),
|
||||
] as const;
|
||||
return (
|
||||
<header className="topbar">
|
||||
@@ -211,14 +214,13 @@ export function Header() {
|
||||
</button>
|
||||
<AnimatePresence>{open && <SettingsPopover onClose={() => setOpen(false)} />}</AnimatePresence>
|
||||
{me && (
|
||||
<div className="me">
|
||||
<Avatar name={me.name} src={me.avatar} color="#5865f2" size={26} />
|
||||
<button className="me me-btn" onClick={() => setProfile((o) => !o)} aria-expanded={profile} title="내 정보 · 표시 이름 · 색 · 로그아웃">
|
||||
<Avatar name={me.name} src={me.avatar} color={userById(me.id)?.color ?? '#5865f2'} size={26} />
|
||||
<span className="me-nm">{me.name}</span>
|
||||
<button className="icon-btn" onClick={logout} title="로그아웃" aria-label="로그아웃">
|
||||
<ILogout width={16} height={16} />
|
||||
</button>
|
||||
</div>
|
||||
<span className="me-caret">▾</span>
|
||||
</button>
|
||||
)}
|
||||
<AnimatePresence>{profile && <ProfilePopover onClose={() => setProfile(false)} />}</AnimatePresence>
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
|
||||
234
site/web/src/components/UserEdit.tsx
Normal file
234
site/web/src/components/UserEdit.tsx
Normal file
@@ -0,0 +1,234 @@
|
||||
// 유저 설정 고치기 (v1.6.0): 머리글 "내 정보" 와 관리 화면이 같이 쓴다
|
||||
// - 표시 이름: 사이트 서버에 저장 (디스코드 이름 대신 보일 이름, 게임 PC 앱에 바로 전달)
|
||||
// - 색 · 녹음 제외 · 라이엇 ID: 게임 PC 앱 기록에 저장 (앱 v1.6.0~)
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { Link } from 'react-router';
|
||||
import { motion } from 'framer-motion';
|
||||
import type { User } from '@gvr/shared';
|
||||
import { api, ApiError } from '../lib/api';
|
||||
import { sfx } from '../lib/sfx';
|
||||
import { useAuth, useData } from '../store/app';
|
||||
import { Avatar } from './common';
|
||||
import { ILogout } from './Icons';
|
||||
|
||||
/** 타임라인에서 잘 보이는 색들 (어두운 배경) */
|
||||
export const USER_COLORS = ['#ff4655', '#ff8a3d', '#f2b23a', '#c8e04a', '#45d39a', '#14c1b7', '#3db8ff', '#5b8cff', '#9a7bff', '#d46bff', '#ff6fb1', '#c9d1dc'];
|
||||
|
||||
/** 오류를 사람이 읽을 말로 */
|
||||
export function errText(e: unknown): string {
|
||||
if (e instanceof ApiError) {
|
||||
if (e.status === 404 && e.code === 'Not Found') return '게임 PC 앱이 아직 이 기능을 모릅니다. 앱을 v1.6.0 이상으로 업데이트해 주세요';
|
||||
if (e.status === 503 && e.code === 'device_offline') return '게임 PC 가 꺼져 있어 저장하지 못했습니다';
|
||||
if (e.status === 504) return '게임 PC 가 답하지 않습니다. 잠시 뒤 다시 해 주세요';
|
||||
if (e.detail) return e.detail;
|
||||
if (e.status === 0) return '서버에 연결하지 못했습니다';
|
||||
return `저장하지 못했습니다 (${e.status} ${e.code})`;
|
||||
}
|
||||
return e instanceof Error ? e.message : String(e);
|
||||
}
|
||||
|
||||
/** 표시 이름 입력: 저장 · 디스코드 이름으로 되돌리기 */
|
||||
export function NameEditor({ value, custom, onSave, placeholder }: { value: string; custom: boolean; onSave: (name: string) => Promise<void>; placeholder?: string }) {
|
||||
const [v, setV] = useState(value);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [msg, setMsg] = useState<{ ok: boolean; text: string } | null>(null);
|
||||
useEffect(() => setV(value), [value]);
|
||||
const save = async (name: string) => {
|
||||
setBusy(true);
|
||||
setMsg(null);
|
||||
try {
|
||||
await onSave(name);
|
||||
setMsg({ ok: true, text: name ? '저장했습니다' : '디스코드 이름으로 되돌렸습니다' });
|
||||
sfx('click');
|
||||
} catch (e) {
|
||||
setMsg({ ok: false, text: errText(e) });
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
return (
|
||||
<div className="ue-block">
|
||||
<form
|
||||
className="ue-row"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
if (v.trim() && v.trim() !== value) void save(v.trim());
|
||||
}}
|
||||
>
|
||||
<input className="ue-input" value={v} maxLength={32} placeholder={placeholder ?? '표시 이름'} onChange={(e) => setV(e.target.value)} aria-label="표시 이름" />
|
||||
<button className="btn sm primary" disabled={busy || !v.trim() || v.trim() === value}>
|
||||
저장
|
||||
</button>
|
||||
{custom && (
|
||||
<button type="button" className="btn sm" disabled={busy} onClick={() => void save('')} title="표시 이름을 지우고 디스코드 서버 별명으로 보이게">
|
||||
되돌리기
|
||||
</button>
|
||||
)}
|
||||
</form>
|
||||
{msg && <div className={`ue-msg${msg.ok ? ' ok' : ' bad'}`}>{msg.text}</div>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** 색 · 녹음 제외 · 라이엇 ID (게임 PC 앱에 저장) */
|
||||
export function AppUserEditor({ user, self }: { user: User; self: boolean }) {
|
||||
const { reloadUsers } = useData();
|
||||
const [riot, setRiot] = useState(user.riot.map((r) => r.riotId).join(', '));
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [msg, setMsg] = useState<{ ok: boolean; text: string } | null>(null);
|
||||
const riotNow = user.riot.map((r) => r.riotId).join(', ');
|
||||
useEffect(() => setRiot(riotNow), [riotNow]);
|
||||
const colorRef = useRef<HTMLInputElement>(null);
|
||||
const patch = async (p: { color?: string; excluded?: boolean; riotIds?: string[] }, okText: string) => {
|
||||
setBusy(true);
|
||||
setMsg(null);
|
||||
try {
|
||||
const r = await api.updateUser(user.id, p);
|
||||
reloadUsers();
|
||||
setMsg(r.taken.length ? { ok: false, text: `다른 사람에게 연결된 라이엇 ID 는 빼고 저장했습니다: ${r.taken.join(', ')}` } : { ok: true, text: okText });
|
||||
sfx('click');
|
||||
} catch (e) {
|
||||
setMsg({ ok: false, text: errText(e) });
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
const riotIds = riot
|
||||
.split(/[,\n]/)
|
||||
.map((x) => x.trim())
|
||||
.filter(Boolean);
|
||||
const riotBad = riotIds.filter((r) => !/^[^#]{1,32}#[^#]{1,8}$/.test(r));
|
||||
return (
|
||||
<div className="ue-block">
|
||||
<div className="ue-label">색</div>
|
||||
<div className="ue-colors" role="radiogroup" aria-label="유저 색">
|
||||
{USER_COLORS.map((c) => (
|
||||
<button
|
||||
key={c}
|
||||
className={`ue-sw${user.color.toLowerCase() === c ? ' on' : ''}`}
|
||||
style={{ background: c }}
|
||||
role="radio"
|
||||
aria-checked={user.color.toLowerCase() === c}
|
||||
aria-label={c}
|
||||
disabled={busy}
|
||||
onClick={() => void patch({ color: c }, '색을 바꿨습니다')}
|
||||
/>
|
||||
))}
|
||||
<button className="ue-sw custom" title="다른 색 고르기" aria-label="다른 색 고르기" disabled={busy} onClick={() => colorRef.current?.click()}>
|
||||
+
|
||||
</button>
|
||||
<input ref={colorRef} type="color" className="ue-hidden" defaultValue={user.color} onChange={(e) => void patch({ color: e.target.value }, '색을 바꿨습니다')} />
|
||||
</div>
|
||||
|
||||
<div className="ue-label">라이엇 ID</div>
|
||||
<form
|
||||
className="ue-row"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
if (!riotBad.length) void patch({ riotIds }, '라이엇 ID 를 저장했습니다');
|
||||
}}
|
||||
>
|
||||
<input className="ue-input" value={riot} placeholder="이름#태그 (여러 개는 쉼표로)" onChange={(e) => setRiot(e.target.value)} aria-label="라이엇 ID" />
|
||||
<button className="btn sm" disabled={busy || riot.trim() === riotNow || riotBad.length > 0 || riotIds.length > 5}>
|
||||
저장
|
||||
</button>
|
||||
</form>
|
||||
{riotBad.length > 0 && <div className="ue-msg bad">이름#태그 형식이 아닙니다: {riotBad.join(', ')}</div>}
|
||||
<div className="ue-hint">경기 기록의 선수와 연결됩니다. 새로 넣은 ID 는 다음 경기에서 확인됩니다.</div>
|
||||
|
||||
<label className="ue-check">
|
||||
<input type="checkbox" checked={user.excluded} disabled={busy} onChange={(e) => void patch({ excluded: e.target.checked }, e.target.checked ? '앞으로 녹음하지 않습니다' : '다시 녹음합니다')} />
|
||||
<span>
|
||||
<b>녹음 제외</b>
|
||||
<span className="ue-hint">{self ? '켜면 앞으로 내 목소리를 녹음하지 않습니다 (이미 녹음된 기록은 그대로).' : '켜면 앞으로 이 사람 목소리를 녹음하지 않습니다.'}</span>
|
||||
</span>
|
||||
</label>
|
||||
{msg && <div className={`ue-msg${msg.ok ? ' ok' : ' bad'}`}>{msg.text}</div>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** 머리글 오른쪽 위 내 이름을 누르면 나오는 "내 정보" */
|
||||
export function ProfilePopover({ onClose }: { onClose: () => void }) {
|
||||
const { auth, logout, refreshMe } = useAuth();
|
||||
const { userById } = useData();
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
const [custom, setCustom] = useState<boolean | null>(null);
|
||||
useEffect(() => {
|
||||
const down = (e: PointerEvent) => {
|
||||
if (ref.current && !ref.current.contains(e.target as Node) && !(e.target as HTMLElement).closest('.me-btn')) onClose();
|
||||
};
|
||||
const key = (e: KeyboardEvent) => e.key === 'Escape' && onClose();
|
||||
document.addEventListener('pointerdown', down);
|
||||
document.addEventListener('keydown', key);
|
||||
return () => {
|
||||
document.removeEventListener('pointerdown', down);
|
||||
document.removeEventListener('keydown', key);
|
||||
};
|
||||
}, [onClose]);
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
fetch('/site/profile', { credentials: 'include' })
|
||||
.then((r) => (r.ok ? r.json() : null))
|
||||
.then((p) => alive && p && setCustom(!!p.customName))
|
||||
.catch(() => undefined);
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
}, []);
|
||||
if (auth.status !== 'ok') return null;
|
||||
const me = auth.me.user;
|
||||
const u = userById(me.id);
|
||||
const admin = auth.me.canViewLogs;
|
||||
const roleLabel = auth.me.role === 'superadmin' ? '최고 관리자' : auth.me.role === 'admin' ? '관리자' : auth.me.role === 'user' ? '앱 유저' : admin ? '관리자' : '서버 멤버';
|
||||
return (
|
||||
<motion.div
|
||||
ref={ref}
|
||||
className="popover profile-pop"
|
||||
initial={{ opacity: 0, y: -6, scale: 0.98 }}
|
||||
animate={{ opacity: 1, y: 0, scale: 1 }}
|
||||
exit={{ opacity: 0, y: -6, scale: 0.98 }}
|
||||
transition={{ duration: 0.16 }}
|
||||
role="dialog"
|
||||
aria-label="내 정보"
|
||||
>
|
||||
<div className="pp-head">
|
||||
<Avatar name={me.name} src={me.avatar} color={u?.color ?? '#5865f2'} size={40} />
|
||||
<div>
|
||||
<b style={u ? { color: u.color } : undefined}>{me.name}</b>
|
||||
<div className="dim small">
|
||||
{roleLabel} · <span className="mono">{me.id}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<h5>표시 이름</h5>
|
||||
<NameEditor
|
||||
value={me.name}
|
||||
custom={!!custom}
|
||||
onSave={async (name) => {
|
||||
const r = await api.setMyName(name);
|
||||
setCustom(!!r.customName);
|
||||
await refreshMe();
|
||||
}}
|
||||
/>
|
||||
<div className="ue-hint">사이트 · 게임 PC 기록 · 범인 분석에서 디스코드 이름 대신 보입니다.</div>
|
||||
<h5>녹음 기록 설정</h5>
|
||||
{u ? <AppUserEditor user={u} self /> : <div className="ue-hint">아직 녹음된 적이 없습니다. 음성채널에서 한 번 녹음되면 색 · 라이엇 ID · 녹음 제외를 바꿀 수 있습니다.</div>}
|
||||
<div className="pp-links">
|
||||
{u && (
|
||||
<Link to={`/users/${me.id}`} className="mini-btn" onClick={onClose}>
|
||||
내 기록 보기
|
||||
</Link>
|
||||
)}
|
||||
{admin && (
|
||||
<Link to="/admin" className="mini-btn" onClick={onClose}>
|
||||
🛡️ 관리 페이지
|
||||
</Link>
|
||||
)}
|
||||
<button className="mini-btn" onClick={logout}>
|
||||
<ILogout width={13} height={13} /> 로그아웃
|
||||
</button>
|
||||
</div>
|
||||
</motion.div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user