Files
lolympus-tournament-support/apps/web/src/App.tsx
T

384 lines
13 KiB
TypeScript

import {
BrowserRouter,
Link,
matchPath,
Navigate,
Route,
Routes,
useLocation,
} from "react-router";
import type { ReactNode } from "react";
import { useMsal } from "@azure/msal-react";
import { LogOut, Moon, Sun } from "lucide-react";
import DevAuthSwitcher from "./components/DevAuthSwitcher";
import { DEFAULT_COMMUNITY_ID, setTheme, useTheme } from "./config";
import { useCommunity, useMatch, useMe } 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 MatchGameDetailPage from "./pages/MatchGameDetailPage";
import MatchTeamProgressPage from "./pages/MatchTeamProgressPage";
import AuctionPage from "./pages/AuctionPage";
import UserHistoryPage from "./pages/UserHistoryPage";
import CommunityInternalStatsPage from "./pages/CommunityInternalStatsPage";
import CommunityInternalPlayerPage from "./pages/CommunityInternalPlayerPage";
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";
import { PlainPage, Tooltip, pageWidthClass } from "./ui";
import "./components/app-header.css";
const NAV_ICON_BUTTON_CLASS =
"lts-header-icon-button";
function MsalHeaderActions() {
const { accounts, instance } = useMsal();
const account = instance.getActiveAccount() ?? accounts[0];
if (!account) {
return (
<Link
className="inline-flex h-8 items-center whitespace-nowrap rounded-full border border-line px-3 text-[13px] font-medium text-content-muted transition-colors hover:bg-sunken hover:text-content"
to="/login"
>
로그인
</Link>
);
}
const name = account.name ?? account.username;
return (
<div className="flex min-w-0 items-center gap-1">
<span className="hidden max-w-40 truncate text-sm font-medium text-content-muted lg:block">
{name}
</span>
<Tooltip content="로그아웃" placement="below">
<button
type="button"
className={NAV_ICON_BUTTON_CLASS}
aria-label={`${name} 로그아웃`}
onClick={() => void instance.logoutRedirect()}
>
<LogOut className="size-[18px]" aria-hidden="true" />
</button>
</Tooltip>
</div>
);
}
function ThemeToggle() {
const theme = useTheme();
const nextTheme = theme === "light" ? "dark" : "light";
const label =
nextTheme === "dark" ? "다크 테마로 전환" : "라이트 테마로 전환";
const Icon = nextTheme === "dark" ? Moon : Sun;
return (
<Tooltip content={label} placement="below">
<button
type="button"
className={`${NAV_ICON_BUTTON_CLASS} lts-header-theme-toggle`}
aria-label={label}
onClick={() => setTheme(nextTheme)}
>
<Icon className="size-[18px]" aria-hidden="true" />
</button>
</Tooltip>
);
}
function PrimaryNavLink({
to,
sectionPaths = [],
children,
}: {
to: string;
sectionPaths?: string[];
children: ReactNode;
}) {
const { pathname } = useLocation();
const current = matchPath(to, pathname)
? "page"
: sectionPaths.some((pattern) => matchPath(pattern, pathname))
? "location"
: undefined;
return (
<Link
to={to}
aria-current={current}
className="lts-primary-nav-link"
>
{children}
</Link>
);
}
function AppHeader() {
const { pathname } = useLocation();
const matchId = matchPath("/match/:id/*", pathname)?.params.id;
const matchQuery = useMatch(matchId);
const isTournamentMatch = matchQuery.data?.eventType === "tournament";
const communityQuery = useCommunity(DEFAULT_COMMUNITY_ID);
const meQuery = useMe();
const communityLabel = communityQuery.data?.name ?? "LOLYMPUS";
const role = meQuery.data?.memberships.find(
(membership) => membership.community?._id === DEFAULT_COMMUNITY_ID,
)?.user?.role;
const canManage = role === "owner" || role === "admin";
const statsPath = `/communities/${DEFAULT_COMMUNITY_ID}/internal-stats`;
const adminPath = `/admin/communities/${DEFAULT_COMMUNITY_ID}`;
return (
<header
className={`lts-app-header${DEFAULT_COMMUNITY_ID ? "" : " lts-app-header--without-nav"}`}
>
<div className="lts-app-header-inner">
<Link
className="lts-header-brand"
to="/"
aria-label={`${communityLabel} 홈`}
>
<span className="lts-header-brand-name">{communityLabel}</span>
<span className="lts-header-brand-tagline">TOURNAMENT</span>
</Link>
{DEFAULT_COMMUNITY_ID && (
<nav aria-label="주 메뉴" className="lts-primary-nav">
<PrimaryNavLink to="/">홈</PrimaryNavLink>
<PrimaryNavLink
to="/inhouse"
sectionPaths={isTournamentMatch ? undefined : ["/match/*"]}
>
내전
</PrimaryNavLink>
<PrimaryNavLink
to="/tournaments"
sectionPaths={isTournamentMatch ? ["/match/*"] : undefined}
>
멸망전
</PrimaryNavLink>
<PrimaryNavLink
to={statsPath}
sectionPaths={[`${statsPath}/*`, "/users/:userId/history"]}
>
전적
</PrimaryNavLink>
{canManage && (
<PrimaryNavLink
to={`${adminPath}/matches`}
sectionPaths={[`${adminPath}/*`]}
>
운영
</PrimaryNavLink>
)}
</nav>
)}
<div className="lts-header-actions">
<ThemeToggle />
{isMsalConfigured && <MsalHeaderActions />}
</div>
</div>
</header>
);
}
function AppFooter() {
return (
<footer className="border-t border-line">
<div
className={`${pageWidthClass("xl")} flex flex-col items-center gap-4 py-10 text-center text-xs text-content-subtle sm:py-12`}
>
<nav
aria-label="정책"
className="flex flex-wrap items-center justify-center gap-x-6 gap-y-2 font-semibold text-content-muted"
>
<Link to="/terms" className="inline-flex min-h-8 items-center hover:text-content">
서비스 이용약관
</Link>
<Link to="/privacy" className="inline-flex min-h-8 items-center font-bold hover:text-content">
개인정보처리방침
</Link>
</nav>
<div className="w-full max-w-4xl space-y-1 leading-relaxed">
<p className="text-balance">
LOLYMPUS is not endorsed by Riot Games and does not reflect the views
or opinions of Riot Games or anyone officially involved in producing
or managing League of Legends. League of Legends and Riot Games are
trademarks or registered trademarks of Riot Games, Inc. League of
Legends © Riot Games, Inc.
</p>
<p>© 2026 LOLYMPUS.</p>
</div>
</div>
</footer>
);
}
function LegalPage({
title,
children,
}: {
title: string;
children: ReactNode;
}) {
return (
<PlainPage width="md" className="py-12">
<h1 className="text-2xl font-extrabold">{title}</h1>
<div className="lts-panel mt-6 space-y-4 p-6 text-sm leading-7 text-content-muted">
{children}
</div>
</PlainPage>
);
}
function NotFoundPage() {
return (
<PlainPage width="md" className="py-24 text-center">
<p className="tabular text-5xl font-extrabold text-content-disabled">
404
</p>
<h1 className="mt-4 text-xl font-bold">
페이지를 찾을 수 없습니다
</h1>
<p className="mt-2 text-sm text-content-muted">
주소가 바뀌었거나 삭제된 내전일 수 있습니다.
</p>
<Link
to="/inhouse"
className="mt-6 inline-flex h-10 items-center rounded-field bg-primary px-5 text-sm font-bold text-primary-content"
>
내전 목록으로
</Link>
</PlainPage>
);
}
function HomeRoute() {
const { search, hash } = useLocation();
const params = new URLSearchParams(search);
if (params.get("history") === "all") {
params.delete("history");
return (
<Navigate
replace
to={{ pathname: "/inhouse", search: params.toString(), hash }}
/>
);
}
return <HomePage />;
}
function App() {
return (
<BrowserRouter>
<div
className={`lts-app-shell flex min-h-screen flex-col bg-body ${DEFAULT_COMMUNITY_ID ? "" : "lts-app-shell--without-nav"}`}
>
<AppHeader />
<div className="flex-1">
<Routes>
<Route path="/" element={<HomeRoute />} />
<Route
path="/inhouse"
element={<HomePage key="inhouse" eventType="inhouse" />}
/>
<Route
path="/tournaments"
element={<HomePage key="tournament" eventType="tournament" />}
/>
<Route path="/login" element={<LoginPage />} />
<Route path="/auth/callback" element={<AuthCallbackPage />} />
<Route path="/match/:id" element={<MatchDetailPage />} />
<Route
path="/match/:id/game/:gameNumber"
element={<MatchGameDetailPage />}
/>
<Route path="/match/:id/team" 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/players/:userId" element={<CommunityInternalPlayerPage />} />
<Route
path="/communities/:cid/internal-stats/match/:matchId"
element={<InternalMatchDetailPage />}
/>
<Route
path="/communities/:cid/internal-stats/match/:matchId/game/:gameNumber"
element={<MatchGameDetailPage />}
/>
<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 />}
/>
<Route
path="/terms"
element={
<LegalPage title="서비스 이용약관">
<p>
This service is provided for community tournament support,
including match scheduling, participation management, team
organization, and related statistics.
</p>
<p>
By using this service, users agree not to interfere with
service operation, misuse community data, or submit content
that violates applicable laws or community rules.
</p>
</LegalPage>
}
/>
<Route
path="/privacy"
element={
<LegalPage title="개인정보처리방침">
<p>
This service processes account, profile, match
participation, team, and authentication data only as needed
to operate community tournament features.
</p>
<p>
Users may request access, correction, or deletion of their
personal data through the service administrator, subject to
records that must be retained for service integrity or legal
obligations.
</p>
</LegalPage>
}
/>
<Route path="*" element={<NotFoundPage />} />
</Routes>
</div>
<AppFooter />
<DevAuthSwitcher />
</div>
</BrowserRouter>
);
}
export default App;