stream/src/components/Info/index.js

105 lines
3.1 KiB
JavaScript
Raw Normal View History

2021-03-11 20:24:44 +00:00
/* eslint-disable react/prop-types */
import { h, Fragment } from 'preact'
2021-05-16 23:08:25 +00:00
import { useState, useEffect } from 'preact/hooks'
2021-03-24 15:24:34 +00:00
import { isFuture, isPast } from 'date-fns'
import { H1 } from '../Text'
import Markdown from '../Markdown'
import translations from '../../data/strings'
import InfoLayout from '../InfoLayout'
2021-05-16 23:08:25 +00:00
import TrailerEmbed from '../VideoEmbed'
2021-03-24 15:24:34 +00:00
import {
VideoCard,
Title,
InfoContent,
PositionedCross as CrossSvg,
TopContent,
2021-03-24 15:24:34 +00:00
} from './styles'
import intro from '../../data/intro.md'
import credits from '../../data/credits.md'
import Button from '../Button'
import PlaySvg from '../Svg/Play'
import { colours } from '../../assets/theme'
2021-05-16 23:08:25 +00:00
import config from '../../data/config'
2021-03-24 15:24:34 +00:00
const Info = ({ data, loading, infoActive, setInfoActive, currentVideo }) => {
2021-05-16 23:08:25 +00:00
const [trailerActive, setTrailerActive] = useState(false)
const toggleTrailerActive = () =>
setTrailerActive(trailerState => !trailerState)
2021-03-11 20:24:44 +00:00
const pastStreams =
data && data.length
2021-03-24 15:24:34 +00:00
? data.filter(feeditem => isPast(new Date(feeditem.end)))
2021-03-11 20:24:44 +00:00
: []
2021-03-11 20:24:44 +00:00
const futureStreams =
data && data.length
? data
.filter(
feeditem =>
feeditem.id !== (currentVideo && currentVideo.id) &&
isFuture(new Date(feeditem.start))
)
.sort(
(a, b) =>
// Turn your strings into dates, and then subtract them
// to get a value that is either negative, positive, or zero.
new Date(a.start) - new Date(b.start)
)
2021-03-11 20:24:44 +00:00
: []
return (
2021-03-24 15:24:34 +00:00
<InfoLayout loading={loading}>
2021-05-16 23:08:25 +00:00
{trailerActive && (
<TrailerEmbed
onClose={toggleTrailerActive}
url={config.seriesTrailer}
/>
)}
2021-03-24 15:24:34 +00:00
{infoActive && <CrossSvg onClick={() => setInfoActive(false)} />}
2021-03-11 20:24:44 +00:00
{!loading && (
<Fragment>
<InfoContent>
<H1>The Para-Real:</H1>
<H1>Finding the Future in Unexpected Places</H1>
<Markdown withLinebreaks>{intro}</Markdown>
2021-05-16 23:08:25 +00:00
<Button onClick={toggleTrailerActive}>
<PlaySvg colour={colours.midnightDarker} size="20" />
Watch the trailer
</Button>
</InfoContent>
2021-03-24 15:24:34 +00:00
{currentVideo && (
<Fragment>
<Title>{translations.en.nowPlaying}:</Title>
<VideoCard {...currentVideo} />
</Fragment>
)}
{futureStreams.length && (
<Fragment>
<Title>{translations.en.nextStream}:</Title>
{futureStreams.map(feeditem => (
<VideoCard key={feeditem.start} {...feeditem} />
))}
</Fragment>
)}
2021-03-11 20:24:44 +00:00
{pastStreams.length ? (
<Fragment>
<Title>{translations.en.pastStream}:</Title>
{pastStreams.map(feeditem => (
<VideoCard key={feeditem.start} hasPassed {...feeditem} />
))}
</Fragment>
) : null}
<InfoContent>
<Markdown>{credits}</Markdown>
</InfoContent>
</Fragment>
2021-03-11 20:24:44 +00:00
)}
</InfoLayout>
)
}
export default Info