1단계 뼈대: joke-app에서 로그인(디스코드·게스트)·세션·권한·관리자·DB를 가져와 음악퀴즈용으로 정리, 새 디자인·아이콘, WS 연결·시계 맞추기, 테스트·e2e
- apps/server: Hono API(auth/me/config/admin), Bun WebSocket(welcome·ping/pong, 압축 끔), SQLite 마이그레이션 - 사이트 설정: 채팅 도배 방지 기본 꺼짐(관리자가 켬, 초당·순간 횟수) - apps/web: 첫 화면·로그인·관리자(대시보드·사이트·사용자·관리자·기록), 라이트/다크, 휴대폰, noindex - packages/shared: 닉네임 규칙, 프로토콜(zod), 시계 차이 계산 - 테스트 20개 + 브라우저 e2e 6단계 통과 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
26
apps/web/src/components/LoginBox.tsx
Normal file
26
apps/web/src/components/LoginBox.tsx
Normal file
@@ -0,0 +1,26 @@
|
||||
/** 시작하기: Discord login (big) + guest nickname (docs/03 첫 화면 오른쪽). */
|
||||
import { DiscordMark } from './ui';
|
||||
import { GuestWarning, NicknameForm } from './NicknameForm';
|
||||
import { discordLoginUrl } from '../net/api';
|
||||
import { useSession } from '../store/session';
|
||||
|
||||
export function LoginBox({ next, onDone }: { next: string; onDone?: () => void }) {
|
||||
const discord = useSession((s) => s.discordEnabled);
|
||||
return (
|
||||
<section className="login-card" aria-labelledby="login-title">
|
||||
<h2 id="login-title">시작하기</h2>
|
||||
<p className="muted small">디스코드로 로그인하면 기록이 남고, 게스트도 바로 놀 수 있어요.</p>
|
||||
{discord && (
|
||||
<>
|
||||
<a className="btn btn-discord btn-lg btn-block" href={discordLoginUrl(next)}>
|
||||
<DiscordMark />
|
||||
디스코드로 로그인
|
||||
</a>
|
||||
<div className="or">또는</div>
|
||||
</>
|
||||
)}
|
||||
<NicknameForm onDone={onDone} />
|
||||
<GuestWarning />
|
||||
</section>
|
||||
);
|
||||
}
|
||||
65
apps/web/src/components/NicknameForm.tsx
Normal file
65
apps/web/src/components/NicknameForm.tsx
Normal file
@@ -0,0 +1,65 @@
|
||||
/** Guest start: nickname (pre-filled suggestion) + start button (joke-app NicknameForm). */
|
||||
import { useState } from 'react';
|
||||
import { nicknameError, normalizeNickname, suggestNickname } from '@mq/shared/lite';
|
||||
import { api } from '../net/api';
|
||||
import { useSession } from '../store/session';
|
||||
|
||||
export function NicknameForm({ onDone }: { onDone?: () => void }) {
|
||||
const [nick, setNick] = useState(() => suggestNickname());
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
const submit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
const n = normalizeNickname(nick);
|
||||
const err = nicknameError(n);
|
||||
if (err) return setError(err);
|
||||
setBusy(true);
|
||||
try {
|
||||
await api.guest(n);
|
||||
await useSession.getState().refresh();
|
||||
onDone?.();
|
||||
} catch (ex) {
|
||||
setError((ex as Error).message);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<form className="stack" onSubmit={submit}>
|
||||
<label className="field">
|
||||
게스트 닉네임 (2~12자)
|
||||
<input
|
||||
className="input"
|
||||
value={nick}
|
||||
onChange={(e) => {
|
||||
setNick(e.target.value);
|
||||
setError(null);
|
||||
}}
|
||||
onFocus={(e) => e.target.select()}
|
||||
maxLength={20}
|
||||
autoComplete="nickname"
|
||||
enterKeyHint="go"
|
||||
/>
|
||||
</label>
|
||||
{error && (
|
||||
<p className="field-error" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
<button className="btn btn-block" disabled={busy}>
|
||||
{busy ? '잠시만요…' : '게스트로 시작'}
|
||||
</button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
/** Guests are deleted a day after they leave the site (docs/02). */
|
||||
export function GuestWarning() {
|
||||
return (
|
||||
<p className="guest-warning small" role="note">
|
||||
게스트는 사이트에 들어오지 않은 채 하루가 지나면 계정이 지워져요. 퀴즈 저장은 디스코드 로그인 계정만 할 수 있어요.
|
||||
</p>
|
||||
);
|
||||
}
|
||||
114
apps/web/src/components/SiteHeader.tsx
Normal file
114
apps/web/src/components/SiteHeader.tsx
Normal file
@@ -0,0 +1,114 @@
|
||||
/** Top bar: logo, menu, theme toggle, login / account menu (joke-app SiteHeader, music-quiz menu). */
|
||||
import { 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';
|
||||
|
||||
export function SiteHeader() {
|
||||
const { me, siteName, role } = useSession();
|
||||
return (
|
||||
<header className="site-header">
|
||||
<div className="site-header-inner">
|
||||
<Link to="/" className="site-logo" aria-label={`${siteName} 홈`}>
|
||||
<img src="/logo.svg" alt="" width={36} height={36} />
|
||||
<span>{siteName}</span>
|
||||
</Link>
|
||||
<nav className="site-nav" aria-label="주 메뉴">
|
||||
<NavLink to="/" end>
|
||||
홈
|
||||
</NavLink>
|
||||
{role !== 'user' && <NavLink to="/admin">관리자</NavLink>}
|
||||
</nav>
|
||||
<div className="grow" />
|
||||
<ThemeToggle />
|
||||
{me ? (
|
||||
<AccountMenu />
|
||||
) : (
|
||||
<Link to="/login" className="btn btn-sm">
|
||||
로그인
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
}
|
||||
|
||||
function ThemeToggle() {
|
||||
const theme = useSession((s) => s.settings.theme);
|
||||
const updateSettings = useSession((s) => s.updateSettings);
|
||||
const [systemDark, setSystemDark] = useState(() => matchMedia('(prefers-color-scheme: dark)').matches);
|
||||
useEffect(() => {
|
||||
const q = matchMedia('(prefers-color-scheme: dark)');
|
||||
const on = () => setSystemDark(q.matches);
|
||||
q.addEventListener('change', on);
|
||||
return () => q.removeEventListener('change', on);
|
||||
}, []);
|
||||
const dark = theme === 'dark' || (theme === 'auto' && systemDark);
|
||||
const label = dark ? '밝은 화면으로 바꾸기' : '어두운 화면으로 바꾸기';
|
||||
return (
|
||||
<button type="button" className="theme-toggle" aria-label={label} title={label} onClick={() => updateSettings({ theme: dark ? 'light' : 'dark' })}>
|
||||
<span aria-hidden>{dark ? '☀️' : '🌙'}</span>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
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 ref = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const onDown = (e: PointerEvent) => !ref.current?.contains(e.target as Node) && setOpen(false);
|
||||
const onKey = (e: KeyboardEvent) => e.key === 'Escape' && setOpen(false);
|
||||
document.addEventListener('pointerdown', onDown);
|
||||
document.addEventListener('keydown', onKey);
|
||||
return () => {
|
||||
document.removeEventListener('pointerdown', onDown);
|
||||
document.removeEventListener('keydown', onKey);
|
||||
};
|
||||
}, [open]);
|
||||
|
||||
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)}>
|
||||
<Avatar user={me} />
|
||||
<span className="header-user-name">{me.nickname}</span>
|
||||
{me.kind === 'guest' && <span className="badge">게스트</span>}
|
||||
<span aria-hidden className="small muted">
|
||||
▾
|
||||
</span>
|
||||
</button>
|
||||
{open && (
|
||||
<div className="account-menu-list" role="menu" aria-label="내 계정">
|
||||
{role !== 'user' && (
|
||||
<button type="button" role="menuitem" onClick={() => (setOpen(false), nav('/admin'))}>
|
||||
🛠 관리자 메뉴
|
||||
</button>
|
||||
)}
|
||||
<button type="button" role="menuitem" onClick={() => (setOpen(false), setConfirm(true))}>
|
||||
🚪 로그아웃
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{confirm && (
|
||||
<ConfirmSheet
|
||||
title="로그아웃할까요?"
|
||||
body={me.kind === 'guest' ? '게스트 계정은 로그아웃하면 이름과 기록이 모두 지워져요.' : undefined}
|
||||
confirm="로그아웃"
|
||||
danger={me.kind === 'guest'}
|
||||
onConfirm={async () => {
|
||||
await api.logout();
|
||||
nav('/');
|
||||
await useSession.getState().refresh();
|
||||
}}
|
||||
onClose={() => setConfirm(false)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
101
apps/web/src/components/ui.tsx
Normal file
101
apps/web/src/components/ui.tsx
Normal file
@@ -0,0 +1,101 @@
|
||||
/** Shared UI primitives (joke-app pattern, new look). */
|
||||
import { useEffect, useRef, type ReactNode } from 'react';
|
||||
import type { PublicUser } from '@mq/shared/lite';
|
||||
import { useToasts } from '../store/toast';
|
||||
|
||||
/** Per-user fixed colour; skips the 60°~160° green band so names never look like the 정답 green (docs/03). */
|
||||
export function userHue(id: string): number {
|
||||
let h = 0;
|
||||
for (const ch of id) h = (h * 31 + ch.charCodeAt(0)) >>> 0;
|
||||
const hue = h % 260;
|
||||
return hue < 60 ? hue : hue + 100;
|
||||
}
|
||||
|
||||
export function Avatar({ user, size = 36 }: { user: Pick<PublicUser, 'id' | 'nickname' | 'avatar'>; size?: number }) {
|
||||
return (
|
||||
<span className="avatar" style={{ width: size, height: size, background: `hsl(${userHue(user.id)} 45% 45%)`, fontSize: size * 0.42 }} aria-hidden>
|
||||
{user.avatar ? <img src={user.avatar} alt="" loading="lazy" referrerPolicy="no-referrer" /> : [...user.nickname][0]}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
export function Sheet({ onClose, children, label }: { onClose: () => void; children: ReactNode; label: string }) {
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
const close = useRef(onClose);
|
||||
close.current = onClose;
|
||||
useEffect(() => {
|
||||
const prev = document.activeElement as HTMLElement | null;
|
||||
ref.current?.focus();
|
||||
const onKey = (e: KeyboardEvent) => e.key === 'Escape' && close.current();
|
||||
window.addEventListener('keydown', onKey);
|
||||
return () => {
|
||||
window.removeEventListener('keydown', onKey);
|
||||
prev?.focus?.();
|
||||
};
|
||||
}, []);
|
||||
return (
|
||||
<div className="sheet-backdrop" onClick={(e) => e.target === e.currentTarget && onClose()}>
|
||||
<div className="sheet" role="dialog" aria-modal="true" aria-label={label} tabIndex={-1} ref={ref}>
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function ConfirmSheet({
|
||||
title,
|
||||
body,
|
||||
confirm,
|
||||
danger,
|
||||
onConfirm,
|
||||
onClose,
|
||||
}: {
|
||||
title: string;
|
||||
body?: ReactNode;
|
||||
confirm: string;
|
||||
danger?: boolean;
|
||||
onConfirm: () => void;
|
||||
onClose: () => void;
|
||||
}) {
|
||||
return (
|
||||
<Sheet onClose={onClose} label={title}>
|
||||
<h2>{title}</h2>
|
||||
{body && <div className="muted">{body}</div>}
|
||||
<div className="stack">
|
||||
<button
|
||||
className={`btn btn-block ${danger ? 'btn-danger' : 'btn-primary'}`}
|
||||
onClick={() => {
|
||||
onConfirm();
|
||||
onClose();
|
||||
}}
|
||||
>
|
||||
{confirm}
|
||||
</button>
|
||||
<button className="btn btn-block" onClick={onClose}>
|
||||
취소
|
||||
</button>
|
||||
</div>
|
||||
</Sheet>
|
||||
);
|
||||
}
|
||||
|
||||
export function Toasts() {
|
||||
const toasts = useToasts((s) => s.toasts);
|
||||
return (
|
||||
<div className="toasts" role="status" aria-live="polite">
|
||||
{toasts.map((t) => (
|
||||
<div key={t.id} className={`toast ${t.kind === 'error' ? 'error' : ''}`}>
|
||||
{t.text}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function DiscordMark() {
|
||||
return (
|
||||
<svg width="22" height="16" viewBox="0 0 71 55" fill="currentColor" aria-hidden>
|
||||
<path d="M60.1 4.9A58.5 58.5 0 0 0 45.6.4a40 40 0 0 0-1.8 3.7 54 54 0 0 0-16.2 0A39 39 0 0 0 25.8.4 58.4 58.4 0 0 0 11.3 4.9C2.1 18.6-.4 32 .8 45.2a59 59 0 0 0 18 9.1 43 43 0 0 0 3.8-6.2 38 38 0 0 1-6-2.9l1.5-1.1a42 42 0 0 0 35.9 0l1.5 1.1a38 38 0 0 1-6 2.9 43 43 0 0 0 3.8 6.2 58.8 58.8 0 0 0 18-9.1c1.4-15.3-2.4-28.6-10.2-40.3ZM23.7 37.1c-3.5 0-6.4-3.2-6.4-7.2s2.8-7.2 6.4-7.2 6.5 3.3 6.4 7.2c0 4-2.8 7.2-6.4 7.2Zm23.6 0c-3.5 0-6.4-3.2-6.4-7.2s2.8-7.2 6.4-7.2 6.5 3.3 6.4 7.2c0 4-2.8 7.2-6.4 7.2Z" />
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
70
apps/web/src/main.tsx
Normal file
70
apps/web/src/main.tsx
Normal file
@@ -0,0 +1,70 @@
|
||||
import { StrictMode, Suspense, lazy, useEffect } from 'react';
|
||||
import { createRoot } from 'react-dom/client';
|
||||
import { BrowserRouter, Route, Routes, useLocation, useNavigate } from 'react-router';
|
||||
import 'pretendard/dist/web/variable/pretendardvariable-dynamic-subset.css';
|
||||
import './styles/global.css';
|
||||
import { Toasts } from './components/ui';
|
||||
import { SiteHeader } from './components/SiteHeader';
|
||||
import { useSession } from './store/session';
|
||||
import { toast } from './store/toast';
|
||||
import { Home } from './pages/Home';
|
||||
|
||||
const LoginPage = lazy(() => import('./pages/LoginPage'));
|
||||
const NotFound = lazy(() => import('./pages/NotFound'));
|
||||
const AdminApp = lazy(() => import('./pages/admin/AdminApp'));
|
||||
|
||||
function Announcement() {
|
||||
const text = useSession((s) => s.announcement);
|
||||
const maintenance = useSession((s) => s.maintenance);
|
||||
if (!text && !maintenance) return null;
|
||||
return (
|
||||
<div role="note" className={`announcement ${maintenance ? 'maintenance' : ''}`}>
|
||||
{maintenance && '🛠 점검 중 · '}
|
||||
{text || '새 방을 잠시 만들 수 없어요.'}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Shell() {
|
||||
const loaded = useSession((s) => s.loaded);
|
||||
const nav = useNavigate();
|
||||
const loc = useLocation();
|
||||
useEffect(() => {
|
||||
void useSession.getState().refresh();
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
const q = new URLSearchParams(loc.search);
|
||||
if (q.get('linked') === '1') toast('디스코드 계정과 연결했어요.');
|
||||
if (q.get('login') === 'failed') toast('디스코드 로그인에 실패했어요. 다시 시도해 주세요.', 'error');
|
||||
if (q.get('login') === 'banned') toast('이용이 제한된 계정이에요.', 'error', 6000);
|
||||
if (q.has('linked') || q.has('login')) {
|
||||
q.delete('linked');
|
||||
q.delete('login');
|
||||
nav({ pathname: loc.pathname, search: q.toString() }, { replace: true });
|
||||
}
|
||||
}, [loc.search]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
if (!loaded) return <div className="page muted">불러오는 중…</div>;
|
||||
return (
|
||||
<>
|
||||
<SiteHeader />
|
||||
<Announcement />
|
||||
<Toasts />
|
||||
<Suspense fallback={<div className="page muted">불러오는 중…</div>}>
|
||||
<Routes>
|
||||
<Route path="/" element={<Home />} />
|
||||
<Route path="/login" element={<LoginPage />} />
|
||||
<Route path="/admin/*" element={<AdminApp />} />
|
||||
<Route path="*" element={<NotFound />} />
|
||||
</Routes>
|
||||
</Suspense>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<StrictMode>
|
||||
<BrowserRouter>
|
||||
<Shell />
|
||||
</BrowserRouter>
|
||||
</StrictMode>,
|
||||
);
|
||||
48
apps/web/src/net/api.ts
Normal file
48
apps/web/src/net/api.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import type { PublicUser, Role } from '@mq/shared/lite';
|
||||
|
||||
export class ApiError extends Error {
|
||||
constructor(
|
||||
message: string,
|
||||
readonly status: number,
|
||||
) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
export async function apiCall<T>(method: string, path: string, body?: unknown): Promise<T> {
|
||||
let res: Response;
|
||||
try {
|
||||
res = await fetch(path, {
|
||||
method,
|
||||
credentials: 'same-origin',
|
||||
headers: body !== undefined ? { 'Content-Type': 'application/json' } : undefined,
|
||||
body: body !== undefined ? JSON.stringify(body) : undefined,
|
||||
});
|
||||
} catch {
|
||||
throw new ApiError('인터넷 연결을 확인해 주세요.', 0);
|
||||
}
|
||||
const data = (await res.json().catch(() => ({}))) as { error?: string } & T;
|
||||
if (!res.ok) throw new ApiError(data.error ?? '잠시 후 다시 시도해 주세요.', res.status);
|
||||
return data;
|
||||
}
|
||||
|
||||
export interface Settings {
|
||||
fontScale?: 'normal' | 'large' | 'xlarge';
|
||||
theme?: 'auto' | 'light' | 'dark';
|
||||
}
|
||||
|
||||
export interface MeResponse {
|
||||
me: PublicUser | null;
|
||||
role?: Role;
|
||||
settings?: Settings;
|
||||
}
|
||||
|
||||
export const api = {
|
||||
config: () => apiCall<{ discord: boolean; siteName: string; announcement: string; maintenance: boolean }>('GET', '/api/config'),
|
||||
me: () => apiCall<MeResponse>('GET', '/api/me'),
|
||||
guest: (nickname: string) => apiCall<{ me: PublicUser }>('POST', '/api/auth/guest', { nickname }),
|
||||
updateMe: (patch: { nickname?: string; settings?: Settings }) => apiCall<{ me: PublicUser }>('PATCH', '/api/me', patch),
|
||||
logout: () => apiCall<{ ok: true }>('POST', '/api/auth/logout', {}),
|
||||
};
|
||||
|
||||
export const discordLoginUrl = (next: string) => `/api/auth/discord/start?next=${encodeURIComponent(next)}`;
|
||||
50
apps/web/src/pages/Home.tsx
Normal file
50
apps/web/src/pages/Home.tsx
Normal file
@@ -0,0 +1,50 @@
|
||||
/** 첫 화면 (docs/03): 소개 + 방 만들기/코드로 참여, 시작하기, 열린 방 목록. Rooms arrive in stage 4. */
|
||||
import { useSession } from '../store/session';
|
||||
import { LoginBox } from '../components/LoginBox';
|
||||
import { Avatar } from '../components/ui';
|
||||
|
||||
export function Home() {
|
||||
const me = useSession((s) => s.me);
|
||||
return (
|
||||
<main className="page">
|
||||
<div className="hero">
|
||||
<section className="welcome" aria-labelledby="hero-title">
|
||||
<div className="bigLP" aria-hidden />
|
||||
<h1 id="hero-title">
|
||||
전주 1초, 채팅 한 줄.
|
||||
<br />
|
||||
누가 먼저 맞히나.
|
||||
</h1>
|
||||
<p>방 만들고 링크 하나 보내면 끝. 인원 제한 없이 같이 듣고, 채팅으로 제목을 먼저 치는 사람이 점수를 가져가요.</p>
|
||||
<div className="acts">
|
||||
<button className="btn btn-mustard btn-lg" disabled title="방 기능을 준비하고 있어요">
|
||||
+ 방 만들기
|
||||
</button>
|
||||
<button className="btn btn-lg" disabled title="방 기능을 준비하고 있어요">
|
||||
코드로 참여
|
||||
</button>
|
||||
</div>
|
||||
<p className="note">방 만들기는 곧 열려요. 지금은 로그인만 먼저 해 볼 수 있어요.</p>
|
||||
</section>
|
||||
{me ? (
|
||||
<section className="login-card" aria-labelledby="me-title">
|
||||
<h2 id="me-title">반가워요!</h2>
|
||||
<div className="row">
|
||||
<Avatar user={me} size={48} />
|
||||
<div>
|
||||
<div style={{ fontWeight: 800, fontSize: '1.1rem' }}>{me.nickname}</div>
|
||||
<div className="muted small">{me.kind === 'member' ? '디스코드 계정으로 로그인했어요' : '게스트로 참여 중이에요'}</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
) : (
|
||||
<LoginBox next="/" />
|
||||
)}
|
||||
</div>
|
||||
<div className="rooms-head">
|
||||
<h2>열린 방 0</h2>
|
||||
</div>
|
||||
<div className="empty">아직 열린 방이 없어요.</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
19
apps/web/src/pages/LoginPage.tsx
Normal file
19
apps/web/src/pages/LoginPage.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
import { Navigate, useNavigate, useSearchParams } from 'react-router';
|
||||
import { LoginBox } from '../components/LoginBox';
|
||||
import { useSession } from '../store/session';
|
||||
|
||||
/** Only same-site paths, so ?next= can't send people to another site. */
|
||||
const safeNext = (v: string | null) => (v && v.startsWith('/') && !v.startsWith('//') ? v : '/');
|
||||
|
||||
export default function LoginPage() {
|
||||
const nav = useNavigate();
|
||||
const me = useSession((s) => s.me);
|
||||
const [params] = useSearchParams();
|
||||
const next = safeNext(params.get('next'));
|
||||
if (me) return <Navigate to={next} replace />;
|
||||
return (
|
||||
<main className="page narrow">
|
||||
<LoginBox next={next} onDone={() => nav(next, { replace: true })} />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
12
apps/web/src/pages/NotFound.tsx
Normal file
12
apps/web/src/pages/NotFound.tsx
Normal file
@@ -0,0 +1,12 @@
|
||||
import { Link } from 'react-router';
|
||||
|
||||
export default function NotFound() {
|
||||
return (
|
||||
<main className="page narrow stack">
|
||||
<h1>페이지를 찾을 수 없어요</h1>
|
||||
<Link to="/" className="btn">
|
||||
홈으로
|
||||
</Link>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
434
apps/web/src/pages/admin/AdminApp.tsx
Normal file
434
apps/web/src/pages/admin/AdminApp.tsx
Normal file
@@ -0,0 +1,434 @@
|
||||
/**
|
||||
* 관리자 페이지 (docs/02): side menu + content. Stage 1 has 대시보드 · 사이트 · 사용자 · 관리자 · 기록;
|
||||
* 노래 · 가수 · 장르 · 수집 · 통계 · 방 are listed and open in later stages.
|
||||
*/
|
||||
import { useCallback, useEffect, useState, type FormEvent } from 'react';
|
||||
import { Link, NavLink, Navigate, Route, Routes } from 'react-router';
|
||||
import type { Role } from '@mq/shared/lite';
|
||||
import { ApiError, apiCall, discordLoginUrl } from '../../net/api';
|
||||
import { useSession } from '../../store/session';
|
||||
import { toast } from '../../store/toast';
|
||||
import { ConfirmSheet } from '../../components/ui';
|
||||
|
||||
const fmt = (ms: number | null | undefined) => (ms ? new Date(ms).toLocaleString('ko-KR', { dateStyle: 'short', timeStyle: 'short' }) : '-');
|
||||
|
||||
function useLoad<T>(path: string | null) {
|
||||
const [data, setData] = useState<T | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const reload = useCallback(() => {
|
||||
if (!path) return;
|
||||
apiCall<T>('GET', path)
|
||||
.then((d) => (setData(d), setError(null)))
|
||||
.catch((e: Error) => setError(e.message));
|
||||
}, [path]);
|
||||
useEffect(reload, [reload]);
|
||||
return { data, error, reload, setData };
|
||||
}
|
||||
|
||||
const SOON = ['노래', '가수', '장르', '수집', '통계', '방'];
|
||||
|
||||
export default function AdminApp() {
|
||||
const me = useSession((s) => s.me);
|
||||
const role = useSession((s) => s.role);
|
||||
if (!me || me.kind === 'guest') {
|
||||
return (
|
||||
<main className="page narrow stack">
|
||||
<h1>관리자 페이지</h1>
|
||||
<p className="muted">관리자는 디스코드로 로그인해야 들어올 수 있어요.</p>
|
||||
<a className="btn btn-discord" href={discordLoginUrl('/admin')}>
|
||||
디스코드로 로그인
|
||||
</a>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
if (role === 'user') {
|
||||
return (
|
||||
<main className="page narrow stack">
|
||||
<h1>권한이 없어요</h1>
|
||||
<p className="muted">관리자로 등록된 디스코드 계정만 들어올 수 있어요.</p>
|
||||
<Link className="btn" to="/">
|
||||
홈으로
|
||||
</Link>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
const isSuper = role === 'superadmin';
|
||||
return (
|
||||
<div className="admin-layout">
|
||||
<nav className="admin-side" aria-label="관리자 메뉴">
|
||||
<NavLink to="/admin" end>
|
||||
📊 대시보드
|
||||
</NavLink>
|
||||
<div className="sep">노래 DB</div>
|
||||
{SOON.map((s) => (
|
||||
<a key={s} className="soon" aria-disabled="true" title="다음 단계에서 열려요">
|
||||
{s} <span className="badge">준비 중</span>
|
||||
</a>
|
||||
))}
|
||||
<div className="sep">운영</div>
|
||||
<NavLink to="/admin/site">⚙️ 사이트</NavLink>
|
||||
{isSuper && <NavLink to="/admin/users">👤 사용자</NavLink>}
|
||||
{isSuper && <NavLink to="/admin/admins">🛡 관리자</NavLink>}
|
||||
<NavLink to="/admin/audit">📜 기록</NavLink>
|
||||
</nav>
|
||||
<main className="admin-main">
|
||||
<Routes>
|
||||
<Route index element={<Dashboard role={role} />} />
|
||||
<Route path="site" element={<SiteSettings />} />
|
||||
{isSuper && <Route path="users" element={<UsersPage />} />}
|
||||
{isSuper && <Route path="admins" element={<AdminsPage />} />}
|
||||
<Route path="audit" element={<AuditPage />} />
|
||||
<Route path="*" element={<Navigate to="/admin" replace />} />
|
||||
</Routes>
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Dashboard({ role }: { role: Role }) {
|
||||
const { data, error } = useLoad<{ users: { total: number; guests: number; members: number; banned: number }; connections: number; uptimeSec: number; memoryMb: number }>(
|
||||
'/api/admin/overview',
|
||||
);
|
||||
return (
|
||||
<>
|
||||
<h1>대시보드</h1>
|
||||
<p className="muted">
|
||||
내 권한: <b>{role === 'superadmin' ? '슈퍼어드민' : '관리자'}</b>
|
||||
</p>
|
||||
{error && <p className="field-error">{error}</p>}
|
||||
{data && (
|
||||
<div className="stat-row">
|
||||
<div className="stat">
|
||||
<b>{data.connections}</b>
|
||||
<span>지금 접속</span>
|
||||
</div>
|
||||
<div className="stat">
|
||||
<b>{data.users.members}</b>
|
||||
<span>디스코드 회원</span>
|
||||
</div>
|
||||
<div className="stat">
|
||||
<b>{data.users.guests}</b>
|
||||
<span>게스트</span>
|
||||
</div>
|
||||
<div className="stat">
|
||||
<b>{data.users.banned}</b>
|
||||
<span>이용 제한</span>
|
||||
</div>
|
||||
<div className="stat">
|
||||
<b>{Math.floor(data.uptimeSec / 3600)}시간</b>
|
||||
<span>서버 켜진 시간</span>
|
||||
</div>
|
||||
<div className="stat">
|
||||
<b>{data.memoryMb}MB</b>
|
||||
<span>서버 메모리</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div className="card">
|
||||
<h2>다음에 생기는 것</h2>
|
||||
<p className="muted small">노래 수, 유튜브 매칭률, 가사 보유율, 진행 중인 방, 오늘 플레이 수는 노래 DB와 방 기능이 들어오면 여기에 보여요.</p>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
interface Site {
|
||||
siteName: string;
|
||||
announcement: string;
|
||||
maintenance: boolean;
|
||||
bannedWords: string[];
|
||||
chatFloodGuard: boolean;
|
||||
chatRatePerSec: number;
|
||||
chatBurst: number;
|
||||
}
|
||||
|
||||
function SiteSettings() {
|
||||
const { data, error } = useLoad<{ site: Site }>('/api/admin/site');
|
||||
const [s, setS] = useState<Site | null>(null);
|
||||
const [words, setWords] = useState('');
|
||||
useEffect(() => {
|
||||
if (data) {
|
||||
setS(data.site);
|
||||
setWords(data.site.bannedWords.join(', '));
|
||||
}
|
||||
}, [data]);
|
||||
if (error) return <p className="field-error">{error}</p>;
|
||||
if (!s) return <p className="muted">불러오는 중…</p>;
|
||||
const save = async (e: FormEvent) => {
|
||||
e.preventDefault();
|
||||
const next = { ...s, bannedWords: words.split(',').map((w) => w.trim()).filter(Boolean) };
|
||||
try {
|
||||
const r = await apiCall<{ site: Site }>('PUT', '/api/admin/site', next);
|
||||
setS(r.site);
|
||||
toast('저장했어요.');
|
||||
void useSession.getState().refresh();
|
||||
} catch (ex) {
|
||||
toast((ex as ApiError).message, 'error');
|
||||
}
|
||||
};
|
||||
return (
|
||||
<form className="stack" onSubmit={save}>
|
||||
<h1>사이트 설정</h1>
|
||||
<div className="form-grid">
|
||||
<label className="field">
|
||||
사이트 이름
|
||||
<input className="input" value={s.siteName} maxLength={40} onChange={(e) => setS({ ...s, siteName: e.target.value })} />
|
||||
</label>
|
||||
<label className="field">
|
||||
공지 (첫 화면 위에 보여요)
|
||||
<input className="input" value={s.announcement} maxLength={300} onChange={(e) => setS({ ...s, announcement: e.target.value })} />
|
||||
</label>
|
||||
</div>
|
||||
<label className="check">
|
||||
<input type="checkbox" checked={s.maintenance} onChange={(e) => setS({ ...s, maintenance: e.target.checked })} />
|
||||
점검 모드
|
||||
</label>
|
||||
<label className="field">
|
||||
금칙어 (쉼표로 구분, 닉네임·채팅에 적용)
|
||||
<textarea className="input" value={words} onChange={(e) => setWords(e.target.value)} />
|
||||
</label>
|
||||
<fieldset className="card stack" style={{ margin: 0 }}>
|
||||
<legend style={{ fontWeight: 800, padding: '0 6px' }}>채팅 도배 방지</legend>
|
||||
<label className="check">
|
||||
<input type="checkbox" checked={s.chatFloodGuard} onChange={(e) => setS({ ...s, chatFloodGuard: e.target.checked })} />
|
||||
도배 방지 켜기 (기본: 꺼짐)
|
||||
</label>
|
||||
<p className="muted small">켜면 한 사람이 너무 빨리 많이 보낸 채팅만 막아요. 꺼져 있으면 채팅은 아무 제한 없이 바로 전달돼요.</p>
|
||||
<div className="form-grid">
|
||||
<label className="field">
|
||||
초당 채팅 수
|
||||
<input className="input" type="number" min={1} max={50} disabled={!s.chatFloodGuard} value={s.chatRatePerSec} onChange={(e) => setS({ ...s, chatRatePerSec: Number(e.target.value) })} />
|
||||
</label>
|
||||
<label className="field">
|
||||
한 번에 몰아서 보낼 수 있는 수
|
||||
<input className="input" type="number" min={1} max={100} disabled={!s.chatFloodGuard} value={s.chatBurst} onChange={(e) => setS({ ...s, chatBurst: Number(e.target.value) })} />
|
||||
</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
<div>
|
||||
<button className="btn btn-primary">저장</button>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
interface AdminUser {
|
||||
id: string;
|
||||
nickname: string;
|
||||
kind: 'guest' | 'member';
|
||||
discordId: string | null;
|
||||
discordName: string | null;
|
||||
role: Role;
|
||||
banned: { at: number; reason: string | null } | null;
|
||||
createdAt: number;
|
||||
lastSeenAt: number;
|
||||
}
|
||||
|
||||
function UsersPage() {
|
||||
const [q, setQ] = useState('');
|
||||
const [query, setQuery] = useState('');
|
||||
const { data, error, reload } = useLoad<{ total: number; users: AdminUser[] }>(`/api/admin/users?q=${encodeURIComponent(query)}`);
|
||||
const [confirm, setConfirm] = useState<{ title: string; run: () => Promise<unknown>; danger?: boolean } | null>(null);
|
||||
const act = (title: string, run: () => Promise<unknown>, danger = false) => setConfirm({ title, run, danger });
|
||||
const done = (msg: string) => (toast(msg), reload());
|
||||
const fail = (e: Error) => toast(e.message, 'error');
|
||||
return (
|
||||
<>
|
||||
<h1>사용자</h1>
|
||||
<form
|
||||
className="row"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
setQuery(q.trim());
|
||||
}}
|
||||
>
|
||||
<input className="input grow" placeholder="닉네임, 사용자 ID, 디스코드 ID" value={q} onChange={(e) => setQ(e.target.value)} style={{ maxWidth: 420 }} />
|
||||
<button className="btn">검색</button>
|
||||
{data && <span className="muted small">전체 {data.total}명</span>}
|
||||
</form>
|
||||
{error && <p className="field-error">{error}</p>}
|
||||
<div className="table-wrap">
|
||||
<table className="data-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>닉네임</th>
|
||||
<th>종류</th>
|
||||
<th>디스코드</th>
|
||||
<th>권한</th>
|
||||
<th>마지막 접속</th>
|
||||
<th>상태</th>
|
||||
<th />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{data?.users.map((u) => (
|
||||
<tr key={u.id}>
|
||||
<td>{u.nickname}</td>
|
||||
<td>{u.kind === 'member' ? '회원' : '게스트'}</td>
|
||||
<td className="mono small">{u.discordId ? `${u.discordName ?? ''} (${u.discordId})` : '-'}</td>
|
||||
<td>{u.role === 'superadmin' ? '슈퍼어드민' : u.role === 'admin' ? '관리자' : '-'}</td>
|
||||
<td className="small">{fmt(u.lastSeenAt)}</td>
|
||||
<td>{u.banned ? <span className="badge warn">제한: {u.banned.reason}</span> : <span className="badge ok">정상</span>}</td>
|
||||
<td>
|
||||
<div className="row" style={{ flexWrap: 'nowrap' }}>
|
||||
<button
|
||||
className="btn btn-sm"
|
||||
onClick={() => {
|
||||
const nick = prompt('새 닉네임', u.nickname);
|
||||
if (nick) apiCall('PATCH', `/api/admin/users/${u.id}`, { nickname: nick }).then(() => done('닉네임을 바꿨어요.'), fail);
|
||||
}}
|
||||
>
|
||||
닉네임
|
||||
</button>
|
||||
{u.banned ? (
|
||||
<button className="btn btn-sm" onClick={() => apiCall('PATCH', `/api/admin/users/${u.id}`, { ban: null }).then(() => done('제한을 풀었어요.'), fail)}>
|
||||
제한 풀기
|
||||
</button>
|
||||
) : (
|
||||
u.role !== 'superadmin' && (
|
||||
<button
|
||||
className="btn btn-sm"
|
||||
onClick={() => {
|
||||
const reason = prompt('제한 사유');
|
||||
if (reason) apiCall('PATCH', `/api/admin/users/${u.id}`, { ban: { reason } }).then(() => done('이용을 제한했어요.'), fail);
|
||||
}}
|
||||
>
|
||||
제한
|
||||
</button>
|
||||
)
|
||||
)}
|
||||
<button className="btn btn-sm" onClick={() => act(`${u.nickname}님을 모든 기기에서 로그아웃할까요?`, () => apiCall('POST', `/api/admin/users/${u.id}/logout`, {}).then(() => done('로그아웃시켰어요.')))}>
|
||||
로그아웃
|
||||
</button>
|
||||
{u.role !== 'superadmin' && (
|
||||
<button className="btn btn-sm btn-danger" onClick={() => act(`${u.nickname}님 계정을 삭제할까요?`, () => apiCall('DELETE', `/api/admin/users/${u.id}`).then(() => done('삭제했어요.')), true)}>
|
||||
삭제
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{confirm && <ConfirmSheet title={confirm.title} confirm="확인" danger={confirm.danger} onConfirm={() => void confirm.run().catch(fail)} onClose={() => setConfirm(null)} />}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
interface AdminEntry {
|
||||
discordId: string;
|
||||
note: string | null;
|
||||
addedAt: number;
|
||||
nickname: string | null;
|
||||
fixed: boolean;
|
||||
}
|
||||
|
||||
function AdminsPage() {
|
||||
const { data, error, setData } = useLoad<{ admins: AdminEntry[] }>('/api/admin/admins');
|
||||
const [discordId, setDiscordId] = useState('');
|
||||
const [note, setNote] = useState('');
|
||||
const add = async (e: FormEvent) => {
|
||||
e.preventDefault();
|
||||
try {
|
||||
setData(await apiCall<{ admins: AdminEntry[] }>('POST', '/api/admin/admins', { discordId: discordId.trim(), note: note.trim() || undefined }));
|
||||
setDiscordId('');
|
||||
setNote('');
|
||||
toast('관리자를 추가했어요.');
|
||||
} catch (ex) {
|
||||
toast((ex as Error).message, 'error');
|
||||
}
|
||||
};
|
||||
const remove = async (id: string) => {
|
||||
try {
|
||||
setData(await apiCall<{ admins: AdminEntry[] }>('DELETE', `/api/admin/admins/${id}`));
|
||||
toast('관리자에서 뺐어요.');
|
||||
} catch (ex) {
|
||||
toast((ex as Error).message, 'error');
|
||||
}
|
||||
};
|
||||
return (
|
||||
<>
|
||||
<h1>관리자</h1>
|
||||
<p className="muted small">디스코드 ID로 추가해요. 그 사람이 아직 로그인한 적이 없어도 미리 등록할 수 있어요. 고정 슈퍼어드민은 서버 설정 파일에서만 바꿀 수 있어요.</p>
|
||||
<form className="row" onSubmit={add}>
|
||||
<input className="input" style={{ maxWidth: 260 }} placeholder="디스코드 ID (숫자 17~20자리)" value={discordId} onChange={(e) => setDiscordId(e.target.value)} inputMode="numeric" />
|
||||
<input className="input" style={{ maxWidth: 220 }} placeholder="메모 (선택)" value={note} onChange={(e) => setNote(e.target.value)} />
|
||||
<button className="btn btn-primary">추가</button>
|
||||
</form>
|
||||
{error && <p className="field-error">{error}</p>}
|
||||
<div className="table-wrap">
|
||||
<table className="data-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>디스코드 ID</th>
|
||||
<th>닉네임</th>
|
||||
<th>메모</th>
|
||||
<th>추가한 때</th>
|
||||
<th />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{data?.admins.map((a) => (
|
||||
<tr key={a.discordId}>
|
||||
<td className="mono">{a.discordId}</td>
|
||||
<td>{a.nickname ?? <span className="muted">아직 로그인 안 함</span>}</td>
|
||||
<td>{a.note}</td>
|
||||
<td className="small">{a.fixed ? '고정' : fmt(a.addedAt)}</td>
|
||||
<td>{a.fixed ? <span className="badge teal">슈퍼어드민</span> : <button className="btn btn-sm" onClick={() => void remove(a.discordId)}>빼기</button>}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function AuditPage() {
|
||||
const [page, setPage] = useState(0);
|
||||
const { data, error } = useLoad<{ entries: { id: number; actor: string | null; action: string; target: string | null; before: unknown; after: unknown; at: number }[] }>(
|
||||
`/api/admin/audit?page=${page}`,
|
||||
);
|
||||
return (
|
||||
<>
|
||||
<h1>기록</h1>
|
||||
{error && <p className="field-error">{error}</p>}
|
||||
<div className="table-wrap">
|
||||
<table className="data-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>때</th>
|
||||
<th>누가</th>
|
||||
<th>무엇을</th>
|
||||
<th>대상</th>
|
||||
<th>내용</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{data?.entries.map((e) => (
|
||||
<tr key={e.id}>
|
||||
<td className="small">{fmt(e.at)}</td>
|
||||
<td>{e.actor ?? '-'}</td>
|
||||
<td className="mono small">{e.action}</td>
|
||||
<td className="mono small">{e.target ?? '-'}</td>
|
||||
<td className="small mono" style={{ maxWidth: 420, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
|
||||
{JSON.stringify(e.after ?? e.before)}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div className="row">
|
||||
<button className="btn btn-sm" disabled={page === 0} onClick={() => setPage((p) => p - 1)}>
|
||||
이전
|
||||
</button>
|
||||
<button className="btn btn-sm" disabled={(data?.entries.length ?? 0) < 50} onClick={() => setPage((p) => p + 1)}>
|
||||
다음
|
||||
</button>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
77
apps/web/src/store/session.ts
Normal file
77
apps/web/src/store/session.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
/** Who am I + display settings (joke-app pattern). */
|
||||
import { create } from 'zustand';
|
||||
import type { PublicUser, Role } from '@mq/shared/lite';
|
||||
import { api, type Settings } from '../net/api';
|
||||
|
||||
const LS_KEY = 'mq.settings';
|
||||
|
||||
export const DEFAULT_SETTINGS: Required<Settings> = { fontScale: 'normal', theme: 'auto' };
|
||||
|
||||
function loadLocal(): Required<Settings> {
|
||||
try {
|
||||
return { ...DEFAULT_SETTINGS, ...JSON.parse(localStorage.getItem(LS_KEY) ?? '{}') };
|
||||
} catch {
|
||||
return DEFAULT_SETTINGS;
|
||||
}
|
||||
}
|
||||
|
||||
export function applySettings(s: Required<Settings>): void {
|
||||
const html = document.documentElement;
|
||||
html.dataset.fontScale = s.fontScale;
|
||||
html.dataset.theme = s.theme;
|
||||
const dark = s.theme === 'dark' || (s.theme === 'auto' && matchMedia('(prefers-color-scheme: dark)').matches);
|
||||
document.querySelector('meta[name="theme-color"]')?.setAttribute('content', dark ? '#17150f' : '#f5efe3');
|
||||
}
|
||||
|
||||
interface SessionState {
|
||||
loaded: boolean;
|
||||
me: PublicUser | null;
|
||||
role: Role;
|
||||
discordEnabled: boolean;
|
||||
siteName: string;
|
||||
announcement: string;
|
||||
maintenance: boolean;
|
||||
settings: Required<Settings>;
|
||||
refresh(): Promise<void>;
|
||||
updateSettings(patch: Settings): void;
|
||||
}
|
||||
|
||||
export const useSession = create<SessionState>((set, get) => ({
|
||||
loaded: false,
|
||||
me: null,
|
||||
role: 'user',
|
||||
discordEnabled: false,
|
||||
siteName: '음악퀴즈',
|
||||
announcement: '',
|
||||
maintenance: false,
|
||||
settings: loadLocal(),
|
||||
async refresh() {
|
||||
const [cfg, me] = await Promise.all([
|
||||
api.config().catch(() => ({ discord: false, siteName: '음악퀴즈', announcement: '', maintenance: false })),
|
||||
api.me().catch(() => ({ me: null }) as Awaited<ReturnType<typeof api.me>>),
|
||||
]);
|
||||
const settings = { ...get().settings, ...(me.settings ?? {}) };
|
||||
applySettings(settings);
|
||||
localStorage.setItem(LS_KEY, JSON.stringify(settings));
|
||||
document.title = cfg.siteName;
|
||||
set({
|
||||
loaded: true,
|
||||
me: me.me,
|
||||
role: me.role ?? 'user',
|
||||
discordEnabled: cfg.discord,
|
||||
siteName: cfg.siteName,
|
||||
announcement: cfg.announcement,
|
||||
maintenance: cfg.maintenance,
|
||||
settings,
|
||||
});
|
||||
},
|
||||
updateSettings(patch) {
|
||||
const settings = { ...get().settings, ...patch };
|
||||
applySettings(settings);
|
||||
localStorage.setItem(LS_KEY, JSON.stringify(settings));
|
||||
set({ settings });
|
||||
if (get().me) api.updateMe({ settings }).catch(() => {});
|
||||
},
|
||||
}));
|
||||
|
||||
applySettings(loadLocal());
|
||||
17
apps/web/src/store/toast.ts
Normal file
17
apps/web/src/store/toast.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { create } from 'zustand';
|
||||
|
||||
export interface Toast {
|
||||
id: number;
|
||||
text: string;
|
||||
kind: 'info' | 'error';
|
||||
}
|
||||
|
||||
let nextId = 1;
|
||||
|
||||
export const useToasts = create<{ toasts: Toast[] }>(() => ({ toasts: [] }));
|
||||
|
||||
export function toast(text: string, kind: Toast['kind'] = 'info', ms = 3000): void {
|
||||
const id = nextId++;
|
||||
useToasts.setState((s) => ({ toasts: [...s.toasts.filter((t) => t.text !== text), { id, text, kind }].slice(-3) }));
|
||||
setTimeout(() => useToasts.setState((s) => ({ toasts: s.toasts.filter((t) => t.id !== id) })), ms);
|
||||
}
|
||||
242
apps/web/src/styles/global.css
Normal file
242
apps/web/src/styles/global.css
Normal file
@@ -0,0 +1,242 @@
|
||||
/* 음악퀴즈 — "동네 레코드 가게" (docs/03-ui-design.md). Hand-written CSS variables, no framework (same approach as joke-app). */
|
||||
:root {
|
||||
--bg: #f5efe3;
|
||||
--surface: #fffdf8;
|
||||
--surface-2: #efe6d3;
|
||||
--surface-3: #e6dac2;
|
||||
--ink: #1e1b18;
|
||||
--text: #1e1b18;
|
||||
--text-sub: #6b6157;
|
||||
--line: #ddd2be;
|
||||
--primary: #1f6f78;
|
||||
--primary-press: #185960;
|
||||
--primary-soft: #d7eae8;
|
||||
--on-primary: #fff;
|
||||
--mustard: #f2b544;
|
||||
--coral: #e4573d;
|
||||
--correct: #2f8f4e;
|
||||
--correct-soft: #ddf0e2;
|
||||
--danger: #b3261e;
|
||||
--danger-soft: #f8dcd6;
|
||||
--warning-soft: #fdebc7;
|
||||
--discord: #5865f2;
|
||||
--star-1: #f2b544;
|
||||
--star-2: #ef8a3a;
|
||||
--star-3: #dc4b3e;
|
||||
--star-4: #6b3fb5;
|
||||
--radius: 14px;
|
||||
--radius-sm: 10px;
|
||||
--shadow-key: 0 3px 0 var(--ink);
|
||||
--font: 'Pretendard Variable', Pretendard, -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
|
||||
color-scheme: light;
|
||||
}
|
||||
:root[data-theme='dark'] {
|
||||
--bg: #17150f;
|
||||
--surface: #221f1a;
|
||||
--surface-2: #2c2821;
|
||||
--surface-3: #39342b;
|
||||
--ink: #e9dfc9;
|
||||
--text: #efe7d6;
|
||||
--text-sub: #b3a891;
|
||||
--line: #3f392f;
|
||||
--primary: #4fa9b2;
|
||||
--primary-press: #3e8f97;
|
||||
--primary-soft: #1d3a3d;
|
||||
--on-primary: #10221f;
|
||||
--correct: #5cc07c;
|
||||
--correct-soft: #1c3324;
|
||||
--danger: #ff8a7a;
|
||||
--danger-soft: #3d1f1a;
|
||||
--warning-soft: #3d311a;
|
||||
color-scheme: dark;
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root[data-theme='auto'] {
|
||||
--bg: #17150f;
|
||||
--surface: #221f1a;
|
||||
--surface-2: #2c2821;
|
||||
--surface-3: #39342b;
|
||||
--ink: #e9dfc9;
|
||||
--text: #efe7d6;
|
||||
--text-sub: #b3a891;
|
||||
--line: #3f392f;
|
||||
--primary: #4fa9b2;
|
||||
--primary-press: #3e8f97;
|
||||
--primary-soft: #1d3a3d;
|
||||
--on-primary: #10221f;
|
||||
--correct: #5cc07c;
|
||||
--correct-soft: #1c3324;
|
||||
--danger: #ff8a7a;
|
||||
--danger-soft: #3d1f1a;
|
||||
--warning-soft: #3d311a;
|
||||
color-scheme: dark;
|
||||
}
|
||||
}
|
||||
:root[data-font-scale='large'] { font-size: 17px; }
|
||||
:root[data-font-scale='xlarge'] { font-size: 19px; }
|
||||
|
||||
*, *::before, *::after { box-sizing: border-box; }
|
||||
html { font-size: 15px; }
|
||||
body {
|
||||
margin: 0;
|
||||
background: var(--bg);
|
||||
/* very subtle paper grain */
|
||||
background-image: radial-gradient(color-mix(in srgb, var(--ink) 4%, transparent) 1px, transparent 1px);
|
||||
background-size: 5px 5px;
|
||||
color: var(--text);
|
||||
font-family: var(--font);
|
||||
font-weight: 500;
|
||||
letter-spacing: -0.01em;
|
||||
word-break: keep-all;
|
||||
line-height: 1.5;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
h1, h2, h3 { margin: 0; letter-spacing: -0.03em; font-weight: 800; }
|
||||
h1 { font-size: 1.6rem; }
|
||||
h2 { font-size: 1.15rem; }
|
||||
p { margin: 0; }
|
||||
a { color: var(--primary); }
|
||||
:focus-visible { outline: 3px solid var(--mustard); outline-offset: 2px; }
|
||||
.muted { color: var(--text-sub); }
|
||||
.small { font-size: 0.87rem; }
|
||||
.mono { font-variant-numeric: tabular-nums; }
|
||||
.stack { display: flex; flex-direction: column; gap: 12px; }
|
||||
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
|
||||
.grow { flex: 1; }
|
||||
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
|
||||
|
||||
/* ---------------------------------------------------------------- buttons (keycap: 2px ink + 3px solid shadow) */
|
||||
.btn {
|
||||
display: inline-flex; align-items: center; justify-content: center; gap: 8px;
|
||||
min-height: 44px; padding: 0 18px;
|
||||
border-radius: 12px; border: 2px solid var(--ink);
|
||||
background: var(--surface); color: var(--ink);
|
||||
font: inherit; font-weight: 700; font-size: 1rem; text-decoration: none; white-space: nowrap;
|
||||
box-shadow: var(--shadow-key); cursor: pointer;
|
||||
transition: transform 0.05s, box-shadow 0.05s;
|
||||
}
|
||||
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
|
||||
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
|
||||
.btn-primary { background: var(--primary); color: var(--on-primary); }
|
||||
.btn-mustard { background: var(--mustard); color: #1e1b18; }
|
||||
.btn-discord { background: var(--discord); color: #fff; }
|
||||
.btn-danger { background: var(--danger); color: #fff; }
|
||||
.btn-ghost { border-color: transparent; box-shadow: none; background: transparent; color: var(--text-sub); }
|
||||
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 0.87rem; border-radius: 9px; box-shadow: 0 2px 0 var(--ink); }
|
||||
.btn-lg { min-height: 52px; font-size: 1.07rem; }
|
||||
.btn-block { width: 100%; }
|
||||
|
||||
/* ---------------------------------------------------------------- form */
|
||||
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.87rem; font-weight: 700; color: var(--text-sub); }
|
||||
.input, textarea.input, select.input {
|
||||
min-height: 48px; width: 100%;
|
||||
border: 2px solid var(--ink); border-radius: 12px; padding: 0 14px;
|
||||
background: var(--surface); color: var(--text); font: inherit; font-weight: 600; font-size: 1rem;
|
||||
}
|
||||
textarea.input { padding: 10px 14px; min-height: 90px; resize: vertical; }
|
||||
.field-error { color: var(--danger); font-weight: 700; font-size: 0.9rem; }
|
||||
.check { display: flex; align-items: center; gap: 8px; font-weight: 700; }
|
||||
.check input { width: 20px; height: 20px; accent-color: var(--primary); }
|
||||
|
||||
/* ---------------------------------------------------------------- cards, badges, chips */
|
||||
.card { background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--radius); padding: 18px; }
|
||||
.card.ink { border: 2px solid var(--ink); }
|
||||
.badge { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 6px; font-size: 0.8rem; font-weight: 750; background: var(--surface-2); color: var(--text-sub); }
|
||||
.badge.teal { background: var(--primary-soft); color: var(--primary); }
|
||||
.badge.live { background: var(--coral); color: #fff; }
|
||||
.badge.ok { background: var(--correct-soft); color: var(--correct); }
|
||||
.badge.warn { background: var(--warning-soft); color: #8a5a00; }
|
||||
:root[data-theme='dark'] .badge.warn { color: var(--mustard); }
|
||||
.chip { min-height: 30px; padding: 0 11px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--surface); font: inherit; font-weight: 650; font-size: 0.87rem; display: inline-flex; align-items: center; gap: 5px; color: var(--text); cursor: pointer; }
|
||||
.chip[aria-pressed='true'] { border: 2px solid var(--ink); background: var(--primary); color: var(--on-primary); }
|
||||
|
||||
/* ---------------------------------------------------------------- site header */
|
||||
.site-header { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 2px solid var(--ink); }
|
||||
.site-header-inner { height: 64px; max-width: 1440px; margin: 0 auto; padding: 0 24px; display: flex; align-items: center; gap: 18px; }
|
||||
.site-logo { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.35rem; letter-spacing: -0.04em; color: var(--ink); text-decoration: none; }
|
||||
.site-logo img { width: 36px; height: 36px; }
|
||||
.site-nav { display: flex; gap: 16px; }
|
||||
.site-nav a { color: var(--text-sub); text-decoration: none; font-weight: 700; padding: 6px 2px; }
|
||||
.site-nav a.active { color: var(--ink); box-shadow: inset 0 -3px 0 var(--mustard); }
|
||||
.header-user { display: flex; align-items: center; gap: 8px; font: inherit; font-weight: 700; color: var(--ink); background: none; border: 0; cursor: pointer; padding: 4px; text-decoration: none; }
|
||||
.theme-toggle { width: 40px; height: 40px; border-radius: 10px; border: 2px solid var(--ink); background: var(--surface); cursor: pointer; font-size: 18px; }
|
||||
.account-menu { position: relative; }
|
||||
.account-menu-list { position: absolute; right: 0; top: calc(100% + 6px); min-width: 180px; background: var(--surface); border: 2px solid var(--ink); border-radius: 12px; box-shadow: 4px 4px 0 var(--ink); padding: 6px; display: flex; flex-direction: column; z-index: 30; }
|
||||
.account-menu-list button { text-align: left; font: inherit; font-weight: 700; padding: 10px 12px; border-radius: 8px; border: 0; background: none; color: var(--text); cursor: pointer; }
|
||||
.account-menu-list button:hover, .account-menu-list button:focus-visible { background: var(--surface-2); }
|
||||
.avatar { border-radius: 50%; border: 2px solid var(--ink); display: inline-flex; align-items: center; justify-content: center; font-weight: 800; color: #fff; overflow: hidden; flex: none; }
|
||||
.avatar img { width: 100%; height: 100%; object-fit: cover; }
|
||||
.announcement { background: var(--primary-soft); padding: 8px 16px; text-align: center; font-weight: 700; border-bottom: 1.5px solid var(--line); }
|
||||
.announcement.maintenance { background: var(--warning-soft); }
|
||||
|
||||
/* ---------------------------------------------------------------- pages */
|
||||
.page { max-width: 1440px; margin: 0 auto; padding: 28px 40px; }
|
||||
.page.narrow { max-width: 520px; }
|
||||
|
||||
/* home */
|
||||
.hero { display: grid; grid-template-columns: 1.1fr 1fr; gap: 28px; align-items: stretch; }
|
||||
.welcome { background: #1f6f78; color: #fff; border: 2px solid var(--ink); border-radius: 20px; padding: 30px 34px; position: relative; overflow: hidden; box-shadow: 6px 6px 0 var(--ink); min-height: 280px; }
|
||||
.welcome h1 { font-size: 2.25rem; font-weight: 850; letter-spacing: -0.045em; line-height: 1.22; position: relative; }
|
||||
.welcome p { opacity: 0.9; margin-top: 10px; font-size: 1.03rem; line-height: 1.6; max-width: 420px; position: relative; }
|
||||
.welcome .acts { display: flex; gap: 10px; margin-top: 22px; flex-wrap: wrap; position: relative; }
|
||||
.welcome .acts .btn { color: #1e1b18; border-color: #1e1b18; box-shadow: 0 3px 0 #1e1b18; }
|
||||
.welcome .acts .btn:not(.btn-mustard) { background: #fffdf8; }
|
||||
.welcome .bigLP { position: absolute; right: -70px; bottom: -90px; width: 300px; height: 300px; border-radius: 50%; background: repeating-radial-gradient(circle, #1c1a1f 0 6px, #2a2830 6px 8px); }
|
||||
.welcome .bigLP::after { content: ''; position: absolute; inset: 105px; border-radius: 50%; background: var(--mustard); }
|
||||
.welcome .note { position: relative; margin-top: 18px; font-size: 0.85rem; font-weight: 700; opacity: 0.85; }
|
||||
.login-card { background: var(--surface); border: 2px solid var(--ink); border-radius: 20px; padding: 26px 28px; display: flex; flex-direction: column; gap: 12px; }
|
||||
.or { display: flex; align-items: center; gap: 10px; color: var(--text-sub); font-size: 0.83rem; font-weight: 700; }
|
||||
.or::before, .or::after { content: ''; flex: 1; height: 1.5px; background: var(--line); }
|
||||
.guest-warning { background: var(--warning-soft); border-radius: 10px; padding: 8px 12px; }
|
||||
.rooms-head { display: flex; align-items: center; gap: 12px; margin: 30px 0 12px; flex-wrap: wrap; }
|
||||
.empty { border: 2px dashed var(--line); border-radius: 16px; padding: 28px; text-align: center; color: var(--text-sub); font-weight: 650; }
|
||||
|
||||
/* ---------------------------------------------------------------- admin (docs/02: side menu + content, .data-table) */
|
||||
.admin-layout { display: grid; grid-template-columns: 220px 1fr; min-height: calc(100vh - 66px); }
|
||||
.admin-side { background: var(--surface-2); border-right: 2px solid var(--ink); padding: 16px 12px; display: flex; flex-direction: column; gap: 3px; }
|
||||
.admin-side a { display: flex; align-items: center; gap: 9px; padding: 9px 12px; border-radius: 10px; font-weight: 700; color: var(--text-sub); text-decoration: none; }
|
||||
.admin-side a.active { background: var(--ink); color: var(--surface); }
|
||||
.admin-side a.soon { opacity: 0.55; }
|
||||
.admin-side .sep { font-size: 0.77rem; font-weight: 800; color: var(--text-sub); padding: 12px 12px 4px; letter-spacing: 0.04em; }
|
||||
.admin-main { padding: 22px 26px; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
|
||||
.stat-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
|
||||
.stat { background: var(--surface); border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px; }
|
||||
.stat b { display: block; font-size: 1.4rem; font-weight: 850; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
|
||||
.stat span { font-size: 0.8rem; color: var(--text-sub); font-weight: 700; }
|
||||
.table-wrap { overflow-x: auto; }
|
||||
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface); border: 2px solid var(--ink); border-radius: 12px; overflow: hidden; font-size: 0.9rem; }
|
||||
.data-table th { background: var(--surface-2); text-align: left; font-size: 0.8rem; color: var(--text-sub); font-weight: 800; padding: 9px 10px; border-bottom: 2px solid var(--ink); white-space: nowrap; }
|
||||
.data-table td { padding: 8px 10px; border-bottom: 1.5px solid var(--line); font-weight: 600; vertical-align: middle; }
|
||||
.data-table tr:last-child td { border-bottom: 0; }
|
||||
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
|
||||
|
||||
/* ---------------------------------------------------------------- toasts */
|
||||
.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; pointer-events: none; }
|
||||
.toast { background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 10px; font-weight: 700; box-shadow: 0 3px 0 color-mix(in srgb, var(--ink) 50%, transparent); }
|
||||
.toast.error { background: var(--danger); color: #fff; }
|
||||
|
||||
/* ---------------------------------------------------------------- sheet (confirm dialog) */
|
||||
.sheet-backdrop { position: fixed; inset: 0; background: rgba(20, 18, 14, 0.45); display: flex; align-items: center; justify-content: center; z-index: 90; padding: 16px; }
|
||||
.sheet { background: var(--surface); border: 2px solid var(--ink); border-radius: 18px; box-shadow: 6px 6px 0 var(--ink); padding: 22px; width: min(420px, 100%); display: flex; flex-direction: column; gap: 14px; }
|
||||
.sheet:focus { outline: none; }
|
||||
|
||||
/* ---------------------------------------------------------------- responsive */
|
||||
@media (max-width: 960px) {
|
||||
.hero { grid-template-columns: 1fr; }
|
||||
.page { padding: 20px 16px; }
|
||||
.admin-layout { grid-template-columns: 1fr; }
|
||||
.admin-side { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 2px solid var(--ink); padding: 8px; }
|
||||
.admin-side .sep { display: none; }
|
||||
.admin-side a { white-space: nowrap; }
|
||||
.admin-main { padding: 16px; }
|
||||
}
|
||||
@media (max-width: 600px) {
|
||||
.site-header-inner { padding: 0 12px; gap: 10px; }
|
||||
.site-logo span { display: none; }
|
||||
.welcome { padding: 24px; }
|
||||
.welcome .bigLP { width: 170px; height: 170px; right: -60px; bottom: -70px; }
|
||||
.welcome .bigLP::after { inset: 60px; }
|
||||
.welcome .acts { margin-bottom: 60px; }
|
||||
.welcome h1 { font-size: 1.75rem; }
|
||||
.header-user-name { display: none; }
|
||||
}
|
||||
Reference in New Issue
Block a user