2020-01-20 17:47:03 +01:00
|
|
|
// @flow
|
2021-03-18 16:41:21 +01:00
|
|
|
import { ENABLE_NO_SOURCE_CLAIMS } from 'config';
|
2021-03-03 20:23:42 +01:00
|
|
|
import * as CS from 'constants/claim_search';
|
2020-01-20 17:47:03 +01:00
|
|
|
import React from 'react';
|
|
|
|
import { createNormalizedClaimSearchKey, MATURE_TAGS } from 'lbry-redux';
|
|
|
|
import ClaimPreviewTile from 'component/claimPreviewTile';
|
2020-05-21 17:38:28 +02:00
|
|
|
import { useHistory } from 'react-router';
|
2020-01-20 17:47:03 +01:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
uris: Array<string>,
|
|
|
|
doClaimSearch: ({}) => void,
|
|
|
|
showNsfw: boolean,
|
2020-04-15 18:43:22 +02:00
|
|
|
hideReposts: boolean,
|
2021-03-03 19:50:16 +01:00
|
|
|
history: { action: string, push: (string) => void, replace: (string) => void },
|
2020-01-20 17:47:03 +01:00
|
|
|
claimSearchByQuery: {
|
|
|
|
[string]: Array<string>,
|
|
|
|
},
|
2020-09-11 21:48:23 +02:00
|
|
|
fetchingClaimSearchByQuery: {
|
|
|
|
[string]: boolean,
|
|
|
|
},
|
2020-01-20 17:47:03 +01:00
|
|
|
// claim search options are below
|
|
|
|
tags: Array<string>,
|
2021-03-03 19:50:16 +01:00
|
|
|
blockedUris: Array<string>,
|
|
|
|
mutedUris: Array<string>,
|
2020-10-05 19:38:40 +02:00
|
|
|
claimIds?: Array<string>,
|
2020-01-20 17:47:03 +01:00
|
|
|
channelIds?: Array<string>,
|
|
|
|
pageSize: number,
|
|
|
|
orderBy?: Array<string>,
|
|
|
|
releaseTime?: string,
|
2020-09-11 20:21:02 +02:00
|
|
|
languages?: Array<string>,
|
2021-03-26 00:52:28 +01:00
|
|
|
claimType?: string | Array<string>,
|
2020-01-20 17:47:03 +01:00
|
|
|
timestamp?: string,
|
2020-05-21 17:38:28 +02:00
|
|
|
feeAmount?: string,
|
2020-08-20 17:23:10 +02:00
|
|
|
limitClaimsPerChannel?: number,
|
2021-03-03 20:23:42 +01:00
|
|
|
streamTypes?: Array<string>,
|
2020-01-20 17:47:03 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
function ClaimTilesDiscover(props: Props) {
|
|
|
|
const {
|
|
|
|
doClaimSearch,
|
|
|
|
claimSearchByQuery,
|
|
|
|
showNsfw,
|
2020-04-15 18:43:22 +02:00
|
|
|
hideReposts,
|
2020-01-20 17:47:03 +01:00
|
|
|
// Below are options to pass that are forwarded to claim_search
|
|
|
|
tags,
|
|
|
|
channelIds,
|
2020-10-05 19:38:40 +02:00
|
|
|
claimIds,
|
2020-01-20 17:47:03 +01:00
|
|
|
orderBy,
|
|
|
|
pageSize = 8,
|
|
|
|
releaseTime,
|
2020-09-11 20:21:02 +02:00
|
|
|
languages,
|
2020-01-20 17:47:03 +01:00
|
|
|
claimType,
|
|
|
|
timestamp,
|
2020-05-21 17:38:28 +02:00
|
|
|
feeAmount,
|
2020-08-20 17:23:10 +02:00
|
|
|
limitClaimsPerChannel,
|
2020-09-11 21:48:23 +02:00
|
|
|
fetchingClaimSearchByQuery,
|
2021-03-03 20:23:42 +01:00
|
|
|
streamTypes,
|
|
|
|
// pin,
|
2020-01-20 17:47:03 +01:00
|
|
|
} = props;
|
2020-05-21 17:38:28 +02:00
|
|
|
const { location } = useHistory();
|
|
|
|
const urlParams = new URLSearchParams(location.search);
|
|
|
|
const feeAmountInUrl = urlParams.get('fee_amount');
|
2021-03-03 20:23:42 +01:00
|
|
|
const feeAmountParam = feeAmountInUrl || feeAmount || CS.FEE_AMOUNT_ONLY_FREE;
|
|
|
|
|
2020-01-20 17:47:03 +01:00
|
|
|
const options: {
|
|
|
|
page_size: number,
|
|
|
|
no_totals: boolean,
|
|
|
|
any_tags: Array<string>,
|
|
|
|
channel_ids: Array<string>,
|
2020-10-05 19:38:40 +02:00
|
|
|
claim_ids?: Array<string>,
|
2020-01-20 17:47:03 +01:00
|
|
|
not_channel_ids: Array<string>,
|
|
|
|
not_tags: Array<string>,
|
|
|
|
order_by: Array<string>,
|
2020-09-11 20:21:02 +02:00
|
|
|
languages?: Array<string>,
|
2020-01-20 17:47:03 +01:00
|
|
|
release_time?: string,
|
2021-03-26 00:52:28 +01:00
|
|
|
claim_type?: string | Array<string>,
|
2020-01-20 17:47:03 +01:00
|
|
|
timestamp?: string,
|
2020-05-21 17:38:28 +02:00
|
|
|
fee_amount?: string,
|
2020-08-20 17:23:10 +02:00
|
|
|
limit_claims_per_channel?: number,
|
2020-10-05 19:38:40 +02:00
|
|
|
stream_types?: Array<string>,
|
2021-03-18 16:41:21 +01:00
|
|
|
has_source?: boolean,
|
|
|
|
has_no_source?: boolean,
|
2020-01-20 17:47:03 +01:00
|
|
|
} = {
|
|
|
|
page_size: pageSize,
|
2020-02-28 18:12:19 +01:00
|
|
|
claim_type: claimType || undefined,
|
2020-01-20 17:47:03 +01:00
|
|
|
// no_totals makes it so the sdk doesn't have to calculate total number pages for pagination
|
|
|
|
// it's faster, but we will need to remove it if we start using total_pages
|
|
|
|
no_totals: true,
|
|
|
|
any_tags: tags || [],
|
|
|
|
not_tags: !showNsfw ? MATURE_TAGS : [],
|
2020-09-11 20:21:02 +02:00
|
|
|
any_languages: languages,
|
2020-01-20 17:47:03 +01:00
|
|
|
channel_ids: channelIds || [],
|
2021-03-04 18:43:12 +01:00
|
|
|
not_channel_ids: [],
|
2020-01-20 17:47:03 +01:00
|
|
|
order_by: orderBy || ['trending_group', 'trending_mixed'],
|
2021-03-03 20:23:42 +01:00
|
|
|
stream_types: streamTypes || [CS.FILE_VIDEO],
|
2020-01-20 17:47:03 +01:00
|
|
|
};
|
|
|
|
|
2021-03-26 00:52:28 +01:00
|
|
|
if (!ENABLE_NO_SOURCE_CLAIMS && (!claimType || claimType === 'stream')) {
|
2021-03-17 18:49:55 +01:00
|
|
|
options.has_source = true;
|
2021-03-18 16:41:21 +01:00
|
|
|
}
|
|
|
|
|
2020-01-20 17:47:03 +01:00
|
|
|
if (releaseTime) {
|
|
|
|
options.release_time = releaseTime;
|
|
|
|
}
|
|
|
|
|
2020-05-21 17:38:28 +02:00
|
|
|
if (feeAmountParam) {
|
|
|
|
options.fee_amount = feeAmountParam;
|
|
|
|
}
|
|
|
|
|
2020-08-20 17:23:10 +02:00
|
|
|
if (limitClaimsPerChannel) {
|
|
|
|
options.limit_claims_per_channel = limitClaimsPerChannel;
|
|
|
|
}
|
|
|
|
|
2020-02-28 23:36:22 +01:00
|
|
|
// https://github.com/lbryio/lbry-desktop/issues/3774
|
2020-04-15 18:43:22 +02:00
|
|
|
if (hideReposts) {
|
|
|
|
if (Array.isArray(options.claim_type)) {
|
2021-03-03 19:50:16 +01:00
|
|
|
options.claim_type = options.claim_type.filter((claimType) => claimType !== 'repost');
|
2020-04-15 18:43:22 +02:00
|
|
|
} else {
|
|
|
|
options.claim_type = ['stream', 'channel'];
|
|
|
|
}
|
|
|
|
}
|
2020-02-20 13:30:27 +01:00
|
|
|
|
2020-01-20 17:47:03 +01:00
|
|
|
if (claimType) {
|
|
|
|
options.claim_type = claimType;
|
|
|
|
}
|
2020-02-20 13:30:27 +01:00
|
|
|
|
2020-01-20 17:47:03 +01:00
|
|
|
if (timestamp) {
|
|
|
|
options.timestamp = timestamp;
|
|
|
|
}
|
|
|
|
|
2020-10-05 19:38:40 +02:00
|
|
|
if (claimIds) {
|
|
|
|
options.claim_ids = claimIds;
|
|
|
|
}
|
|
|
|
|
2020-01-20 17:47:03 +01:00
|
|
|
const claimSearchCacheQuery = createNormalizedClaimSearchKey(options);
|
2021-03-03 20:23:42 +01:00
|
|
|
const uris = claimSearchByQuery[claimSearchCacheQuery] || [];
|
|
|
|
|
2020-01-20 17:47:03 +01:00
|
|
|
// Don't use the query from createNormalizedClaimSearchKey for the effect since that doesn't include page & release_time
|
|
|
|
const optionsStringForEffect = JSON.stringify(options);
|
2020-09-11 21:48:23 +02:00
|
|
|
const isLoading = fetchingClaimSearchByQuery[claimSearchCacheQuery];
|
|
|
|
const shouldPerformSearch = !isLoading && uris.length === 0;
|
2020-01-20 17:47:03 +01:00
|
|
|
|
2021-03-03 20:23:42 +01:00
|
|
|
// const fixUri = 'lbry://@ElectroBOOM#9/remove-your-mustache#9';
|
|
|
|
// if (pin && uris && uris.length > 2 && window.location.pathname === '/') {
|
|
|
|
// if (uris.indexOf(fixUri) !== -1) {
|
|
|
|
// uris.splice(uris.indexOf(fixUri), 1);
|
|
|
|
// } else {
|
|
|
|
// uris.pop();
|
|
|
|
// }
|
|
|
|
// uris.splice(2, 0, fixUri);
|
|
|
|
// }
|
|
|
|
|
2020-01-20 17:47:03 +01:00
|
|
|
React.useEffect(() => {
|
|
|
|
if (shouldPerformSearch) {
|
|
|
|
const searchOptions = JSON.parse(optionsStringForEffect);
|
|
|
|
doClaimSearch(searchOptions);
|
|
|
|
}
|
2020-09-11 21:48:23 +02:00
|
|
|
}, [doClaimSearch, shouldPerformSearch, optionsStringForEffect]);
|
2020-01-20 17:47:03 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<ul className="claim-grid">
|
|
|
|
{uris && uris.length
|
2021-03-03 19:50:16 +01:00
|
|
|
? uris.map((uri) => <ClaimPreviewTile key={uri} uri={uri} />)
|
2020-01-20 17:47:03 +01:00
|
|
|
: new Array(pageSize).fill(1).map((x, i) => <ClaimPreviewTile key={i} placeholder />)}
|
|
|
|
</ul>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
export default ClaimTilesDiscover;
|