2022-09-22 09:37:49 +00:00
|
|
|
// FIXME: breaks on vercel, research
|
|
|
|
// import 'solid-devtools'
|
|
|
|
|
2022-10-25 16:25:42 +00:00
|
|
|
import { MODALS, setLocale, showModal } from '../stores/ui'
|
|
|
|
import { Component, createEffect, createMemo, onMount } 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-10-07 09:23:19 +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'
|
2022-10-31 20:42:20 +00:00
|
|
|
import { DiscussionRulesPage } from './Pages/about/DiscussionRulesPage'
|
2022-10-07 09:23:19 +00:00
|
|
|
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'
|
2022-10-31 20:42:20 +00:00
|
|
|
import { PrinciplesPage } from './Pages/about/PrinciplesPage'
|
2022-10-07 09:23:19 +00:00
|
|
|
import { ProjectsPage } from './Pages/about/ProjectsPage'
|
|
|
|
import { TermsOfUsePage } from './Pages/about/TermsOfUsePage'
|
|
|
|
import { ThanksPage } from './Pages/about/ThanksPage'
|
|
|
|
import { CreatePage } from './Pages/CreatePage'
|
2022-11-02 22:11:30 +00:00
|
|
|
import { ConnectPage } from './Pages/ConnectPage'
|
2022-10-25 16:25:42 +00:00
|
|
|
import { renewSession } from '../stores/auth'
|
2022-10-07 09:23:19 +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-10-07 12:57:33 +00:00
|
|
|
// const CreatePage = lazy(() => import('./Pages/about/CreatePage'))
|
2022-09-22 09:37:49 +00:00
|
|
|
|
|
|
|
const log = getLogger('root')
|
|
|
|
|
2022-10-25 16:25:42 +00:00
|
|
|
type RootSearchParams = {
|
|
|
|
modal: string
|
|
|
|
lang: string
|
|
|
|
}
|
|
|
|
|
2022-09-22 09:37:49 +00:00
|
|
|
const pagesMap: Record<keyof Routes, Component<PageProps>> = {
|
2022-11-02 22:11:30 +00:00
|
|
|
connect: ConnectPage,
|
2022-10-05 11:42:13 +00:00
|
|
|
create: CreatePage,
|
2022-09-22 09:37:49 +00:00
|
|
|
home: HomePage,
|
|
|
|
topics: AllTopicsPage,
|
|
|
|
topic: TopicPage,
|
|
|
|
authors: AllAuthorsPage,
|
|
|
|
author: AuthorPage,
|
|
|
|
feed: FeedPage,
|
|
|
|
article: ArticlePage,
|
2022-09-23 18:27:05 +00:00
|
|
|
search: SearchPage,
|
2022-10-31 20:42:20 +00:00
|
|
|
discussionRules: DiscussionRulesPage,
|
2022-09-23 18:27:05 +00:00
|
|
|
dogma: DogmaPage,
|
|
|
|
guide: GuidePage,
|
|
|
|
help: HelpPage,
|
|
|
|
manifest: ManifestPage,
|
|
|
|
projects: ProjectsPage,
|
|
|
|
partners: PartnersPage,
|
2022-10-31 20:42:20 +00:00
|
|
|
principles: PrinciplesPage,
|
2022-09-23 18:27:05 +00:00
|
|
|
termsOfUse: TermsOfUsePage,
|
|
|
|
thanks: ThanksPage
|
2022-09-22 09:37:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const Root = (props: PageProps) => {
|
2022-10-25 16:25:42 +00:00
|
|
|
const { page, searchParams } = useRouter<RootSearchParams>()
|
2022-09-22 09:37:49 +00:00
|
|
|
|
2022-10-25 16:25:42 +00:00
|
|
|
createEffect(() => {
|
|
|
|
const modal = MODALS[searchParams().modal]
|
|
|
|
if (modal) {
|
|
|
|
showModal(modal)
|
|
|
|
}
|
|
|
|
})
|
2022-09-22 09:37:49 +00:00
|
|
|
|
2022-10-25 16:25:42 +00:00
|
|
|
onMount(() => {
|
|
|
|
renewSession()
|
|
|
|
})
|
2022-09-22 09:37:49 +00:00
|
|
|
|
2022-10-25 16:25:42 +00:00
|
|
|
const pageComponent = createMemo(() => {
|
|
|
|
const result = pagesMap[page().route]
|
2022-09-22 09:37:49 +00:00
|
|
|
|
2022-10-25 16:25:42 +00:00
|
|
|
if (!result || page().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(() => {
|
2022-10-25 16:25:42 +00:00
|
|
|
const lang = searchParams().lang || 'ru'
|
2022-09-24 10:34:57 +00:00
|
|
|
console.log('[root] client locale is', lang)
|
|
|
|
setLocale(lang)
|
2022-10-25 16:25:42 +00:00
|
|
|
})
|
2022-09-24 10:34:57 +00:00
|
|
|
}
|
|
|
|
|
2022-09-22 09:37:49 +00:00
|
|
|
return <Dynamic component={pageComponent()} {...props} />
|
|
|
|
}
|