Public Access
109 lines
5.4 KiB
React
109 lines
5.4 KiB
React
import {Link, Route, Routes, useLocation, useNavigate} from 'react-router-dom';
|
|
import {useTranslation} from 'react-i18next';
|
|
import {useEffect} from 'react';
|
|
|
|
import LandingPage from './pages/LandingPage';
|
|
import LoginPage from './pages/LoginPage';
|
|
import ImprintPage from './pages/ImprintPage';
|
|
import Dashboard from "./pages/Dashboard.jsx";
|
|
import RegistrationPage from './pages/RegistrationPage.jsx';
|
|
import SettingsPage from './pages/SettingsPage.jsx';
|
|
import AdminHintsPage from './pages/AdminHintsPage.jsx';
|
|
import AdminBroadcastPage from './pages/AdminBroadcastPage.jsx';
|
|
import AdminNewsPage from './pages/AdminNewsPage.jsx';
|
|
import WhatsNewPage from './pages/WhatsNewPage.jsx';
|
|
import WelcomePage from './pages/WelcomePage.jsx';
|
|
import WelcomeGate from './components/WelcomeGate.jsx';
|
|
import AdminUsersPage from './pages/AdminUsersPage.jsx';
|
|
import GameLibrary from './pages/GameLibrary.jsx';
|
|
import GameDetail from './pages/GameDetail.jsx';
|
|
import WishlistPage from './pages/WishlistPage.jsx';
|
|
import PlayNextPage from './pages/PlayNextPage.jsx';
|
|
import StatsPage from './pages/StatsPage.jsx';
|
|
import ImportPage from './pages/ImportPage.jsx';
|
|
import PointsPage from './pages/PointsPage.jsx';
|
|
import PublicProfilePage from './pages/PublicProfilePage.jsx';
|
|
import AppHeader from './components/AppHeader.jsx';
|
|
import RequireSession from './components/RequireSession.jsx';
|
|
import {Toaster} from '@/components/ui/sonner';
|
|
import {TooltipProvider} from '@/components/ui/tooltip';
|
|
import PageBackground from './components/PageBackground.jsx';
|
|
import {usePreferences} from './context/PreferencesContext.jsx';
|
|
import {backgroundEffect} from './utils/rewards.js';
|
|
import {clearSession} from './utils/auth.js';
|
|
import useSession from './hooks/useSession.js';
|
|
import {UnsavedChangesGuard} from './hooks/useUnsavedChanges.js';
|
|
import {logout} from './utils/api.js';
|
|
|
|
function App() {
|
|
const {t} = useTranslation();
|
|
const {active: isAuthenticated} = useSession();
|
|
const {appearance, equipped, syncPreferences} = usePreferences();
|
|
|
|
// Hooks for routing
|
|
const navigate = useNavigate();
|
|
const location = useLocation();
|
|
|
|
// On login and on page load; the cached look shows until Auth answers.
|
|
useEffect(() => {
|
|
if (isAuthenticated) syncPreferences();
|
|
}, [isAuthenticated, syncPreferences]);
|
|
|
|
// Waits for Auth: a late logout answer would clear the cookies of a login that came after it.
|
|
const handleLogout = async () => {
|
|
await logout();
|
|
clearSession();
|
|
navigate('/login');
|
|
};
|
|
|
|
return (
|
|
<TooltipProvider>
|
|
{/* isolate: the background layer sits behind the content but in front of this div's own background. */}
|
|
<div className="isolate min-h-screen flex flex-col bg-background text-foreground font-sans">
|
|
{/* A public profile shows the owner's background instead. */}
|
|
{isAuthenticated && !location.pathname.startsWith('/u/') && (
|
|
<PageBackground appid={appearance.backgroundAppid} effect={backgroundEffect(equipped)}/>
|
|
)}
|
|
<AppHeader isAuthenticated={isAuthenticated} onLogout={handleLogout}/>
|
|
|
|
<main className="grow flex flex-col">
|
|
<Routes>
|
|
<Route path="/" element={<LandingPage/>}/>
|
|
<Route path="/login" element={<LoginPage/>}/>
|
|
<Route path="/register" element={<RegistrationPage/>}/>
|
|
<Route element={<RequireSession/>}>
|
|
<Route path="/dashboard" element={<WelcomeGate><Dashboard/></WelcomeGate>}/>
|
|
<Route path="/library" element={<GameLibrary/>}/>
|
|
<Route path="/library/:appid" element={<GameDetail/>}/>
|
|
<Route path="/wishlist" element={<WishlistPage/>}/>
|
|
<Route path="/play-next" element={<PlayNextPage/>}/>
|
|
<Route path="/stats" element={<StatsPage/>}/>
|
|
<Route path="/import" element={<ImportPage/>}/>
|
|
<Route path="/points" element={<PointsPage/>}/>
|
|
<Route path="/settings" element={<SettingsPage/>}/>
|
|
<Route path="/whats-new" element={<WhatsNewPage/>}/>
|
|
<Route path="/welcome" element={<WelcomePage/>}/>
|
|
<Route path="/admin/users" element={<AdminUsersPage/>}/>
|
|
<Route path="/admin/hints" element={<AdminHintsPage/>}/>
|
|
<Route path="/admin/news" element={<AdminNewsPage/>}/>
|
|
<Route path="/admin/broadcasts" element={<AdminBroadcastPage/>}/>
|
|
</Route>
|
|
<Route path="/u/:name" element={<PublicProfilePage/>}/>
|
|
<Route path="/impressum" element={<ImprintPage/>}/>
|
|
</Routes>
|
|
</main>
|
|
|
|
<footer className="border-t py-6 text-center text-sm text-muted-foreground">
|
|
<Link to="/impressum" className="font-medium hover:text-foreground transition-colors">
|
|
{t('IMPRINT.TITLE')}
|
|
</Link>
|
|
</footer>
|
|
</div>
|
|
<UnsavedChangesGuard/>
|
|
<Toaster richColors position="bottom-right"/>
|
|
</TooltipProvider>
|
|
);
|
|
}
|
|
|
|
export default App;
|