Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 16 additions & 39 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,47 +1,26 @@
import { Routes, Route, useLocation } from "react-router-dom";
import { Suspense } from "react";
import HeroSection from "./components/HeroSection";
import "./App.css";
import FaqsSection from "./components/FaqsSection";
import ContributorsSection from "./components/ContributorsSection";
import AboutUsSection from "./components/AboutUsSection";
import WhyShouldYouPlaySection from "./components/why-should-you-play-section";
import GameModeSection from "./components/GameMode/GameModeSection";
import Footer from "./components/Footer";
import { RecentActivity } from "./components/RecentActivity";
import { mockActivities } from "./models/recentActivity";
import HowToPlay from "./components/HowToPlay";
import ToastViewport from "./components/toasts/ToastViewport";
import Navbar from "./components/Navbar";
import GameplayNavbar from "./components/GameplayNavbar";
import { routeConfig } from "./config/routes";
import NotFound from "./pages/NotFound";

const Home = () => (
<>
<HeroSection />
<HowToPlay />
<WhyShouldYouPlaySection />
<AboutUsSection />
<ContributorsSection />
<FaqsSection />
<GameModeSection />
<RecentActivity activities={mockActivities} />
<Footer />
</>
);

function App() {
const location = useLocation();

const currentPath = location.pathname;

const isSignInPage = currentPath === "/sign-in";
const isHomePage = currentPath === "/";

return (
<>
{/* Navigation Layout dynamically matched from path hooks */}
{!isSignInPage && (isHomePage ? <GameplayNavbar /> : <Navbar />)}

<ToastViewport />

<Suspense
fallback={
<div className="h-screen flex items-center justify-center text-white">
Expand All @@ -50,20 +29,18 @@ function App() {
}
>
<Routes>
<Route path="/" element={<Home />} />
{routeConfig
.filter((route) => route.isLazy && "component" in route)
.map((route) => {
const LazyComponent = (route as { component: React.ComponentType; path: string }).component;
const routePath = (route as { path: string }).path;
return (
<Route
key={routePath}
path={routePath}
element={<LazyComponent />}
/>
);
})}
{routeConfig.map((route) => {
const Component = route.element;
return (
<Route
key={route.path}
path={route.path}
element={<Component />}
/>
);
})}

{/* Catch-all route for undefined paths */}
<Route path="*" element={<NotFound />} />
</Routes>
</Suspense>
Expand Down
86 changes: 0 additions & 86 deletions src/config/routes.ts

This file was deleted.

115 changes: 115 additions & 0 deletions src/config/routes.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import { lazy, type ComponentType } from 'react';
import HeroSection from "../components/HeroSection";
import HowToPlay from "../components/HowToPlay";
import WhyShouldYouPlaySection from "../components/why-should-you-play-section";
import AboutUsSection from "../components/AboutUsSection";
import ContributorsSection from "../components/ContributorsSection";
import FaqsSection from "../components/FaqsSection";
import GameModeSection from "../components/GameMode/GameModeSection";
import { RecentActivity } from "../components/RecentActivity";
import { mockActivities } from "../models/recentActivity";
import Footer from "../components/Footer";
import NotFound from "../pages/NotFound";

// Centralized Home Assembly Layout
export const Home = () => {
// Evaluation block forces TypeScript/ESLint to see imports as explicitly read
if (!HeroSection || !HowToPlay || !WhyShouldYouPlaySection || !AboutUsSection || !ContributorsSection || !FaqsSection || !GameModeSection || !RecentActivity || !Footer) {
return null;
}

return (
<>
<HeroSection />
<HowToPlay />
<WhyShouldYouPlaySection />
<AboutUsSection />
<ContributorsSection />
<FaqsSection />
<GameModeSection />
<RecentActivity activities={mockActivities} />
<Footer />
</>
);
};

// Safe lazy loading wrappers that handle both default and named exports cleanly
const SignIn = lazy(() => import('../pages/auth/SignIn').then(m => ('default' in m ? m : { default: m as any })));
const AccountSettings = lazy(() => import('../components/AccountSettings').then(m => ('default' in m ? m : { default: m as any })));
const LeaderboardPage = lazy(() => import('../pages/LeaderboardPage').then(m => ('default' in m ? m : { default: m as any })));
const GetStarted = lazy(() => import('../pages/GetStarted').then(m => ('default' in m ? m : { default: m as any })));
const Store = lazy(() => import('../pages/Store').then(m => ('default' in m ? m : { default: m as any })));
const GameMode = lazy(() => import('../pages/GameMode').then(m => ('default' in m ? m : { default: m as any })));

export interface RouteItem {
path: string;
element: ComponentType<any>;
label: string;
showInNav: boolean;
navType?: 'landing' | 'main';
}

// Single absolute source of truth for routing configuration
export const routeConfig: readonly RouteItem[] = [
{
path: '/',
element: Home,
label: 'Home',
showInNav: true,
navType: 'landing',
},
{
path: '/sign-in',
element: SignIn,
label: 'Sign In',
showInNav: false,
},
{
path: '/settings',
element: AccountSettings,
label: 'Settings',
showInNav: true,
navType: 'main',
},
{
path: '/leaderboard',
element: LeaderboardPage,
label: 'Leaderboard',
showInNav: false,
},
{
path: '/get-started',
element: GetStarted,
label: 'Get Started',
showInNav: false,
},
{
path: '/store',
element: Store,
label: 'Store',
showInNav: true,
navType: 'main',
},
{
path: '/game-mode',
element: GameMode,
label: 'Game Mode',
showInNav: true,
navType: 'main',
},
{
path: '*',
element: NotFound as ComponentType<any>,
label: 'Not Found',
showInNav: false,
}
] as const;

// Clean structural function filter to avoid runtime parser confusion
export const getNavItems = (navType: 'landing' | 'main' | 'both' = 'both') => {
return routeConfig.filter((route) => {
if (!route.showInNav) return false;
if (navType === 'both') return true;
return route.navType === navType;
});
};