useGetLivestreams: add ability to filter by minimum viewers

This commit is contained in:
infinite-persistence 2021-04-29 16:25:06 +08:00 committed by Sean Yesmunt
parent ec5e14ca96
commit 0258c2d3c3
4 changed files with 8 additions and 5 deletions

View file

@ -6,10 +6,11 @@ import { BITWAVE_LIVE_API } from 'constants/livestream';
* Gets latest livestream info list. Returns null (instead of a blank object) * Gets latest livestream info list. Returns null (instead of a blank object)
* when there are no active livestreams. * when there are no active livestreams.
* *
* @param minViewers
* @param refreshMs * @param refreshMs
* @returns {{livestreamMap: null, loading: boolean}} * @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 [loading, setLoading] = React.useState(true);
const [livestreamMap, setLivestreamMap] = React.useState(null); const [livestreamMap, setLivestreamMap] = React.useState(null);
@ -25,7 +26,9 @@ export default function useGetLivestreams(refreshMs: number) {
} }
const livestreamMap = res.data.reduce((acc, curr) => { const livestreamMap = res.data.reduce((acc, curr) => {
acc[curr.claimId] = curr; if (curr.viewCount >= minViewers) {
acc[curr.claimId] = curr;
}
return acc; return acc;
}, {}); }, {});

View file

@ -19,7 +19,7 @@ type Props = {
function ChannelsFollowingPage(props: Props) { function ChannelsFollowingPage(props: Props) {
const { subscribedChannels, tileLayout } = props; const { subscribedChannels, tileLayout } = props;
const hasSubsribedChannels = subscribedChannels.length > 0; const hasSubsribedChannels = subscribedChannels.length > 0;
const { livestreamMap } = useGetLivestreams(0); const { livestreamMap } = useGetLivestreams();
return !hasSubsribedChannels ? ( return !hasSubsribedChannels ? (
<ChannelsFollowingDiscoverPage /> <ChannelsFollowingDiscoverPage />

View file

@ -44,7 +44,7 @@ function DiscoverPage(props: Props) {
const buttonRef = useRef(); const buttonRef = useRef();
const isHovering = useHover(buttonRef); const isHovering = useHover(buttonRef);
const isMobile = useIsMobile(); const isMobile = useIsMobile();
const { livestreamMap } = useGetLivestreams(0); const { livestreamMap } = useGetLivestreams();
const urlParams = new URLSearchParams(search); const urlParams = new URLSearchParams(search);
const claimType = urlParams.get('claim_type'); const claimType = urlParams.get('claim_type');

View file

@ -25,7 +25,7 @@ function HomePage(props: Props) {
const showPersonalizedTags = (authenticated || !IS_WEB) && followedTags && followedTags.length > 0; const showPersonalizedTags = (authenticated || !IS_WEB) && followedTags && followedTags.length > 0;
const showIndividualTags = showPersonalizedTags && followedTags.length < 5; const showIndividualTags = showPersonalizedTags && followedTags.length < 5;
const { default: getHomepage } = homepageData; const { default: getHomepage } = homepageData;
const { livestreamMap } = useGetLivestreams(0); const { livestreamMap } = useGetLivestreams();
const rowData: Array<RowDataItem> = getHomepage( const rowData: Array<RowDataItem> = getHomepage(
authenticated, authenticated,