degmods.com/src/routes/index.tsx

159 lines
4.2 KiB
TypeScript

import { createBrowserRouter } from 'react-router-dom'
import { NDKContextType } from 'contexts/NDKContext'
import { Layout } from 'layout'
import { SearchPage } from '../pages/search'
import { AboutPage } from '../pages/about'
import { GamesPage } from '../pages/games'
import { HomePage } from '../pages/home'
import { ModPage } from '../pages/mod'
import { ModsPage } from '../pages/mods'
import { ProfilePage } from '../pages/profile'
import { SettingsPage } from '../pages/settings'
import { SubmitModPage } from '../pages/submitMod'
import { GamePage } from '../pages/game'
import { NotFoundPage } from '../pages/404'
import { FeedLayout } from '../layout/feed'
import { FeedPage } from '../pages/feed'
import { NotificationsPage } from '../pages/notifications'
import { WritePage } from '../pages/write'
import { writeRouteAction } from '../pages/write/action'
import { BlogsPage } from 'pages/blogs'
import { BlogPage } from 'pages/blog'
import { blogRouteLoader } from 'pages/blog/loader'
import { blogsRouteLoader } from 'pages/blogs/loader'
export const appRoutes = {
index: '/',
home: '/',
games: '/games',
game: '/game/:name',
mods: '/mods',
mod: '/mod/:naddr',
about: '/about',
blogs: '/blog',
blog: '/blog/:naddr',
submitMod: '/submit-mod',
editMod: '/edit-mod/:naddr',
write: '/write',
search: '/search',
settingsProfile: '/settings-profile',
settingsRelays: '/settings-relays',
settingsPreferences: '/settings-preferences',
settingsAdmin: '/settings-admin',
profile: '/profile/:nprofile?',
feed: '/feed',
notifications: '/notifications'
}
export const getGamePageRoute = (name: string) =>
appRoutes.game.replace(':name', name)
export const getModPageRoute = (eventId: string) =>
appRoutes.mod.replace(':naddr', eventId)
export const getModsEditPageRoute = (eventId: string) =>
appRoutes.editMod.replace(':naddr', eventId)
export const getBlogPageRoute = (eventId: string) =>
appRoutes.blog.replace(':naddr', eventId)
export const getProfilePageRoute = (nprofile: string) =>
appRoutes.profile.replace(':nprofile', nprofile)
export const routerWithNdkContext = (context: NDKContextType) =>
createBrowserRouter([
{
element: <Layout />,
children: [
{
path: appRoutes.index,
element: <HomePage />
},
{
path: appRoutes.games,
element: <GamesPage />
},
{
path: appRoutes.game,
element: <GamePage />
},
{
path: appRoutes.mods,
element: <ModsPage />
},
{
path: appRoutes.mod,
element: <ModPage />
},
{
path: appRoutes.about,
element: <AboutPage />
},
{
path: appRoutes.blogs,
element: <BlogsPage />,
loader: blogsRouteLoader(context)
},
{
path: appRoutes.blog,
element: <BlogPage />,
loader: blogRouteLoader(context)
},
{
path: appRoutes.submitMod,
element: <SubmitModPage />
},
{
path: appRoutes.editMod,
element: <SubmitModPage />
},
{
path: appRoutes.write,
element: <WritePage />,
action: writeRouteAction(context)
},
{
path: appRoutes.search,
element: <SearchPage />
},
{
path: appRoutes.settingsProfile,
element: <SettingsPage />
},
{
path: appRoutes.settingsRelays,
element: <SettingsPage />
},
{
path: appRoutes.settingsPreferences,
element: <SettingsPage />
},
{
path: appRoutes.settingsAdmin,
element: <SettingsPage />
},
{
path: appRoutes.profile,
element: <ProfilePage />
},
{
element: <FeedLayout />,
children: [
{
path: appRoutes.feed,
element: <FeedPage />
},
{
path: appRoutes.notifications,
element: <NotificationsPage />
}
]
},
{
path: '*',
element: <NotFoundPage />
}
]
}
])