stream/src/pages/SeriesPage/index.js

116 lines
3.4 KiB
JavaScript
Raw Normal View History

2021-10-11 13:50:24 +00:00
/* eslint-disable react/prop-types */
import { h, Fragment } from 'preact'
2021-10-20 14:33:06 +00:00
import { useEffect } from 'preact/hooks'
2021-10-11 13:50:24 +00:00
import striptags from 'striptags'
import { H1 } from '../../components/Text'
import Markdown from '../../components/Markdown'
2021-10-11 17:15:09 +00:00
import translations from '../../data/strings'
2021-10-12 12:45:52 +00:00
import InfoLayout from '../../layouts/InfoLayout'
2021-10-11 13:50:24 +00:00
import VideoEmbed from '../../components/VideoEmbed'
import {
2021-10-11 17:15:09 +00:00
EpisodeCard,
2021-10-11 13:50:24 +00:00
Title,
InfoContent,
Row,
ActionButton as Button,
2021-10-12 12:45:52 +00:00
TrailerContainer,
2021-10-11 13:50:24 +00:00
} from './styles'
2021-10-12 12:45:52 +00:00
import Page from '../../layouts/Page'
2021-10-15 13:37:54 +00:00
import { splitArray } from '../../helpers/utils'
2021-10-20 14:33:06 +00:00
import { defaultTheme } from '../../assets/theme'
2021-10-11 13:50:24 +00:00
const SeriesPage = ({ data }) => {
2021-10-20 14:33:06 +00:00
const theme = data.theme || defaultTheme
2021-10-20 14:32:27 +00:00
const credits = data.credits ? `
2021-10-11 17:15:09 +00:00
## Credits
${data.credits}
2021-10-20 14:32:27 +00:00
` : null
2021-10-11 13:50:24 +00:00
const dateString = `${new Date()}`
let tzShort =
// Works for the majority of modern browsers
dateString.match(/\(([^\)]+)\)$/) ||
// IE outputs date strings in a different format:
dateString.match(/([A-Z]+) [\d]{4}$/)
if (tzShort) {
// Old Firefox uses the long timezone name (e.g., "Central
// Daylight Time" instead of "CDT")
tzShort = tzShort[1].match(/[A-Z]/g).join('')
}
2021-10-15 13:37:54 +00:00
const links = data.links.length ? splitArray(data.links, 2) : null
2021-10-11 13:50:24 +00:00
return (
2021-10-15 13:37:54 +00:00
<Page title={data.title} theme={data.theme} withHeader={false}>
2021-10-20 14:33:06 +00:00
<InfoLayout title={data.title} subtitle={data.subtitle} image={data.image} theme={theme}>
2021-10-12 12:45:52 +00:00
<Fragment>
<InfoContent>
<H1>{data.title}:</H1>
<H1>{data.subtitle}</H1>
2021-10-20 14:33:06 +00:00
{data.description ? <Markdown withLinebreaks theme={theme}>{data.description}</Markdown> : null}
2021-10-11 13:50:24 +00:00
2021-10-12 12:45:52 +00:00
{data.trailer ? (
<TrailerContainer>
<VideoEmbed url={data.trailer} />
</TrailerContainer>
) : null}
2021-10-11 13:50:24 +00:00
2021-10-15 13:37:54 +00:00
{links ?
links.map(linkRow => <Row>
{linkRow.map(link => (
2021-10-12 12:45:52 +00:00
<a
href={link.resourceUrl}
target="_blank"
rel="noopener noreferrer"
>
<Button>{link.summary}</Button>
</a>
))}
2021-10-15 13:37:54 +00:00
</Row>) : null
2021-10-12 12:45:52 +00:00
}
</InfoContent>
{data.episodes.future.length ? (
<Fragment>
2021-10-15 13:37:54 +00:00
<Title>{translations.en.program}:</Title>
2021-10-12 12:45:52 +00:00
{data.episodes.future.map(feeditem => (
<EpisodeCard
2021-10-20 14:33:06 +00:00
theme={theme}
2021-10-12 12:45:52 +00:00
key={feeditem.start}
tzShort={tzShort}
{...feeditem}
/>
))}
</Fragment>
) : null}
{data.episodes.past.length ? (
<Fragment>
<Title>Past streams:</Title>
{data.episodes.past.map(feeditem => (
<EpisodeCard
2021-10-20 14:33:06 +00:00
theme={theme}
2021-10-12 12:45:52 +00:00
key={feeditem.beginsOn}
hasPassed
2021-10-15 13:37:54 +00:00
onClickButton={() => null} // todo: fix this
2021-10-12 12:45:52 +00:00
{...feeditem}
/>
))}
</Fragment>
) : null}
2021-10-20 14:32:27 +00:00
{credits ? <InfoContent>
2021-10-12 12:45:52 +00:00
<Title>Credits</Title>
2021-10-20 14:33:06 +00:00
<Markdown theme={theme}>{credits}</Markdown>
2021-10-15 13:37:54 +00:00
</InfoContent> : null}
2021-10-12 12:45:52 +00:00
</Fragment>
2021-10-11 13:50:24 +00:00
2021-10-12 12:45:52 +00:00
</InfoLayout>
</Page>
2021-10-11 13:50:24 +00:00
)
}
export default SeriesPage