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

159 lines
4.8 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';
import { Form, FormField } from 'component/common/form';
import { DEBOUNCE_WAIT_DURATION_MS } from 'constants/search';
const LIGHTHOUSE_URL = 'https://lighthouse.lbry.com/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,
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,
} = 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);
}
function getResults(fetchUrl) {
fetch(fetchUrl)
.then(res => res.json())
.then(results => {
const urls = results.map(({ name, claimId }) => {
return `lbry://${name}#${claimId}`;
});
setSearchResults(urls);
})
.catch(() => {
setSearchResults(null);
});
}
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 {
getResults(
`${LIGHTHOUSE_URL}?s=${encodeURIComponent(searchQuery)}&channel_id=${encodeURIComponent(claimId)}${
2020-10-27 19:51:05 +01:00
!showMature ? '&nsfw=false&size=999&from=0' : ''
}`
);
}
}, 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} />
)}
{!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
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
claimType={CS.CLAIM_TYPES}
feeAmount={CS.FEE_AMOUNT_ANY}
2020-03-26 22:47:07 +01:00
defaultOrderBy={CS.ORDER_BY_NEW}
pageSize={defaultPageSize}
2020-09-30 20:46:17 +02:00
streamType={CS.CONTENT_ALL}
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>
}
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;