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

168 lines
5.3 KiB
React
Raw Normal View History

2019-05-07 04:35:04 +02:00
// @flow
import { SHOW_ADS } from 'config';
import * as CS from 'constants/claim_search';
import * as ICONS from 'constants/icons';
2019-05-07 04:35:04 +02:00
import React, { Fragment } from 'react';
import HiddenNsfwClaims from 'component/hiddenNsfwClaims';
import { useHistory } from 'react-router-dom';
import Button from 'component/button';
2020-02-28 15:40:18 +01:00
import ClaimListDiscover from 'component/claimListDiscover';
import Ads from 'web/component/ads';
import Icon from 'component/common/icon';
2021-03-19 21:14:31 +01:00
import LivestreamLink from 'component/livestreamLink';
import { Form, FormField } from 'component/common/form';
import { DEBOUNCE_WAIT_DURATION_MS } from 'constants/search';
import { lighthouse } from 'redux/actions/search';
2019-05-07 04:35:04 +02:00
type Props = {
uri: string,
totalPages: number,
fetching: boolean,
params: { page: number },
pageOfClaimsInChannel: Array<StreamClaim>,
channelIsBlocked: boolean,
2019-05-07 04:35:04 +02:00
channelIsMine: boolean,
fetchClaims: (string, number) => void,
channelIsBlackListed: boolean,
defaultPageSize?: number,
defaultInfiniteScroll?: Boolean,
claim: ?Claim,
2020-03-26 22:47:07 +01:00
isAuthenticated: boolean,
showMature: boolean,
tileLayout: boolean,
viewHiddenChannels: boolean,
doResolveUris: (Array<string>, boolean) => void,
2019-05-07 04:35:04 +02:00
};
function ChannelContent(props: Props) {
const {
uri,
fetching,
channelIsMine,
channelIsBlocked,
channelIsBlackListed,
claim,
isAuthenticated,
defaultPageSize = CS.PAGE_SIZE,
defaultInfiniteScroll = true,
showMature,
tileLayout,
viewHiddenChannels,
doResolveUris,
} = props;
const claimsInChannel = (claim && claim.meta.claims_in_channel) || 0;
const [searchQuery, setSearchQuery] = React.useState('');
const [searchResults, setSearchResults] = React.useState(undefined);
const {
location: { pathname, search },
} = useHistory();
const url = `${pathname}${search}`;
const claimId = claim && claim.claim_id;
function handleInputChange(e) {
const { value } = e.target;
setSearchQuery(value);
}
React.useEffect(() => {
const timer = setTimeout(() => {
if (searchQuery === '' || !claimId) {
// In order to display original search results, search results must be set to null. A query of '' should display original results.
return setSearchResults(null);
} else {
lighthouse
.search(
`s=${encodeURIComponent(searchQuery)}&channel_id=${encodeURIComponent(claimId)}${
2021-03-17 20:52:23 +01:00
!showMature ? '&nsfw=false&size=50&from=0' : ''
}`
)
.then((results) => {
const urls = results.map(({ name, claimId }) => {
return `lbry://${name}#${claimId}`;
});
// Batch-resolve the urls before calling 'setSearchResults', as the
// latter will immediately cause the tiles to resolve, ending up
// calling doResolveUri one by one before the batched one.
doResolveUris(urls, true);
setSearchResults(urls);
})
.catch(() => {
setSearchResults(null);
});
}
}, DEBOUNCE_WAIT_DURATION_MS);
return () => clearTimeout(timer);
}, [claimId, searchQuery, showMature]);
React.useEffect(() => {
setSearchQuery('');
setSearchResults(null);
}, [url]);
2020-02-28 15:40:18 +01:00
2019-05-07 04:35:04 +02:00
return (
<Fragment>
2020-02-28 15:40:18 +01:00
{!fetching && Boolean(claimsInChannel) && !channelIsBlocked && !channelIsBlackListed && (
<HiddenNsfwClaims uri={uri} />
)}
2021-03-19 21:14:31 +01:00
<LivestreamLink uri={uri} />
{!fetching && channelIsBlackListed && (
<section className="card card--section">
<p>
{__(
'In response to a complaint we received under the US Digital Millennium Copyright Act, we have blocked access to this channel from our applications.'
)}
</p>
2020-05-01 19:55:42 +02:00
<div className="section__actions">
<Button button="link" href="https://lbry.com/faq/dmca" label={__('Read More')} />
</div>
</section>
)}
{!fetching && channelIsBlocked && (
<div className="card--section">
2019-08-02 17:11:31 +02:00
<h2 className="help">{__('You have blocked this channel content.')}</h2>
</div>
)}
2019-05-07 04:35:04 +02:00
2020-02-28 15:40:18 +01:00
{!channelIsMine && claimsInChannel > 0 && <HiddenNsfwClaims uri={uri} />}
2019-10-27 15:41:43 +01:00
2020-02-28 15:40:18 +01:00
{claim && claimsInChannel > 0 ? (
2020-03-26 22:47:07 +01:00
<ClaimListDiscover
showHiddenByUser={viewHiddenChannels}
2020-09-30 20:46:17 +02:00
forceShowReposts
tileLayout={tileLayout}
uris={searchResults}
2020-03-26 22:47:07 +01:00
channelIds={[claim.claim_id]}
2020-09-30 20:46:17 +02:00
feeAmount={CS.FEE_AMOUNT_ANY}
2020-03-26 22:47:07 +01:00
defaultOrderBy={CS.ORDER_BY_NEW}
pageSize={defaultPageSize}
infiniteScroll={defaultInfiniteScroll}
injectedItem={SHOW_ADS && !isAuthenticated && IS_WEB && <Ads type="video" />}
meta={
<Form onSubmit={() => {}} className="wunderbar--inline">
<Icon icon={ICONS.SEARCH} />
<FormField
className="wunderbar__input--inline"
value={searchQuery}
onChange={handleInputChange}
type="text"
placeholder={__('Search')}
/>
</Form>
}
isChannel
channelIsMine={channelIsMine}
2020-03-26 22:47:07 +01:00
/>
2020-02-28 15:40:18 +01:00
) : (
2020-06-02 02:08:53 +02:00
<section className="main--empty">{__("This channel hasn't published anything yet")}</section>
)}
2019-05-07 04:35:04 +02:00
</Fragment>
);
}
export default ChannelContent;