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 { slugify } from './src/helpers/string'
|
|
|
|
import { useEventApi, useEventCalendar } from './src/hooks/data'
|
|
|
|
import { useTimeout } from './src/hooks/timerHooks'
|
|
|
|
import LoaderLayout from './src/pages/LoaderLayout'
|
|
|
|
|
|
|
|
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)
|
|
|
|
console.log(seriesData)
|
|
|
|
|
|
|
|
return calLoading || eventsLoading || !minLoadTimePassed ? (
|
|
|
|
<LoaderLayout />
|
|
|
|
) : (
|
|
|
|
<BrowserRouter>
|
|
|
|
<Switch>
|
|
|
|
<Route exact path="/" component={Main} />
|
|
|
|
{seriesData.length ? seriesData.map(series => (
|
|
|
|
<Route exact path={`/series/${slugify(series.name)}`}>
|
|
|
|
<SeriesPage data={series} />
|
|
|
|
</Route>)) : null}
|
|
|
|
</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)
|