useGetLivestreams: add ability to filter by minimum viewers
This commit is contained in:
parent
ec5e14ca96
commit
0258c2d3c3
4 changed files with 8 additions and 5 deletions
|
@ -6,10 +6,11 @@ import { BITWAVE_LIVE_API } from 'constants/livestream';
|
|||
* Gets latest livestream info list. Returns null (instead of a blank object)
|
||||
* when there are no active livestreams.
|
||||
*
|
||||
* @param minViewers
|
||||
* @param refreshMs
|
||||
* @returns {{livestreamMap: null, loading: boolean}}
|
||||
*/
|
||||
export default function useGetLivestreams(refreshMs: number) {
|
||||
export default function useGetLivestreams(minViewers: number = 0, refreshMs: number = 0) {
|
||||
const [loading, setLoading] = React.useState(true);
|
||||
const [livestreamMap, setLivestreamMap] = React.useState(null);
|
||||
|
||||
|
@ -25,7 +26,9 @@ export default function useGetLivestreams(refreshMs: number) {
|
|||
}
|
||||
|
||||
const livestreamMap = res.data.reduce((acc, curr) => {
|
||||
acc[curr.claimId] = curr;
|
||||
if (curr.viewCount >= minViewers) {
|
||||
acc[curr.claimId] = curr;
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ type Props = {
|
|||
function ChannelsFollowingPage(props: Props) {
|
||||
const { subscribedChannels, tileLayout } = props;
|
||||
const hasSubsribedChannels = subscribedChannels.length > 0;
|
||||
const { livestreamMap } = useGetLivestreams(0);
|
||||
const { livestreamMap } = useGetLivestreams();
|
||||
|
||||
return !hasSubsribedChannels ? (
|
||||
<ChannelsFollowingDiscoverPage />
|
||||
|
|
|
@ -44,7 +44,7 @@ function DiscoverPage(props: Props) {
|
|||
const buttonRef = useRef();
|
||||
const isHovering = useHover(buttonRef);
|
||||
const isMobile = useIsMobile();
|
||||
const { livestreamMap } = useGetLivestreams(0);
|
||||
const { livestreamMap } = useGetLivestreams();
|
||||
|
||||
const urlParams = new URLSearchParams(search);
|
||||
const claimType = urlParams.get('claim_type');
|
||||
|
|
|
@ -25,7 +25,7 @@ function HomePage(props: Props) {
|
|||
const showPersonalizedTags = (authenticated || !IS_WEB) && followedTags && followedTags.length > 0;
|
||||
const showIndividualTags = showPersonalizedTags && followedTags.length < 5;
|
||||
const { default: getHomepage } = homepageData;
|
||||
const { livestreamMap } = useGetLivestreams(0);
|
||||
const { livestreamMap } = useGetLivestreams();
|
||||
|
||||
const rowData: Array<RowDataItem> = getHomepage(
|
||||
authenticated,
|
||||
|
|
Loading…
Reference in a new issue