2021-03-05 12:17:51 +00:00
|
|
|
import { h, render } from 'preact'
|
2021-10-11 13:50:24 +00:00
|
|
|
import { useState } from 'preact/hooks'
|
|
|
|
import { BrowserRouter, Route, Switch } from 'react-router-dom'
|
|
|
|
|
|
|
|
import Main from './app'
|
|
|
|
import SeriesPage from './src/pages/SeriesPage'
|
|
|
|
import { useEventApi, useEventCalendar } from './src/hooks/data'
|
|
|
|
import { useTimeout } from './src/hooks/timerHooks'
|
|
|
|
import LoaderLayout from './src/pages/LoaderLayout'
|
2021-10-15 13:37:54 +00:00
|
|
|
import FourOhFour from './src/pages/404'
|
|
|
|
import Series from './src/pages/Series'
|
2021-10-11 13:50:24 +00:00
|
|
|
|
|
|
|
const App = () => {
|
|
|
|
const { data: calData, calLoading } = useEventCalendar()
|
|
|
|
const { data: seriesDataArray, loading: eventsLoading } = useEventApi()
|
|
|
|
const [minLoadTimePassed, setMinTimeUp] = useState(false)
|
|
|
|
|
|
|
|
useTimeout(() => {
|
|
|
|
setMinTimeUp(true)
|
|
|
|
}, 1500)
|
|
|
|
|
|
|
|
|
|
|
|
const seriesData = Object.values(seriesDataArray)
|
|
|
|
|
|
|
|
return calLoading || eventsLoading || !minLoadTimePassed ? (
|
|
|
|
<LoaderLayout />
|
|
|
|
) : (
|
|
|
|
<BrowserRouter>
|
|
|
|
<Switch>
|
|
|
|
<Route exact path="/" component={Main} />
|
2021-10-15 13:37:54 +00:00
|
|
|
<Route exact path="/series" component={Series} />
|
2021-10-11 13:50:24 +00:00
|
|
|
{seriesData.length ? seriesData.map(series => (
|
2021-10-11 17:15:09 +00:00
|
|
|
<Route exact path={`/series/${series.slug}`}>
|
2021-10-11 13:50:24 +00:00
|
|
|
<SeriesPage data={series} />
|
|
|
|
</Route>)) : null}
|
2021-10-15 13:37:54 +00:00
|
|
|
<Route path="*">
|
|
|
|
<FourOhFour />
|
|
|
|
</Route>
|
2021-10-11 13:50:24 +00:00
|
|
|
</Switch>
|
|
|
|
</BrowserRouter>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-03-05 12:17:51 +00:00
|
|
|
|
2021-03-10 13:51:24 +00:00
|
|
|
const appEl = document.getElementById('app')
|
2021-03-05 12:17:51 +00:00
|
|
|
|
2021-03-10 13:51:24 +00:00
|
|
|
render(<App />, appEl)
|