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'
|
2022-11-13 19:35:57 +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
|
|
|
|
2022-11-13 19:35:57 +00:00
|
|
|
import type { PageProps, RootSearchParams } from './types'
|
2022-09-22 09:37:49 +00:00
|
|
|
|
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-11-16 13:44:41 +00:00
|
|
|
import { InboxPage } from './Pages/InboxPage'
|
2022-11-12 18:59:29 +00:00
|
|
|
import { LayoutShoutsPage } from './Pages/LayoutShoutsPage'
|
2022-11-14 10:02:08 +00:00
|
|
|
import { SessionProvider } from '../context/session'
|
2022-11-24 21:37:43 +00:00
|
|
|
import { ProfileSettingsPage } from './Pages/profile/ProfileSettingsPage'
|
2022-11-28 22:14:19 +00:00
|
|
|
import { ProfileSecurityPage } from './Pages/profile/ProfileSecurityPage'
|
|
|
|
import { ProfileSubscriptionsPage } from './Pages/profile/ProfileSubscriptionsPage'
|
2022-10-07 09:23:19 +00:00
|
|
|
|
|
|
|
// TODO: lazy load
|
2022-11-12 18:14:20 +00:00
|
|
|
// const SomePage = lazy(() => import('./Pages/SomePage'))
|
2022-09-22 09:37:49 +00:00
|
|
|
|
|
|
|
const pagesMap: Record<keyof Routes, Component<PageProps>> = {
|
2022-11-16 13:44:41 +00:00
|
|
|
inbox: InboxPage,
|
2022-11-13 03:47:55 +00:00
|
|
|
expo: LayoutShoutsPage,
|
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,
|
2022-11-24 21:37:43 +00:00
|
|
|
thanks: ThanksPage,
|
2022-11-28 22:14:19 +00:00
|
|
|
profileSettings: ProfileSettingsPage,
|
|
|
|
profileSecurity: ProfileSecurityPage,
|
|
|
|
profileSubscriptions: ProfileSubscriptionsPage
|
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
|
|
|
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-11-13 19:35:57 +00:00
|
|
|
return (
|
2022-11-14 10:02:08 +00:00
|
|
|
<SessionProvider>
|
2022-11-13 19:35:57 +00:00
|
|
|
<Dynamic component={pageComponent()} {...props} />
|
2022-11-14 10:02:08 +00:00
|
|
|
</SessionProvider>
|
2022-11-13 19:35:57 +00:00
|
|
|
)
|
2022-09-22 09:37:49 +00:00
|
|
|
}
|