primary.tsx raw

   1  import BookmarkPage from '@/pages/primary/BookmarkPage'
   2  import ChatPage from '@/pages/primary/ChatPage'
   3  import HelpPage from '@/pages/primary/HelpPage'
   4  import MePage from '@/pages/primary/MePage'
   5  import NoteListPage from '@/pages/primary/NoteListPage'
   6  import NotificationListPage from '@/pages/primary/NotificationListPage'
   7  import ProfilePage from '@/pages/primary/ProfilePage'
   8  import RelayPage from '@/pages/primary/RelayPage'
   9  import SearchPage from '@/pages/primary/SearchPage'
  10  import SettingsPage from '@/pages/primary/SettingsPage'
  11  import { TPageRef } from '@/types'
  12  import { createRef, ForwardRefExoticComponent, RefAttributes } from 'react'
  13  
  14  type RouteConfig = {
  15    key: string
  16    component: ForwardRefExoticComponent<RefAttributes<TPageRef>>
  17  }
  18  
  19  const PRIMARY_ROUTE_CONFIGS: RouteConfig[] = [
  20    { key: 'home', component: NoteListPage },
  21    { key: 'inbox', component: ChatPage },
  22    { key: 'notifications', component: NotificationListPage },
  23    { key: 'me', component: MePage },
  24    { key: 'profile', component: ProfilePage },
  25    { key: 'relay', component: RelayPage },
  26    { key: 'search', component: SearchPage },
  27    { key: 'bookmark', component: BookmarkPage },
  28    { key: 'settings', component: SettingsPage },
  29    { key: 'help', component: HelpPage },
  30    { key: 'chat', component: ChatPage }
  31  ]
  32  
  33  export const PRIMARY_PAGE_REF_MAP = PRIMARY_ROUTE_CONFIGS.reduce(
  34    (acc, { key }) => {
  35      acc[key] = createRef<TPageRef>()
  36      return acc
  37    },
  38    {} as Record<string, React.RefObject<TPageRef>>
  39  )
  40  
  41  export const PRIMARY_PAGE_MAP = PRIMARY_ROUTE_CONFIGS.reduce(
  42    (acc, { key, component: Component }) => {
  43      acc[key] = <Component ref={PRIMARY_PAGE_REF_MAP[key]} />
  44      return acc
  45    },
  46    {} as Record<string, JSX.Element>
  47  )
  48  
  49  export type TPrimaryPageName = keyof typeof PRIMARY_PAGE_MAP
  50