stream/index.js

57 lines
1.7 KiB
JavaScript
Raw Normal View History

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'
2021-10-20 14:33:06 +00:00
import { ThemeProvider } from 'styled-components'
2021-10-11 13:50:24 +00:00
import { BrowserRouter, Route, Switch } from 'react-router-dom'
import Main from './app'
import SeriesPage from './src/pages/SeriesPage'
2021-10-22 13:44:28 +00:00
import { useEventApi } from './src/hooks/data'
2021-10-20 14:33:06 +00:00
import { useTheme } from './src/store'
2021-10-11 13:50:24 +00:00
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-22 13:44:28 +00:00
import Program from './src/pages/Program'
2021-10-11 13:50:24 +00:00
const App = () => {
2021-10-20 14:33:06 +00:00
const { theme } = useTheme((store) => store)
2021-10-22 13:44:28 +00:00
const { data, loading: eventsLoading } = useEventApi()
2021-10-11 13:50:24 +00:00
const [minLoadTimePassed, setMinTimeUp] = useState(false)
useTimeout(() => {
setMinTimeUp(true)
}, 1500)
2021-10-22 13:44:28 +00:00
// console.log({ episodes: data.episodes, series: data.series })
const seriesData = data.series ? Object.values(data.series) : []
2021-10-11 13:50:24 +00:00
2021-10-20 14:33:06 +00:00
return (
<ThemeProvider theme={theme}>
2021-10-22 13:44:28 +00:00
{!seriesData.length || eventsLoading || !minLoadTimePassed ? (
2021-10-20 14:33:06 +00:00
<LoaderLayout />
) : (
<BrowserRouter>
<Switch>
<Route exact path="/" component={Main} />
<Route exact path="/series" component={Series} />
2021-10-22 13:44:28 +00:00
<Route exact path="/program" component={Program} />
2021-10-20 14:33:06 +00:00
{seriesData.length ? seriesData.map(series => (
<Route exact path={`/series/${series.slug}`}>
<SeriesPage data={series} />
</Route>)) : null}
<Route path="*">
<FourOhFour />
</Route>
</Switch>
</BrowserRouter>
)}
</ThemeProvider>)
2021-10-11 13:50:24 +00:00
}
2021-03-05 12:17:51 +00:00
const appEl = document.getElementById('app')
2021-03-05 12:17:51 +00:00
render(<App />, appEl)