lbry-desktop/ui/component/livestreamList/view.jsx

42 lines
1.4 KiB
React
Raw Normal View History

2021-04-23 21:59:48 +02:00
// @flow
import React from 'react';
import ClaimList from 'component/claimList';
2021-04-23 21:59:48 +02:00
import Spinner from 'component/spinner';
import { FETCH_ACTIVE_LIVESTREAMS_MIN_INTERVAL_MS } from 'constants/livestream';
import { getLivestreamUris } from 'util/livestream';
2021-04-23 21:59:48 +02:00
type Props = {
activeLivestreams: ?LivestreamInfo,
fetchingActiveLivestreams: boolean,
doFetchActiveLivestreams: () => void,
};
2021-04-23 21:59:48 +02:00
export default function LivestreamList(props: Props) {
const { activeLivestreams, fetchingActiveLivestreams, doFetchActiveLivestreams } = props;
const livestreamUris = getLivestreamUris(activeLivestreams, null);
2021-04-23 21:59:48 +02:00
React.useEffect(() => {
doFetchActiveLivestreams();
2021-04-23 21:59:48 +02:00
// doFetchActiveLivestreams is currently limited to 5 minutes per fetch as
// a global default. If we want more frequent updates (say, to update the
// view count), we can either change that limit, or add a 'force' parameter
// to doFetchActiveLivestreams to override selectively.
const fetchInterval = setInterval(doFetchActiveLivestreams, FETCH_ACTIVE_LIVESTREAMS_MIN_INTERVAL_MS + 50);
2021-04-23 21:59:48 +02:00
return () => {
clearInterval(fetchInterval);
2021-04-23 21:59:48 +02:00
};
}, []);
return (
<>
{fetchingActiveLivestreams && (
2021-04-23 21:59:48 +02:00
<div className="main--empty">
<Spinner delayed />
</div>
)}
{!fetchingActiveLivestreams && <ClaimList uris={livestreamUris} showNoSourceClaims tileLayout />}
2021-04-23 21:59:48 +02:00
</>
);
}