stream/src/components/Info/index.js

68 lines
1.8 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-03-24 15:24:34 +00:00
import { isFuture, isPast } from 'date-fns'
2021-03-11 20:24:44 +00:00
import { P } from '../Text'
import translations from '../../data/strings'
import InfoLayout from '../InfoLayout'
2021-03-24 15:24:34 +00:00
import {
VideoCard,
Title,
InfoContent,
PositionedCross as CrossSvg,
} from './styles'
2021-03-24 15:24:34 +00:00
const Info = ({ data, loading, infoActive, setInfoActive, currentVideo }) => {
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
2021-03-24 15:24:34 +00:00
? data.filter(
feeditem =>
feeditem.id !== (currentVideo && currentVideo.id) &&
isFuture(new Date(feeditem.start))
)
2021-03-11 20:24:44 +00:00
: []
2021-03-24 15:24:34 +00:00
console.log({ currentVideo })
return (
2021-03-24 15:24:34 +00:00
<InfoLayout loading={loading}>
{infoActive && <CrossSvg onClick={() => setInfoActive(false)} />}
2021-03-11 20:24:44 +00:00
{!loading && (
<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>
)}
</InfoLayout>
)
}
export default Info