refactor: page manager
This commit is contained in:
parent
1b7ec56c89
commit
579385ce3d
13 changed files with 131 additions and 121 deletions
46
src/routes/primary.tsx
Normal file
46
src/routes/primary.tsx
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import BookmarkPage from '@/pages/primary/BookmarkPage'
|
||||
import ExplorePage from '@/pages/primary/ExplorePage'
|
||||
import MePage from '@/pages/primary/MePage'
|
||||
import NoteListPage from '@/pages/primary/NoteListPage'
|
||||
import NotificationListPage from '@/pages/primary/NotificationListPage'
|
||||
import ProfilePage from '@/pages/primary/ProfilePage'
|
||||
import RelayPage from '@/pages/primary/RelayPage'
|
||||
import SearchPage from '@/pages/primary/SearchPage'
|
||||
import SettingsPage from '@/pages/primary/SettingsPage'
|
||||
import { TPageRef } from '@/types'
|
||||
import { createRef, ForwardRefExoticComponent, RefAttributes } from 'react'
|
||||
|
||||
type RouteConfig = {
|
||||
key: string
|
||||
component: ForwardRefExoticComponent<RefAttributes<TPageRef>>
|
||||
}
|
||||
|
||||
const PRIMARY_ROUTE_CONFIGS: RouteConfig[] = [
|
||||
{ key: 'home', component: NoteListPage },
|
||||
{ key: 'explore', component: ExplorePage },
|
||||
{ key: 'notifications', component: NotificationListPage },
|
||||
{ key: 'me', component: MePage },
|
||||
{ key: 'profile', component: ProfilePage },
|
||||
{ key: 'relay', component: RelayPage },
|
||||
{ key: 'search', component: SearchPage },
|
||||
{ key: 'bookmark', component: BookmarkPage },
|
||||
{ key: 'settings', component: SettingsPage }
|
||||
]
|
||||
|
||||
export const PRIMARY_PAGE_REF_MAP = PRIMARY_ROUTE_CONFIGS.reduce(
|
||||
(acc, { key }) => {
|
||||
acc[key] = createRef<TPageRef>()
|
||||
return acc
|
||||
},
|
||||
{} as Record<string, React.RefObject<TPageRef>>
|
||||
)
|
||||
|
||||
export const PRIMARY_PAGE_MAP = PRIMARY_ROUTE_CONFIGS.reduce(
|
||||
(acc, { key, component: Component }) => {
|
||||
acc[key] = <Component ref={PRIMARY_PAGE_REF_MAP[key]} />
|
||||
return acc
|
||||
},
|
||||
{} as Record<string, JSX.Element>
|
||||
)
|
||||
|
||||
export type TPrimaryPageName = keyof typeof PRIMARY_PAGE_MAP
|
||||
52
src/routes/secondary.tsx
Normal file
52
src/routes/secondary.tsx
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import AppearanceSettingsPage from '@/pages/secondary/AppearanceSettingsPage'
|
||||
import BookmarkPage from '@/pages/secondary/BookmarkPage'
|
||||
import FollowingListPage from '@/pages/secondary/FollowingListPage'
|
||||
import GeneralSettingsPage from '@/pages/secondary/GeneralSettingsPage'
|
||||
import MuteListPage from '@/pages/secondary/MuteListPage'
|
||||
import NoteListPage from '@/pages/secondary/NoteListPage'
|
||||
import NotePage from '@/pages/secondary/NotePage'
|
||||
import OthersRelaySettingsPage from '@/pages/secondary/OthersRelaySettingsPage'
|
||||
import PostSettingsPage from '@/pages/secondary/PostSettingsPage'
|
||||
import ProfileEditorPage from '@/pages/secondary/ProfileEditorPage'
|
||||
import ProfileListPage from '@/pages/secondary/ProfileListPage'
|
||||
import ProfilePage from '@/pages/secondary/ProfilePage'
|
||||
import RelayPage from '@/pages/secondary/RelayPage'
|
||||
import RelayReviewsPage from '@/pages/secondary/RelayReviewsPage'
|
||||
import RelaySettingsPage from '@/pages/secondary/RelaySettingsPage'
|
||||
import RizfulPage from '@/pages/secondary/RizfulPage'
|
||||
import SearchPage from '@/pages/secondary/SearchPage'
|
||||
import SettingsPage from '@/pages/secondary/SettingsPage'
|
||||
import TranslationPage from '@/pages/secondary/TranslationPage'
|
||||
import WalletPage from '@/pages/secondary/WalletPage'
|
||||
import { match } from 'path-to-regexp'
|
||||
import { isValidElement } from 'react'
|
||||
|
||||
// Right column routes
|
||||
const SECONDARY_ROUTE_CONFIGS = [
|
||||
{ path: '/notes', element: <NoteListPage /> },
|
||||
{ path: '/notes/:id', element: <NotePage /> },
|
||||
{ path: '/users', element: <ProfileListPage /> },
|
||||
{ path: '/users/:id', element: <ProfilePage /> },
|
||||
{ path: '/users/:id/following', element: <FollowingListPage /> },
|
||||
{ path: '/users/:id/relays', element: <OthersRelaySettingsPage /> },
|
||||
{ path: '/relays/:url', element: <RelayPage /> },
|
||||
{ path: '/relays/:url/reviews', element: <RelayReviewsPage /> },
|
||||
{ path: '/search', element: <SearchPage /> },
|
||||
{ path: '/settings', element: <SettingsPage /> },
|
||||
{ path: '/settings/relays', element: <RelaySettingsPage /> },
|
||||
{ path: '/settings/wallet', element: <WalletPage /> },
|
||||
{ path: '/settings/posts', element: <PostSettingsPage /> },
|
||||
{ path: '/settings/general', element: <GeneralSettingsPage /> },
|
||||
{ path: '/settings/appearance', element: <AppearanceSettingsPage /> },
|
||||
{ path: '/settings/translation', element: <TranslationPage /> },
|
||||
{ path: '/profile-editor', element: <ProfileEditorPage /> },
|
||||
{ path: '/mutes', element: <MuteListPage /> },
|
||||
{ path: '/rizful', element: <RizfulPage /> },
|
||||
{ path: '/bookmarks', element: <BookmarkPage /> }
|
||||
]
|
||||
|
||||
export const SECONDARY_ROUTES = SECONDARY_ROUTE_CONFIGS.map(({ path, element }) => ({
|
||||
path,
|
||||
element: isValidElement(element) ? element : null,
|
||||
matcher: match(path)
|
||||
}))
|
||||
Loading…
Add table
Add a link
Reference in a new issue