From 9fbb11c634bd6b00baf183cb24e06b495650ebec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EB=8B=A4=ED=98=84=20=28Dahyeon=20Park=29?= Date: Sat, 11 Apr 2026 00:58:00 +0900 Subject: [PATCH] feat(web): add app shell --- apps/web/src/App.css | 1 + apps/web/src/App.tsx | 116 ++++++++++++++++++++ apps/web/src/components/DevAuthSwitcher.tsx | 58 ++++++++++ apps/web/src/config.ts | 97 ++++++++++++++++ apps/web/src/index.css | 46 ++++++++ apps/web/src/main.tsx | 26 +++++ 6 files changed, 344 insertions(+) create mode 100644 apps/web/src/App.css create mode 100644 apps/web/src/App.tsx create mode 100644 apps/web/src/components/DevAuthSwitcher.tsx create mode 100644 apps/web/src/config.ts create mode 100644 apps/web/src/index.css create mode 100644 apps/web/src/main.tsx diff --git a/apps/web/src/App.css b/apps/web/src/App.css new file mode 100644 index 00000000..e00a71c3 --- /dev/null +++ b/apps/web/src/App.css @@ -0,0 +1 @@ +/* App-specific styles — currently using Tailwind + daisyUI */ diff --git a/apps/web/src/App.tsx b/apps/web/src/App.tsx new file mode 100644 index 00000000..c5c84037 --- /dev/null +++ b/apps/web/src/App.tsx @@ -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 ( + + 로그인 + + ); + } + + return ( + + ); +} + +function App() { + const communityQuery = useCommunity(DEFAULT_COMMUNITY_ID); + const communityLabel = communityQuery.data?.name ?? 'LOLYMPUS'; + + return ( + +
+ + + + } /> + } /> + } /> + } /> + } + /> + } /> + } /> + } + /> + } + /> + } + /> + } + /> + } + /> + } + /> + + +
+
+ ); +} + +export default App; diff --git a/apps/web/src/components/DevAuthSwitcher.tsx b/apps/web/src/components/DevAuthSwitcher.tsx new file mode 100644 index 00000000..29f25143 --- /dev/null +++ b/apps/web/src/components/DevAuthSwitcher.tsx @@ -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 ( +
+
+ Dev Auth +
+
+ X-Auth-User-Id +
+ 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" + /> +
+ + +
+
+ 현재값: {authUserId ?? '없음'} +
+
+ ); +} diff --git a/apps/web/src/config.ts b/apps/web/src/config.ts new file mode 100644 index 00000000..2e0381ca --- /dev/null +++ b/apps/web/src/config.ts @@ -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( + (callback) => subscribeToWindowChanges(AUTH_USER_CHANGED_EVENT, callback), + getAuthUserId, + () => null, + ); +} + +export function useDevCaptainTeamIndex(): number | null { + return useSyncExternalStore( + (callback) => subscribeToWindowChanges(CAPTAIN_SIDE_CHANGED_EVENT, callback), + getDevCaptainTeamIndex, + () => null, + ); +} diff --git a/apps/web/src/index.css b/apps/web/src/index.css new file mode 100644 index 00000000..45ade146 --- /dev/null +++ b/apps/web/src/index.css @@ -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; +} diff --git a/apps/web/src/main.tsx b/apps/web/src/main.tsx new file mode 100644 index 00000000..5487c4df --- /dev/null +++ b/apps/web/src/main.tsx @@ -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( + + + + + + + , +);