132 lines
4.8 KiB
TypeScript
132 lines
4.8 KiB
TypeScript
import { useEffect } from 'react';
|
|
import { Navigate, Route, Routes } from 'react-router';
|
|
import { DictionaryPage } from './pages/DictionaryPage';
|
|
import { MotionConfig } from 'framer-motion';
|
|
import { AuthProvider, DataProvider, StatusProvider, useAuth, useStatus } from './store/app';
|
|
import { useReducedMotion } from './store/settings';
|
|
import { player } from './store/player';
|
|
import { resumeAudio } from './lib/audio';
|
|
import { Header } from './components/Header';
|
|
import { LockOverlay } from './components/LockOverlay';
|
|
import { LoginPage } from './components/LoginPage';
|
|
import { PlayerBar } from './components/PlayerBar';
|
|
import { UttMenuHost } from './components/UttMenu';
|
|
import { Spinner } from './components/common';
|
|
import { TimelinePage } from './pages/TimelinePage';
|
|
import { MatchPage } from './pages/MatchPage';
|
|
import { CulpritPage } from './pages/CulpritPage';
|
|
import { MatchesPage, UserPage, UsersPage } from './pages/UserPages';
|
|
import { LogsPage } from './pages/LogsPage';
|
|
import { RecordsPage } from './pages/RecordsPage';
|
|
import { installErrorReporting } from './lib/report';
|
|
import { useLocation } from 'react-router';
|
|
|
|
/** Space 재생/일시정지 · ←/→ 이전/다음 발화 · / 검색 */
|
|
function useShortcuts() {
|
|
useEffect(() => {
|
|
const onKey = (e: KeyboardEvent) => {
|
|
const t = e.target as HTMLElement;
|
|
const typing = t.isContentEditable || ['INPUT', 'TEXTAREA', 'SELECT'].includes(t.tagName);
|
|
if (e.ctrlKey || e.metaKey || e.altKey) return;
|
|
if (e.key === '/' && !typing) {
|
|
e.preventDefault();
|
|
document.getElementById('gvr-search')?.focus();
|
|
return;
|
|
}
|
|
if (typing) return;
|
|
if (e.key === ' ' || e.code === 'Space') {
|
|
if (t.tagName === 'BUTTON' || t.tagName === 'A') t.blur();
|
|
e.preventDefault();
|
|
player.toggle();
|
|
} else if (e.key === 'ArrowRight') {
|
|
e.preventDefault();
|
|
player.next();
|
|
} else if (e.key === 'ArrowLeft') {
|
|
e.preventDefault();
|
|
player.prev();
|
|
}
|
|
};
|
|
window.addEventListener('keydown', onKey);
|
|
// 첫 사용자 제스처에서 AudioContext 를 깨워 효과음이 바로 나게
|
|
const wake = () => resumeAudio();
|
|
window.addEventListener('pointerdown', wake, { once: true });
|
|
return () => {
|
|
window.removeEventListener('keydown', onKey);
|
|
window.removeEventListener('pointerdown', wake);
|
|
};
|
|
}, []);
|
|
}
|
|
|
|
function Shell() {
|
|
const { locked, epoch } = useStatus();
|
|
useShortcuts();
|
|
return (
|
|
<div className={`shell${locked ? ' is-locked' : ''}`}>
|
|
<div className="app" aria-hidden={locked || undefined}>
|
|
<Header />
|
|
<div className="content" key={epoch}>
|
|
<Routes>
|
|
<Route path="/" element={<TimelinePage />} />
|
|
<Route path="/matches" element={<MatchesPage />} />
|
|
<Route path="/records" element={<RecordsPage />} />
|
|
<Route path="/matches/:id" element={<MatchPage />} />
|
|
<Route path="/users" element={<UsersPage />} />
|
|
<Route path="/users/:id" element={<UserPage />} />
|
|
<Route path="/dictionary" element={<DictionaryPage />} />
|
|
<Route path="/culprit" element={<CulpritPage />} />
|
|
<Route path="/culprit/:id" element={<CulpritPage />} />
|
|
<Route path="*" element={<Navigate to="/" replace />} />
|
|
</Routes>
|
|
</div>
|
|
<PlayerBar />
|
|
</div>
|
|
<UttMenuHost />
|
|
<LockOverlay />
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function Gate() {
|
|
const { auth } = useAuth();
|
|
const loc = useLocation();
|
|
useEffect(() => {
|
|
if (auth.status === 'ok') installErrorReporting();
|
|
}, [auth.status]);
|
|
if (auth.status === 'loading')
|
|
return (
|
|
<div className="boot">
|
|
<img src="/icon-192.png" alt="" />
|
|
<Spinner label="겜녹이 여는 중" />
|
|
</div>
|
|
);
|
|
if (auth.status === 'anon') {
|
|
// 서버가 OAuth 결과를 ?login=... 으로 알려 준다
|
|
const q = new URLSearchParams(window.location.search).get('login');
|
|
return <LoginPage notMember={q === 'not_member'} error={q === 'error' || q === 'invalid' ? '로그인 중 문제가 생겼습니다. 다시 시도해 주세요.' : undefined} />;
|
|
}
|
|
if (auth.status === 'not_member') return <LoginPage notMember />;
|
|
// 사이트 로그: 게임 PC 연결(잠금)과 상관없이 연다
|
|
if (loc.pathname === '/logs') return <LogsPage />;
|
|
return (
|
|
<StatusProvider>
|
|
<DataProvider>
|
|
<Shell />
|
|
</DataProvider>
|
|
</StatusProvider>
|
|
);
|
|
}
|
|
|
|
export function App() {
|
|
const reduce = useReducedMotion();
|
|
useEffect(() => {
|
|
document.documentElement.classList.toggle('reduce-motion', reduce);
|
|
}, [reduce]);
|
|
return (
|
|
<MotionConfig reducedMotion={reduce ? 'always' : 'never'}>
|
|
<AuthProvider>
|
|
<Gate />
|
|
</AuthProvider>
|
|
</MotionConfig>
|
|
);
|
|
}
|