stream/src/components/Info/index.js

52 lines
1.4 KiB
JavaScript
Raw Normal View History

2021-03-11 20:24:44 +00:00
/* eslint-disable react/prop-types */
import { h, Fragment } from 'preact'
import { useEffect, useRef, useState } from 'preact/hooks'
2021-03-11 20:24:44 +00:00
import { isBefore } 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-11 20:24:44 +00:00
import { VideoCard, Title, InfoContent } from './styles'
2021-03-11 20:24:44 +00:00
const Info = ({ data, loading }) => {
const now = new Date()
const pastStreams =
data && data.length
? data.filter(feeditem => isBefore(new Date(feeditem.end), now))
: []
2021-03-11 20:24:44 +00:00
const futureStreams =
data && data.length
? data.filter(feeditem => isBefore(now, new Date(feeditem.start)))
: []
return (
2021-03-11 20:24:44 +00:00
<InfoLayout
title={
data && data.length
? `${translations.en.nextStream}:`
: translations.en.noStreams
}
loading={loading}
>
{!loading && (
<InfoContent>
{futureStreams.map(feeditem => (
<VideoCard key={feeditem.start} {...feeditem} />
))}
{pastStreams.length ? (
<Fragment>
<Title>{translations.en.pastStream}:</Title>
{pastStreams.map(feeditem => (
<VideoCard key={feeditem.start} hasPassed {...feeditem} />
))}
</Fragment>
) : null}
</InfoContent>
)}
</InfoLayout>
)
}
export default Info