You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
spa_instat_tv/src/features/App/index.tsx

64 lines
2.1 KiB

import { Suspense } from 'react'
import { Router } from 'react-router-dom'
import { MatomoProvider } from '@jonkoops/matomo-tracker-react'
import { history } from 'config/history'
import { client } from 'config/clients'
import { matomoInstance } from 'config/matomo'
import { isAvailable } from 'config/env'
import { setClientTitleAndDescription } from 'helpers/setClientHeads'
import { isMatchPage, isMatchPageRFEF } from 'helpers/isMatchPage'
import { GlobalStores } from 'features/GlobalStores'
import { useAuthStore } from 'features/AuthStore'
import { Background } from 'features/Background'
import { GlobalStyles } from 'features/GlobalStyles'
import { Theme } from 'features/Theme'
import { JoinMatchPage } from 'features/JoinMatchPage'
import { JoinMatchPageRFEF } from 'features/JoinMatchPageRFEF'
import { UnavailableText } from 'components/UnavailableText'
import { AuthenticatedApp } from './AuthenticatedApp'
import { checkPage } from '../../helpers/checkPage'
import { PAGES } from '../../config'
setClientTitleAndDescription(client.title, client.description)
const Main = () => {
const { loadingUser, user } = useAuthStore()
if (!user && (isMatchPage() || checkPage(PAGES.tournament))) return <JoinMatchPage />
if (!user && isMatchPageRFEF()) return <JoinMatchPageRFEF />
if (user && isMatchPageRFEF()) {
window.location.href = 'https://instat.tv/football/tournaments/131'
}
// юзер считывается из localstorage или
// access_token токен истек и запрашивается новый
if (loadingUser || user?.expired) return null
// имеется действующий токен
return <AuthenticatedApp />
}
const OTTApp = () => (
<MatomoProvider value={matomoInstance}>
<Router history={history}>
<Theme>
<GlobalStyles />
<GlobalStores>
<Background>
<Suspense fallback={null}>
{isAvailable ? (<Main />) : (<UnavailableText />)}
</Suspense>
</Background>
</GlobalStores>
</Theme>
</Router>
</MatomoProvider>
)
export default OTTApp