feat(web): add app shell
This commit is contained in:
1 parent
39f3221640
commit
9fbb11c634
6 files changed
+344
No files matched your search
@@ -0,0 +1 @@
|
||||
/* App-specific styles — currently using Tailwind + daisyUI */
|
||||
@@ -0,0 +1,116 @@
|
||||
import { BrowserRouter, Link, Route, Routes } from 'react-router';
|
||||
import { useMsal } from '@azure/msal-react';
|
||||
import DevAuthSwitcher from './components/DevAuthSwitcher';
|
||||
import { DEFAULT_COMMUNITY_ID } from './config';
|
||||
import { useCommunity } from './api/hooks';
|
||||
import { isMsalConfigured } from './lib/auth/msal.config';
|
||||
import AuthCallbackPage from './pages/AuthCallback';
|
||||
import HomePage from './pages/HomePage';
|
||||
import LoginPage from './pages/Login';
|
||||
import MatchDetailPage from './pages/MatchDetailPage';
|
||||
import MatchTeamProgressPage from './pages/MatchTeamProgressPage';
|
||||
import AuctionPage from './pages/AuctionPage';
|
||||
import UserHistoryPage from './pages/UserHistoryPage';
|
||||
import CommunityInternalStatsPage from './pages/CommunityInternalStatsPage';
|
||||
import InternalMatchDetailPage from './pages/InternalMatchDetailPage';
|
||||
import LegacyImportPage from './pages/admin/LegacyImportPage';
|
||||
import LegacyMatchesPage from './pages/admin/LegacyMatchesPage';
|
||||
import MatchAdminPage from './pages/admin/MatchAdminPage';
|
||||
import TournamentCodesPage from './pages/admin/TournamentCodesPage';
|
||||
|
||||
function MsalHeaderActions() {
|
||||
const { accounts, instance } = useMsal();
|
||||
const account = instance.getActiveAccount() ?? accounts[0];
|
||||
|
||||
if (!account) {
|
||||
return (
|
||||
<Link className="btn btn-primary btn-xs px-3" to="/login">
|
||||
로그인
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-ghost btn-xs px-3"
|
||||
onClick={() => void instance.logoutRedirect()}
|
||||
>
|
||||
{account.name ?? account.username} 로그아웃
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
function App() {
|
||||
const communityQuery = useCommunity(DEFAULT_COMMUNITY_ID);
|
||||
const communityLabel = communityQuery.data?.name ?? 'LOLYMPUS';
|
||||
|
||||
return (
|
||||
<BrowserRouter>
|
||||
<div className="min-h-screen bg-base-100">
|
||||
<nav className="bg-base-100 border-b border-base-content/10 sticky top-0 z-50">
|
||||
<div className="max-w-5xl mx-auto px-4 sm:px-6 flex items-center justify-between h-11">
|
||||
<Link
|
||||
className="text-sm font-bold tracking-tight text-base-content"
|
||||
to="/"
|
||||
>
|
||||
{communityLabel}
|
||||
</Link>
|
||||
<div className="flex items-center gap-3">
|
||||
{DEFAULT_COMMUNITY_ID ? (
|
||||
<span className="text-[10px] uppercase tracking-wider text-base-content/25">
|
||||
API Live
|
||||
</span>
|
||||
) : (
|
||||
<span className="text-[10px] uppercase tracking-wider text-amber-500/70">
|
||||
Set `VITE_DEFAULT_COMMUNITY_ID`
|
||||
</span>
|
||||
)}
|
||||
{isMsalConfigured && <MsalHeaderActions />}
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<Routes>
|
||||
<Route path="/" element={<HomePage />} />
|
||||
<Route path="/login" element={<LoginPage />} />
|
||||
<Route path="/auth/callback" element={<AuthCallbackPage />} />
|
||||
<Route path="/match/:id" element={<MatchDetailPage />} />
|
||||
<Route
|
||||
path="/match/:id/team/:teamIndex"
|
||||
element={<MatchTeamProgressPage />}
|
||||
/>
|
||||
<Route path="/match/:id/auction" element={<AuctionPage />} />
|
||||
<Route path="/users/:userId/history" element={<UserHistoryPage />} />
|
||||
<Route
|
||||
path="/communities/:cid/internal-stats"
|
||||
element={<CommunityInternalStatsPage />}
|
||||
/>
|
||||
<Route
|
||||
path="/communities/:cid/internal-stats/match/:matchId"
|
||||
element={<InternalMatchDetailPage />}
|
||||
/>
|
||||
<Route
|
||||
path="/admin/communities/:cid/matches"
|
||||
element={<MatchAdminPage />}
|
||||
/>
|
||||
<Route
|
||||
path="/admin/communities/:cid/tournament-codes"
|
||||
element={<TournamentCodesPage />}
|
||||
/>
|
||||
<Route
|
||||
path="/admin/communities/:cid/legacy-import"
|
||||
element={<LegacyImportPage />}
|
||||
/>
|
||||
<Route
|
||||
path="/admin/communities/:cid/legacy-matches"
|
||||
element={<LegacyMatchesPage />}
|
||||
/>
|
||||
</Routes>
|
||||
<DevAuthSwitcher />
|
||||
</div>
|
||||
</BrowserRouter>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
@@ -0,0 +1,58 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { setAuthUserId, useAuthUserId } from '../config';
|
||||
|
||||
export default function DevAuthSwitcher() {
|
||||
const authUserId = useAuthUserId();
|
||||
const queryClient = useQueryClient();
|
||||
const [inputValue, setInputValue] = useState(authUserId ?? '');
|
||||
|
||||
useEffect(() => {
|
||||
setInputValue(authUserId ?? '');
|
||||
}, [authUserId]);
|
||||
|
||||
if (!import.meta.env.DEV) {
|
||||
return null;
|
||||
}
|
||||
|
||||
function updateAuthUserId(nextValue: string | null) {
|
||||
setAuthUserId(nextValue);
|
||||
void queryClient.invalidateQueries();
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="fixed right-4 bottom-4 z-50 w-72 border border-base-content/10 bg-base-100/95 backdrop-blur px-3 py-3 shadow-xl">
|
||||
<div className="text-[10px] font-bold uppercase tracking-wider text-base-content/35">
|
||||
Dev Auth
|
||||
</div>
|
||||
<div className="mt-2 text-[11px] text-base-content/45">
|
||||
X-Auth-User-Id
|
||||
</div>
|
||||
<input
|
||||
value={inputValue}
|
||||
onChange={(event) => setInputValue(event.target.value)}
|
||||
placeholder="Mongo User ID"
|
||||
className="mt-1 w-full border border-base-content/10 bg-transparent px-2 py-2 text-xs text-base-content focus:outline-none focus:border-primary/30"
|
||||
/>
|
||||
<div className="mt-2 flex items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-primary btn-xs px-3"
|
||||
onClick={() => updateAuthUserId(inputValue)}
|
||||
>
|
||||
Set
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-ghost btn-xs px-3"
|
||||
onClick={() => updateAuthUserId(null)}
|
||||
>
|
||||
Clear
|
||||
</button>
|
||||
</div>
|
||||
<div className="mt-2 text-[10px] text-base-content/35 break-all">
|
||||
현재값: {authUserId ?? '없음'}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
import { useSyncExternalStore } from 'react';
|
||||
|
||||
const AUTH_USER_ID_STORAGE_KEY = 'lolympus.authUserId';
|
||||
const DEV_CAPTAIN_TEAM_INDEX_STORAGE_KEY = 'lolympus.devCaptainTeamIndex';
|
||||
const LEGACY_DEV_CAPTAIN_SIDE_STORAGE_KEY = 'lolympus.devCaptainSide';
|
||||
const AUTH_USER_CHANGED_EVENT = 'lolympus:auth-user-changed';
|
||||
const CAPTAIN_SIDE_CHANGED_EVENT = 'lolympus:captain-side-changed';
|
||||
|
||||
export const API_BASE_URL = (
|
||||
import.meta.env.VITE_API_BASE_URL ?? 'http://localhost:3000'
|
||||
).replace(/\/$/, '');
|
||||
|
||||
export const DEFAULT_COMMUNITY_ID = (
|
||||
import.meta.env.VITE_DEFAULT_COMMUNITY_ID ?? ''
|
||||
).trim();
|
||||
|
||||
function dispatchWindowEvent(eventName: string) {
|
||||
if (typeof window === 'undefined') return;
|
||||
window.dispatchEvent(new Event(eventName));
|
||||
}
|
||||
|
||||
function subscribeToWindowChanges(eventName: string, callback: () => void) {
|
||||
if (typeof window === 'undefined') {
|
||||
return () => undefined;
|
||||
}
|
||||
|
||||
const handleChange = () => callback();
|
||||
window.addEventListener(eventName, handleChange);
|
||||
window.addEventListener('storage', handleChange);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener(eventName, handleChange);
|
||||
window.removeEventListener('storage', handleChange);
|
||||
};
|
||||
}
|
||||
|
||||
export function getAuthUserId(): string | null {
|
||||
if (!import.meta.env.DEV) return null;
|
||||
if (typeof window === 'undefined') return null;
|
||||
const value = window.localStorage.getItem(AUTH_USER_ID_STORAGE_KEY)?.trim();
|
||||
return value ? value : null;
|
||||
}
|
||||
|
||||
export function setAuthUserId(userId: string | null) {
|
||||
if (!import.meta.env.DEV) return;
|
||||
if (typeof window === 'undefined') return;
|
||||
|
||||
if (!userId?.trim()) {
|
||||
window.localStorage.removeItem(AUTH_USER_ID_STORAGE_KEY);
|
||||
} else {
|
||||
window.localStorage.setItem(AUTH_USER_ID_STORAGE_KEY, userId.trim());
|
||||
}
|
||||
|
||||
dispatchWindowEvent(AUTH_USER_CHANGED_EVENT);
|
||||
}
|
||||
|
||||
export function getDevCaptainTeamIndex(): number | null {
|
||||
if (typeof window === 'undefined') return null;
|
||||
|
||||
const value = window.localStorage.getItem(DEV_CAPTAIN_TEAM_INDEX_STORAGE_KEY);
|
||||
const parsed = Number(value);
|
||||
if (Number.isInteger(parsed) && parsed > 0) return parsed;
|
||||
|
||||
const legacy = window.localStorage.getItem(LEGACY_DEV_CAPTAIN_SIDE_STORAGE_KEY);
|
||||
if (legacy === 'blue') return 1;
|
||||
if (legacy === 'red') return 2;
|
||||
return null;
|
||||
}
|
||||
|
||||
export function setDevCaptainTeamIndex(teamIndex: number | null) {
|
||||
if (typeof window === 'undefined') return;
|
||||
if (teamIndex && Number.isInteger(teamIndex) && teamIndex > 0) {
|
||||
window.localStorage.setItem(
|
||||
DEV_CAPTAIN_TEAM_INDEX_STORAGE_KEY,
|
||||
String(teamIndex),
|
||||
);
|
||||
} else {
|
||||
window.localStorage.removeItem(DEV_CAPTAIN_TEAM_INDEX_STORAGE_KEY);
|
||||
}
|
||||
dispatchWindowEvent(CAPTAIN_SIDE_CHANGED_EVENT);
|
||||
}
|
||||
|
||||
export function useAuthUserId(): string | null {
|
||||
return useSyncExternalStore<string | null>(
|
||||
(callback) => subscribeToWindowChanges(AUTH_USER_CHANGED_EVENT, callback),
|
||||
getAuthUserId,
|
||||
() => null,
|
||||
);
|
||||
}
|
||||
|
||||
export function useDevCaptainTeamIndex(): number | null {
|
||||
return useSyncExternalStore<number | null>(
|
||||
(callback) => subscribeToWindowChanges(CAPTAIN_SIDE_CHANGED_EVENT, callback),
|
||||
getDevCaptainTeamIndex,
|
||||
() => null,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
@import url("https://fonts.googleapis.com/css2?family=Asta+Sans:wght@300..800&family=Gamja+Flower&display=swap");
|
||||
|
||||
@import "tailwindcss";
|
||||
@plugin "daisyui" {
|
||||
themes:
|
||||
light --default,
|
||||
dark --prefersdark;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
font-family:
|
||||
"Asta Sans",
|
||||
-apple-system,
|
||||
BlinkMacSystemFont,
|
||||
system-ui,
|
||||
Roboto,
|
||||
"Helvetica Neue",
|
||||
"Segoe UI",
|
||||
"Apple SD Gothic Neo",
|
||||
"Noto Sans KR",
|
||||
"Malgun Gothic",
|
||||
"Apple Color Emoji",
|
||||
"Segoe UI Emoji",
|
||||
"Segoe UI Symbol",
|
||||
sans-serif;
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
/* poro.gg style: 모든 모서리 각지게 */
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
border-radius: 0 !important;
|
||||
}
|
||||
|
||||
/* daisyUI badge만 살짝 둥글게 (pill 형태) */
|
||||
.badge {
|
||||
border-radius: 2px !important;
|
||||
}
|
||||
|
||||
/* 버튼도 각지게 */
|
||||
.btn {
|
||||
border-radius: 0 !important;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { StrictMode } from 'react';
|
||||
import { createRoot } from 'react-dom/client';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import './index.css';
|
||||
import App from './App.tsx';
|
||||
import { MsalAppProvider } from './lib/auth/MsalAppProvider.tsx';
|
||||
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
staleTime: 10 * 1000,
|
||||
gcTime: 5 * 60 * 1000,
|
||||
refetchOnWindowFocus: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<StrictMode>
|
||||
<MsalAppProvider>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<App />
|
||||
</QueryClientProvider>
|
||||
</MsalAppProvider>
|
||||
</StrictMode>,
|
||||
);
|
||||
Reference in new issue
Block a user