2022-09-22 09:37:49 +00:00
|
|
|
// FIXME: breaks on vercel, research
|
|
|
|
// import 'solid-devtools'
|
|
|
|
|
2022-09-24 10:34:57 +00:00
|
|
|
import { setLocale } from '../stores/ui'
|
2022-09-29 11:50:48 +00:00
|
|
|
import { Component, createEffect, createMemo } from 'solid-js'
|
2022-09-22 09:37:49 +00:00
|
|
|
import { Routes, useRouter } from '../stores/router'
|
2022-09-24 10:34:57 +00:00
|
|
|
import { Dynamic, isServer } from 'solid-js/web'
|
2022-09-22 09:37:49 +00:00
|
|
|
import { getLogger } from '../utils/logger'
|
|
|
|
|
|
|
|
import type { PageProps } from './types'
|
|
|
|
|
2022-09-28 20:16:44 +00:00
|
|
|
import { HomePage } from './Pages/HomePage'
|
|
|
|
import { AllTopicsPage } from './Pages/AllTopicsPage'
|
|
|
|
import { TopicPage } from './Pages/TopicPage'
|
|
|
|
import { AllAuthorsPage } from './Pages/AllAuthorsPage'
|
|
|
|
import { AuthorPage } from './Pages/AuthorPage'
|
|
|
|
import { FeedPage } from './Pages/FeedPage'
|
|
|
|
import { ArticlePage } from './Pages/ArticlePage'
|
|
|
|
import { SearchPage } from './Pages/SearchPage'
|
|
|
|
import { FourOuFourPage } from './Pages/FourOuFourPage'
|
|
|
|
import { DogmaPage } from './Pages/about/DogmaPage'
|
|
|
|
import { GuidePage } from './Pages/about/GuidePage'
|
|
|
|
import { HelpPage } from './Pages/about/HelpPage'
|
|
|
|
import { ManifestPage } from './Pages/about/ManifestPage'
|
|
|
|
import { PartnersPage } from './Pages/about/PartnersPage'
|
|
|
|
import { ProjectsPage } from './Pages/about/ProjectsPage'
|
|
|
|
import { TermsOfUsePage } from './Pages/about/TermsOfUsePage'
|
|
|
|
import { ThanksPage } from './Pages/about/ThanksPage'
|
2022-09-22 09:37:49 +00:00
|
|
|
|
2022-09-28 20:16:44 +00:00
|
|
|
// TODO: lazy load
|
|
|
|
// const HomePage = lazy(() => import('./Pages/HomePage'))
|
|
|
|
// const AllTopicsPage = lazy(() => import('./Pages/AllTopicsPage'))
|
|
|
|
// const TopicPage = lazy(() => import('./Pages/TopicPage'))
|
|
|
|
// const AllAuthorsPage = lazy(() => import('./Pages/AllAuthorsPage'))
|
|
|
|
// const AuthorPage = lazy(() => import('./Pages/AuthorPage'))
|
|
|
|
// const FeedPage = lazy(() => import('./Pages/FeedPage'))
|
|
|
|
// const ArticlePage = lazy(() => import('./Pages/ArticlePage'))
|
|
|
|
// const SearchPage = lazy(() => import('./Pages/SearchPage'))
|
|
|
|
// const FourOuFourPage = lazy(() => import('./Pages/FourOuFourPage'))
|
|
|
|
// const DogmaPage = lazy(() => import('./Pages/about/DogmaPage'))
|
|
|
|
// const GuidePage = lazy(() => import('./Pages/about/GuidePage'))
|
|
|
|
// const HelpPage = lazy(() => import('./Pages/about/HelpPage'))
|
|
|
|
// const ManifestPage = lazy(() => import('./Pages/about/ManifestPage'))
|
|
|
|
// const PartnersPage = lazy(() => import('./Pages/about/PartnersPage'))
|
|
|
|
// const ProjectsPage = lazy(() => import('./Pages/about/ProjectsPage'))
|
|
|
|
// const TermsOfUsePage = lazy(() => import('./Pages/about/TermsOfUsePage'))
|
|
|
|
// const ThanksPage = lazy(() => import('./Pages/about/ThanksPage'))
|
2022-09-22 09:37:49 +00:00
|
|
|
|
|
|
|
const log = getLogger('root')
|
|
|
|
|
|
|
|
const pagesMap: Record<keyof Routes, Component<PageProps>> = {
|
|
|
|
home: HomePage,
|
|
|
|
topics: AllTopicsPage,
|
|
|
|
topic: TopicPage,
|
|
|
|
authors: AllAuthorsPage,
|
|
|
|
author: AuthorPage,
|
|
|
|
feed: FeedPage,
|
|
|
|
article: ArticlePage,
|
2022-09-23 18:27:05 +00:00
|
|
|
search: SearchPage,
|
|
|
|
dogma: DogmaPage,
|
|
|
|
guide: GuidePage,
|
|
|
|
help: HelpPage,
|
|
|
|
manifest: ManifestPage,
|
|
|
|
projects: ProjectsPage,
|
|
|
|
partners: PartnersPage,
|
|
|
|
termsOfUse: TermsOfUsePage,
|
|
|
|
thanks: ThanksPage
|
2022-09-22 09:37:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const Root = (props: PageProps) => {
|
|
|
|
const { getPage } = useRouter()
|
|
|
|
|
|
|
|
// log.debug({ route: getPage().route })
|
|
|
|
|
|
|
|
const pageComponent = createMemo(() => {
|
|
|
|
const result = pagesMap[getPage().route]
|
|
|
|
|
|
|
|
// log.debug('page', getPage())
|
|
|
|
|
2022-09-23 18:27:05 +00:00
|
|
|
if (!result || getPage().path === '/404') {
|
2022-09-22 09:37:49 +00:00
|
|
|
return FourOuFourPage
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
})
|
2022-09-24 10:34:57 +00:00
|
|
|
|
|
|
|
if (!isServer) {
|
|
|
|
createEffect(() => {
|
|
|
|
const lang = new URLSearchParams(window.location.search).get('lang') || 'ru'
|
|
|
|
console.log('[root] client locale is', lang)
|
|
|
|
setLocale(lang)
|
|
|
|
}, [window.location.search])
|
|
|
|
}
|
|
|
|
|
2022-09-22 09:37:49 +00:00
|
|
|
return <Dynamic component={pageComponent()} {...props} />
|
|
|
|
}
|