2019-05-07 04:35:04 +02:00
|
|
|
// @flow
|
2020-08-03 22:14:43 +02:00
|
|
|
import { SHOW_ADS } from 'config';
|
2020-06-18 17:10:46 +02:00
|
|
|
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';
|
2020-06-18 17:10:46 +02:00
|
|
|
import { useHistory } from 'react-router-dom';
|
2019-08-29 03:39:21 +02:00
|
|
|
import Button from 'component/button';
|
2020-02-28 15:40:18 +01:00
|
|
|
import ClaimListDiscover from 'component/claimListDiscover';
|
2020-05-07 20:44:11 +02:00
|
|
|
import Ads from 'web/component/ads';
|
2020-06-18 17:10:46 +02:00
|
|
|
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 },
|
2019-11-22 02:37:25 +01:00
|
|
|
pageOfClaimsInChannel: Array<StreamClaim>,
|
2019-07-08 22:54:58 +02:00
|
|
|
channelIsBlocked: boolean,
|
2019-05-07 04:35:04 +02:00
|
|
|
channelIsMine: boolean,
|
|
|
|
fetchClaims: (string, number) => void,
|
2019-08-29 03:39:21 +02:00
|
|
|
channelIsBlackListed: boolean,
|
2020-04-22 14:07:09 +02:00
|
|
|
defaultPageSize?: number,
|
|
|
|
defaultInfiniteScroll?: Boolean,
|
2019-12-13 23:32:20 +01:00
|
|
|
claim: ?Claim,
|
2020-03-26 22:47:07 +01:00
|
|
|
isAuthenticated: boolean,
|
2020-06-18 17:10:46 +02:00
|
|
|
showMature: boolean,
|
2020-09-17 19:28:46 +02:00
|
|
|
tileLayout: boolean,
|
2019-05-07 04:35:04 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
function ChannelContent(props: Props) {
|
2020-04-22 14:07:09 +02:00
|
|
|
const {
|
|
|
|
uri,
|
|
|
|
fetching,
|
|
|
|
channelIsMine,
|
|
|
|
channelIsBlocked,
|
|
|
|
channelIsBlackListed,
|
|
|
|
claim,
|
|
|
|
isAuthenticated,
|
|
|
|
defaultPageSize = CS.PAGE_SIZE,
|
|
|
|
defaultInfiniteScroll = true,
|
2020-06-18 17:10:46 +02:00
|
|
|
showMature,
|
2020-09-17 19:28:46 +02:00
|
|
|
tileLayout,
|
2020-04-22 14:07:09 +02:00
|
|
|
} = props;
|
2019-12-13 23:32:20 +01:00
|
|
|
const claimsInChannel = (claim && claim.meta.claims_in_channel) || 0;
|
2020-06-18 17:10:46 +02:00
|
|
|
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' : ''
|
2020-06-18 17:10:46 +02:00
|
|
|
}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}, 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} />
|
2019-12-13 23:32:20 +01:00
|
|
|
)}
|
|
|
|
|
2019-08-29 03:39:21 +02:00
|
|
|
{!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">
|
2019-08-29 03:39:21 +02:00
|
|
|
<Button button="link" href="https://lbry.com/faq/dmca" label={__('Read More')} />
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
)}
|
|
|
|
|
2019-07-08 22:54:58 +02:00
|
|
|
{!fetching && channelIsBlocked && (
|
|
|
|
<div className="card--section">
|
2019-08-02 17:11:31 +02:00
|
|
|
<h2 className="help">{__('You have blocked this channel content.')}</h2>
|
2019-07-08 22:54:58 +02:00
|
|
|
</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
|
2020-09-17 19:28:46 +02:00
|
|
|
tileLayout={tileLayout}
|
2020-06-18 17:10:46 +02:00
|
|
|
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}
|
2020-04-22 14:07:09 +02:00
|
|
|
pageSize={defaultPageSize}
|
2020-09-30 20:46:17 +02:00
|
|
|
streamType={CS.CONTENT_ALL}
|
2020-04-22 14:07:09 +02:00
|
|
|
infiniteScroll={defaultInfiniteScroll}
|
2020-08-03 22:14:43 +02:00
|
|
|
injectedItem={SHOW_ADS && !isAuthenticated && IS_WEB && <Ads type="video" />}
|
2020-06-18 17:10:46 +02:00
|
|
|
meta={
|
|
|
|
<Form onSubmit={() => {}} className="wunderbar--inline">
|
|
|
|
<Icon icon={ICONS.SEARCH} />
|
|
|
|
<FormField
|
2020-07-15 21:59:21 +02:00
|
|
|
className="wunderbar__input--inline"
|
2020-06-18 17:10:46 +02:00
|
|
|
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-07-08 22:54:58 +02:00
|
|
|
)}
|
2019-05-07 04:35:04 +02:00
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-06-18 17:10:46 +02:00
|
|
|
export default ChannelContent;
|