stream/src/components/Info/index.js

135 lines
3.9 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-26 13:47:59 +00:00
import VideoEmbed from '../VideoEmbed'
2021-03-24 15:24:34 +00:00
import {
VideoCard,
Title,
InfoContent,
PositionedCross as CrossSvg,
2021-05-17 15:27:31 +00:00
Row,
ActionButton as Button,
Img,
Trailer,
2021-03-24 15:24:34 +00:00
} from './styles'
import intro from '../../data/intro.md'
import credits from '../../data/credits.md'
import { colours } from '../../assets/theme'
2021-05-16 23:08:25 +00:00
import config from '../../data/config'
2021-05-17 15:27:31 +00:00
import trailerThumb from '../../assets/img/main_thumb.png'
2021-03-24 15:24:34 +00:00
const Info = ({ data, loading, infoActive, setInfoActive, currentVideo }) => {
2021-05-26 13:47:59 +00:00
const trailerUrl = `https://www.youtube-nocookie.com/embed/${config.seriesTrailerId}?autoplay=1&vq=hd1080`
const [embedURL, setEmbedUrl] = useState('')
const onClickTrailerButton = () => {
setEmbedUrl(trailerUrl)
}
const deactivateEmbed = () => {
setEmbedUrl('')
}
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-26 13:47:59 +00:00
{embedURL ? (
<VideoEmbed onClose={deactivateEmbed} url={embedURL} />
) : null}
2021-05-23 15:21:15 +00:00
{infoActive && (
<CrossSvg size="64" 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-17 15:27:31 +00:00
2021-05-26 13:47:59 +00:00
<Trailer imgSrc={trailerThumb} onClick={onClickTrailerButton} />
2021-05-17 15:27:31 +00:00
<Row>
<a
href="https://discord.gg/Xu9D3qVana"
target="_blank"
rel="noopener noreferrer"
>
<Button>Join the Discord</Button>
</a>
<a
href="https://ndc.substack.com/subscribe"
target="_blank"
rel="noopener noreferrer"
>
<Button>Subscribe to the mailing list</Button>
</a>
</Row>
</InfoContent>
2021-03-24 15:24:34 +00:00
{currentVideo && (
<Fragment>
<Title>{translations.en.nowPlaying}:</Title>
<VideoCard {...currentVideo} />
</Fragment>
)}
2021-05-23 15:21:15 +00:00
{futureStreams.length ? (
2021-03-24 15:24:34 +00:00
<Fragment>
<Title>{translations.en.nextStream}:</Title>
{futureStreams.map(feeditem => (
<VideoCard key={feeditem.start} {...feeditem} />
))}
</Fragment>
2021-05-23 15:21:15 +00:00
) : null}
2021-03-24 15:24:34 +00:00
2021-03-11 20:24:44 +00:00
{pastStreams.length ? (
<Fragment>
<Title>{translations.en.pastStream}:</Title>
{pastStreams.map(feeditem => (
2021-05-26 13:47:59 +00:00
<VideoCard
key={feeditem.start}
hasPassed
onClickButton={() =>
setEmbedUrl(`${config.peertube_root}${feeditem.embedPath}`)
}
{...feeditem}
/>
2021-03-11 20:24:44 +00:00
))}
</Fragment>
) : null}
<InfoContent>
<Markdown>{credits}</Markdown>
</InfoContent>
</Fragment>
2021-03-11 20:24:44 +00:00
)}
</InfoLayout>
)
}
export default Info