2021-12-16 22:59:13 +01:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import * as CS from 'constants/claim_search';
|
|
|
|
import moment from 'moment';
|
|
|
|
import * as ICONS from 'constants/icons';
|
2022-03-02 03:15:06 +01:00
|
|
|
import { useIsLargeScreen, useIsMobile } from 'effects/use-screensize';
|
2021-12-16 22:59:13 +01:00
|
|
|
import ClaimListDiscover from 'component/claimListDiscover';
|
|
|
|
import Button from 'component/button';
|
|
|
|
import { LIVESTREAM_UPCOMING_BUFFER } from 'constants/livestream';
|
2022-01-11 17:33:33 +01:00
|
|
|
import { SCHEDULED_LIVESTREAM_TAG } from 'constants/tags';
|
2022-01-05 22:20:43 +01:00
|
|
|
import * as SETTINGS from 'constants/settings';
|
2021-12-16 22:59:13 +01:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
channelIds: Array<string>,
|
|
|
|
tileLayout: boolean,
|
|
|
|
liveUris: Array<string>,
|
|
|
|
limitClaimsPerChannel?: number,
|
2022-01-06 22:13:26 +01:00
|
|
|
onLoad: (number) => void,
|
2022-01-11 17:46:13 +01:00
|
|
|
showHideSetting: boolean,
|
2022-01-05 22:20:43 +01:00
|
|
|
// --- perform ---
|
|
|
|
setClientSetting: (string, boolean | string | number, boolean) => void,
|
|
|
|
doShowSnackBar: (string) => void,
|
2021-12-16 22:59:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const ScheduledStreams = (props: Props) => {
|
2022-01-06 22:13:26 +01:00
|
|
|
const {
|
|
|
|
channelIds,
|
2022-03-02 03:11:02 +01:00
|
|
|
// tileLayout,
|
2022-01-06 22:13:26 +01:00
|
|
|
liveUris = [],
|
|
|
|
limitClaimsPerChannel,
|
|
|
|
setClientSetting,
|
|
|
|
doShowSnackBar,
|
|
|
|
onLoad,
|
2022-01-11 17:46:13 +01:00
|
|
|
showHideSetting = true,
|
2022-01-06 22:13:26 +01:00
|
|
|
} = props;
|
2022-03-02 03:15:06 +01:00
|
|
|
const isMobileScreen = useIsMobile();
|
2021-12-16 22:59:13 +01:00
|
|
|
const isLargeScreen = useIsLargeScreen();
|
|
|
|
|
|
|
|
const [totalUpcomingLivestreams, setTotalUpcomingLivestreams] = React.useState(0);
|
|
|
|
const [showAllUpcoming, setShowAllUpcoming] = React.useState(false);
|
|
|
|
|
|
|
|
const showUpcomingLivestreams = totalUpcomingLivestreams > 0;
|
2022-03-02 03:15:06 +01:00
|
|
|
const useSwipeLayout = totalUpcomingLivestreams > 1 && isMobileScreen;
|
2021-12-16 22:59:13 +01:00
|
|
|
|
|
|
|
const upcomingMax = React.useMemo(() => {
|
2022-01-06 22:13:26 +01:00
|
|
|
if (showAllUpcoming || useSwipeLayout) return 50;
|
2021-12-16 22:59:13 +01:00
|
|
|
if (isLargeScreen) return 6;
|
2022-03-02 03:15:06 +01:00
|
|
|
if (isMobileScreen) return 3;
|
2021-12-16 22:59:13 +01:00
|
|
|
return 4;
|
2022-03-02 03:15:06 +01:00
|
|
|
}, [showAllUpcoming, isMobileScreen, isLargeScreen, useSwipeLayout]);
|
2021-12-16 22:59:13 +01:00
|
|
|
|
|
|
|
const loadedCallback = (total) => {
|
|
|
|
setTotalUpcomingLivestreams(total);
|
2022-01-06 22:13:26 +01:00
|
|
|
if (typeof onLoad === 'function') onLoad(total);
|
2021-12-16 22:59:13 +01:00
|
|
|
};
|
|
|
|
|
2022-01-05 22:20:43 +01:00
|
|
|
const hideScheduledStreams = () => {
|
|
|
|
setClientSetting(SETTINGS.HIDE_SCHEDULED_LIVESTREAMS, true, true);
|
|
|
|
doShowSnackBar(__('Scheduled streams hidden, you can re-enable them in settings.'));
|
|
|
|
};
|
|
|
|
|
|
|
|
const Header = () => {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{__('Upcoming Livestreams')}
|
2022-01-11 17:46:13 +01:00
|
|
|
{showHideSetting && (
|
|
|
|
<Button button="link" label={__('Hide')} onClick={hideScheduledStreams} className={'ml-s text-s'} />
|
|
|
|
)}
|
2022-01-05 22:20:43 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-12-16 22:59:13 +01:00
|
|
|
return (
|
2022-01-06 22:13:26 +01:00
|
|
|
<div className={'mb-m mt-m md:mb-xl'} style={{ display: showUpcomingLivestreams ? 'block' : 'none' }}>
|
2021-12-22 17:12:44 +01:00
|
|
|
<ClaimListDiscover
|
2022-01-06 22:13:26 +01:00
|
|
|
swipeLayout={useSwipeLayout}
|
2021-12-22 17:12:44 +01:00
|
|
|
useSkeletonScreen={false}
|
|
|
|
channelIds={channelIds}
|
|
|
|
limitClaimsPerChannel={limitClaimsPerChannel}
|
|
|
|
pageSize={50}
|
|
|
|
streamType={'all'}
|
|
|
|
hasNoSource
|
|
|
|
orderBy={CS.ORDER_BY_NEW_ASC}
|
2022-03-02 03:11:02 +01:00
|
|
|
// List-layout is not scrollable, and doesn't look good either. Force
|
|
|
|
// to tile-only until we can fix it. If we decide to always use
|
|
|
|
// tile-only, then remove the parameter for ScheduledStreams
|
|
|
|
// tileLayout={tileLayout}
|
|
|
|
tileLayout
|
2022-01-11 17:33:33 +01:00
|
|
|
tags={[SCHEDULED_LIVESTREAM_TAG]}
|
2022-01-11 18:08:55 +01:00
|
|
|
claimType={[CS.CLAIM_STREAM]}
|
2021-12-22 17:12:44 +01:00
|
|
|
releaseTime={`>${moment().subtract(LIVESTREAM_UPCOMING_BUFFER, 'minutes').startOf('minute').unix()}`}
|
|
|
|
hideAdvancedFilter
|
|
|
|
hideFilters
|
|
|
|
infiniteScroll={false}
|
|
|
|
showNoSourceClaims
|
|
|
|
hideLayoutButton
|
2022-02-11 19:50:55 +01:00
|
|
|
// header={__('🔴 Upcoming Livestreams')}
|
2022-01-05 22:20:43 +01:00
|
|
|
header={<Header />}
|
2021-12-22 17:12:44 +01:00
|
|
|
maxClaimRender={upcomingMax}
|
|
|
|
excludeUris={liveUris}
|
|
|
|
loadedCallback={loadedCallback}
|
|
|
|
/>
|
2022-01-06 22:13:26 +01:00
|
|
|
{totalUpcomingLivestreams > upcomingMax && !showAllUpcoming && !useSwipeLayout && (
|
2021-12-22 17:12:44 +01:00
|
|
|
<div className="livestream-list--view-more">
|
|
|
|
<Button
|
|
|
|
label={__('Show more upcoming livestreams')}
|
|
|
|
button="link"
|
|
|
|
iconRight={ICONS.ARROW_RIGHT}
|
|
|
|
className="claim-grid__title--secondary"
|
|
|
|
onClick={() => {
|
|
|
|
setShowAllUpcoming(true);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{showAllUpcoming && (
|
|
|
|
<div className="livestream-list--view-more">
|
|
|
|
<Button
|
|
|
|
label={__('Show less upcoming livestreams')}
|
|
|
|
button="link"
|
|
|
|
iconRight={ICONS.ARROW_RIGHT}
|
|
|
|
className="claim-grid__title--secondary"
|
|
|
|
onClick={() => {
|
|
|
|
setShowAllUpcoming(false);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
2021-12-16 22:59:13 +01:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ScheduledStreams;
|