2019-06-11 20:10:58 +02:00
|
|
|
// @flow
|
2019-06-17 22:32:38 +02:00
|
|
|
import type { Node } from 'react';
|
2020-01-02 17:30:27 +01:00
|
|
|
import classnames from 'classnames';
|
2019-09-11 20:29:20 +02:00
|
|
|
import React, { Fragment, useEffect, useState } from 'react';
|
2019-07-17 22:49:06 +02:00
|
|
|
import { withRouter } from 'react-router';
|
2020-02-10 20:43:24 +01:00
|
|
|
import * as CS from 'constants/claim_search';
|
2019-07-31 21:07:26 +02:00
|
|
|
import { createNormalizedClaimSearchKey, MATURE_TAGS } from 'lbry-redux';
|
2019-06-11 20:10:58 +02:00
|
|
|
import { FormField } from 'component/common/form';
|
2019-08-15 00:32:55 +02:00
|
|
|
import Button from 'component/button';
|
2019-07-17 22:49:06 +02:00
|
|
|
import moment from 'moment';
|
2019-06-19 07:05:43 +02:00
|
|
|
import ClaimList from 'component/claimList';
|
2019-06-27 08:18:45 +02:00
|
|
|
import ClaimPreview from 'component/claimPreview';
|
2019-07-17 22:49:06 +02:00
|
|
|
import { toCapitalCase } from 'util/string';
|
2019-11-13 19:11:51 +01:00
|
|
|
import I18nMessage from 'component/i18nMessage';
|
2020-02-10 20:43:24 +01:00
|
|
|
import * as ICONS from 'constants/icons';
|
2019-06-11 20:10:58 +02:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
uris: Array<string>,
|
2019-07-01 03:52:38 +02:00
|
|
|
subscribedChannels: Array<Subscription>,
|
2019-07-11 20:06:25 +02:00
|
|
|
doClaimSearch: ({}) => void,
|
2019-06-11 20:10:58 +02:00
|
|
|
loading: boolean,
|
2019-07-17 22:49:06 +02:00
|
|
|
personalView: boolean,
|
2020-03-10 00:46:37 +01:00
|
|
|
doToggleTagFollowDesktop: string => void,
|
2019-06-17 22:32:38 +02:00
|
|
|
meta?: Node,
|
2019-07-03 06:43:32 +02:00
|
|
|
showNsfw: boolean,
|
2020-04-15 18:43:22 +02:00
|
|
|
hideReposts: boolean,
|
2019-07-17 22:49:06 +02:00
|
|
|
history: { action: string, push: string => void, replace: string => void },
|
|
|
|
location: { search: string, pathname: string },
|
|
|
|
claimSearchByQuery: {
|
|
|
|
[string]: Array<string>,
|
|
|
|
},
|
2019-08-02 02:56:25 +02:00
|
|
|
hiddenUris: Array<string>,
|
2019-10-14 03:19:24 +02:00
|
|
|
hiddenNsfwMessage?: Node,
|
2020-01-02 17:30:27 +01:00
|
|
|
channelIds?: Array<string>,
|
2020-03-12 02:43:52 +01:00
|
|
|
tags: string, // these are just going to be string. pass a CSV if you want multi
|
|
|
|
defaultTags: string,
|
2020-02-10 20:43:24 +01:00
|
|
|
orderBy?: Array<string>,
|
|
|
|
defaultOrderBy?: string,
|
|
|
|
freshness?: string,
|
|
|
|
defaultFreshness?: string,
|
2020-02-11 20:04:51 +01:00
|
|
|
header?: Node,
|
2020-01-02 21:36:03 +01:00
|
|
|
headerLabel?: string | Node,
|
2020-02-11 20:04:51 +01:00
|
|
|
name?: string,
|
2020-02-10 20:43:24 +01:00
|
|
|
hideBlock?: boolean,
|
2020-02-28 22:52:42 +01:00
|
|
|
hideFilter?: boolean,
|
|
|
|
claimType?: Array<string>,
|
|
|
|
defaultClaimType?: Array<string>,
|
2020-02-10 20:43:24 +01:00
|
|
|
streamType?: string | Array<string>,
|
|
|
|
defaultStreamType?: string | Array<string>,
|
2020-02-11 20:04:51 +01:00
|
|
|
renderProperties?: Claim => Node,
|
2020-02-12 19:59:48 +01:00
|
|
|
includeSupportAction?: boolean,
|
2020-03-19 17:54:37 +01:00
|
|
|
repostedClaimId?: string,
|
2020-02-28 22:52:42 +01:00
|
|
|
pageSize?: number,
|
2020-03-12 02:43:52 +01:00
|
|
|
followedTags?: Array<Tag>,
|
2020-03-26 22:47:07 +01:00
|
|
|
injectedItem: ?Node,
|
2020-04-22 14:07:09 +02:00
|
|
|
infiniteScroll?: Boolean,
|
2019-06-11 20:10:58 +02:00
|
|
|
};
|
|
|
|
|
2019-06-19 07:05:43 +02:00
|
|
|
function ClaimListDiscover(props: Props) {
|
2019-07-17 22:49:06 +02:00
|
|
|
const {
|
|
|
|
doClaimSearch,
|
|
|
|
claimSearchByQuery,
|
|
|
|
tags,
|
2020-03-12 02:43:52 +01:00
|
|
|
defaultTags,
|
2019-07-17 22:49:06 +02:00
|
|
|
loading,
|
|
|
|
meta,
|
2020-01-02 17:30:27 +01:00
|
|
|
channelIds,
|
2019-07-17 22:49:06 +02:00
|
|
|
showNsfw,
|
2020-04-15 18:43:22 +02:00
|
|
|
hideReposts,
|
2019-07-17 22:49:06 +02:00
|
|
|
history,
|
|
|
|
location,
|
2019-08-02 02:56:25 +02:00
|
|
|
hiddenUris,
|
2019-10-14 03:19:24 +02:00
|
|
|
hiddenNsfwMessage,
|
2020-02-11 20:04:51 +01:00
|
|
|
defaultOrderBy,
|
2020-02-10 20:43:24 +01:00
|
|
|
orderBy,
|
2020-01-02 21:36:03 +01:00
|
|
|
headerLabel,
|
2020-02-11 20:04:51 +01:00
|
|
|
header,
|
|
|
|
name,
|
2020-02-21 17:33:14 +01:00
|
|
|
claimType,
|
2020-02-26 19:39:03 +01:00
|
|
|
pageSize,
|
2020-02-10 20:43:24 +01:00
|
|
|
hideBlock,
|
|
|
|
defaultClaimType,
|
|
|
|
streamType,
|
|
|
|
defaultStreamType,
|
|
|
|
freshness,
|
2020-02-27 23:15:17 +01:00
|
|
|
defaultFreshness = CS.FRESH_WEEK,
|
2020-02-11 20:04:51 +01:00
|
|
|
renderProperties,
|
2020-02-12 19:59:48 +01:00
|
|
|
includeSupportAction,
|
2020-03-19 17:54:37 +01:00
|
|
|
repostedClaimId,
|
2020-02-28 22:52:42 +01:00
|
|
|
hideFilter,
|
2020-04-22 14:07:09 +02:00
|
|
|
infiniteScroll = true,
|
2020-03-12 02:43:52 +01:00
|
|
|
followedTags,
|
2020-03-26 22:47:07 +01:00
|
|
|
injectedItem,
|
2019-07-17 22:49:06 +02:00
|
|
|
} = props;
|
|
|
|
const didNavigateForward = history.action === 'PUSH';
|
2019-09-11 20:29:20 +02:00
|
|
|
const { search } = location;
|
2020-02-10 20:43:24 +01:00
|
|
|
|
|
|
|
const [page, setPage] = useState(1);
|
2019-11-13 19:11:51 +01:00
|
|
|
const [forceRefresh, setForceRefresh] = useState();
|
2020-02-10 20:43:24 +01:00
|
|
|
const [expanded, setExpanded] = useState(false);
|
2020-03-12 02:43:52 +01:00
|
|
|
const followed = (followedTags && followedTags.map(t => t.name)) || [];
|
2019-07-17 22:49:06 +02:00
|
|
|
const urlParams = new URLSearchParams(search);
|
2020-03-12 02:43:52 +01:00
|
|
|
const tagsParam = // can be 'x,y,z' or 'x' or ['x','y'] or CS.CONSTANT
|
|
|
|
(tags && getParamFromTags(tags)) ||
|
|
|
|
(urlParams.get(CS.TAGS_KEY) !== null && urlParams.get(CS.TAGS_KEY)) ||
|
|
|
|
(defaultTags && getParamFromTags(defaultTags));
|
2020-02-10 20:43:24 +01:00
|
|
|
const orderParam = orderBy || urlParams.get(CS.ORDER_BY_KEY) || defaultOrderBy || CS.ORDER_BY_TRENDING;
|
2020-02-27 23:15:17 +01:00
|
|
|
const freshnessParam = freshness || urlParams.get(CS.FRESH_KEY) || defaultFreshness;
|
2020-02-10 20:43:24 +01:00
|
|
|
const contentTypeParam = urlParams.get(CS.CONTENT_KEY);
|
|
|
|
const claimTypeParam =
|
|
|
|
claimType || (CS.CLAIM_TYPES.includes(contentTypeParam) && contentTypeParam) || defaultClaimType || null;
|
|
|
|
const streamTypeParam =
|
|
|
|
streamType || (CS.FILE_TYPES.includes(contentTypeParam) && contentTypeParam) || defaultStreamType || null;
|
|
|
|
const durationParam = urlParams.get(CS.DURATION_KEY) || null;
|
|
|
|
|
2020-03-01 23:51:21 +01:00
|
|
|
const showDuration = !(claimType && claimType === CS.CLAIM_CHANNEL);
|
2020-02-10 20:43:24 +01:00
|
|
|
const isFiltered = () =>
|
2020-03-12 02:43:52 +01:00
|
|
|
Boolean(
|
|
|
|
urlParams.get(CS.FRESH_KEY) ||
|
|
|
|
urlParams.get(CS.CONTENT_KEY) ||
|
|
|
|
urlParams.get(CS.DURATION_KEY) ||
|
|
|
|
urlParams.get(CS.TAGS_KEY)
|
|
|
|
);
|
2020-02-10 20:43:24 +01:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (isFiltered()) setExpanded(true);
|
2020-03-10 00:46:37 +01:00
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
2020-02-10 20:43:24 +01:00
|
|
|
}, []);
|
|
|
|
|
2020-03-19 17:54:37 +01:00
|
|
|
let options: {
|
2019-07-17 22:49:06 +02:00
|
|
|
page_size: number,
|
|
|
|
page: number,
|
|
|
|
no_totals: boolean,
|
2020-03-12 02:43:52 +01:00
|
|
|
any_tags?: Array<string>,
|
2020-02-10 20:43:24 +01:00
|
|
|
not_tags: Array<string>,
|
2019-07-17 22:49:06 +02:00
|
|
|
channel_ids: Array<string>,
|
2019-08-02 02:56:25 +02:00
|
|
|
not_channel_ids: Array<string>,
|
2019-07-17 22:49:06 +02:00
|
|
|
order_by: Array<string>,
|
|
|
|
release_time?: string,
|
2020-02-28 18:12:19 +01:00
|
|
|
claim_type?: Array<string>,
|
2020-02-11 20:04:51 +01:00
|
|
|
name?: string,
|
2020-02-10 20:43:24 +01:00
|
|
|
duration?: string,
|
2020-03-24 17:31:23 +01:00
|
|
|
reposted_claim_id?: string,
|
2020-02-10 20:43:24 +01:00
|
|
|
stream_types?: any,
|
2019-07-17 22:49:06 +02:00
|
|
|
} = {
|
2020-02-10 20:43:24 +01:00
|
|
|
page_size: pageSize || CS.PAGE_SIZE,
|
2019-07-17 22:49:06 +02:00
|
|
|
page,
|
2020-02-11 20:04:51 +01:00
|
|
|
name,
|
2020-02-28 18:12:19 +01:00
|
|
|
claim_type: claimType || undefined,
|
2019-07-17 22:49:06 +02: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,
|
2020-01-02 17:30:27 +01:00
|
|
|
channel_ids: channelIds || [],
|
2020-01-24 21:43:07 +01:00
|
|
|
not_channel_ids:
|
|
|
|
// If channelIds were passed in, we don't need not_channel_ids
|
|
|
|
!channelIds && hiddenUris && hiddenUris.length ? hiddenUris.map(hiddenUri => hiddenUri.split('#')[1]) : [],
|
2019-07-17 22:49:06 +02:00
|
|
|
not_tags: !showNsfw ? MATURE_TAGS : [],
|
|
|
|
order_by:
|
2020-02-10 20:43:24 +01:00
|
|
|
orderParam === CS.ORDER_BY_TRENDING
|
|
|
|
? CS.ORDER_BY_TRENDING_VALUE
|
|
|
|
: orderParam === CS.ORDER_BY_NEW
|
|
|
|
? CS.ORDER_BY_NEW_VALUE
|
|
|
|
: CS.ORDER_BY_TOP_VALUE, // Sort by top
|
2019-07-17 22:49:06 +02:00
|
|
|
};
|
2020-03-19 17:54:37 +01:00
|
|
|
|
|
|
|
if (repostedClaimId) {
|
|
|
|
// SDK chokes on reposted_claim_id of null or false, needs to not be present if no value
|
|
|
|
options.reposted_claim_id = repostedClaimId;
|
|
|
|
}
|
|
|
|
|
2020-02-10 20:43:24 +01:00
|
|
|
if (orderParam === CS.ORDER_BY_TOP && freshnessParam !== CS.FRESH_ALL) {
|
2019-07-17 22:49:06 +02:00
|
|
|
options.release_time = `>${Math.floor(
|
|
|
|
moment()
|
2020-02-10 20:43:24 +01:00
|
|
|
.subtract(1, freshnessParam)
|
2020-01-24 03:13:59 +01:00
|
|
|
.startOf('hour')
|
|
|
|
.unix()
|
|
|
|
)}`;
|
2020-02-10 20:43:24 +01:00
|
|
|
} else if (orderParam === CS.ORDER_BY_NEW || orderParam === CS.ORDER_BY_TRENDING) {
|
2020-01-24 17:32:13 +01:00
|
|
|
// Warning - hack below
|
2020-01-24 21:38:33 +01:00
|
|
|
// If users are following more than 10 channels or tags, limit results to stuff less than a year old
|
|
|
|
// For more than 20, drop it down to 6 months
|
2020-01-24 16:16:25 +01:00
|
|
|
// This helps with timeout issues for users that are following a ton of stuff
|
2020-01-24 17:32:13 +01:00
|
|
|
// https://github.com/lbryio/lbry-sdk/issues/2420
|
2020-03-01 23:51:21 +01:00
|
|
|
if (
|
|
|
|
(options.channel_ids && options.channel_ids.length > 20) ||
|
|
|
|
(options.any_tags && options.any_tags.length > 20)
|
|
|
|
) {
|
2020-01-24 21:38:33 +01:00
|
|
|
options.release_time = `>${Math.floor(
|
|
|
|
moment()
|
2020-02-10 20:43:24 +01:00
|
|
|
.subtract(3, CS.FRESH_MONTH)
|
2020-01-24 21:38:33 +01:00
|
|
|
.startOf('week')
|
|
|
|
.unix()
|
|
|
|
)}`;
|
2020-03-01 23:51:21 +01:00
|
|
|
} else if (
|
|
|
|
(options.channel_ids && options.channel_ids.length > 10) ||
|
|
|
|
(options.any_tags && options.any_tags.length > 10)
|
|
|
|
) {
|
2020-01-24 21:38:33 +01:00
|
|
|
options.release_time = `>${Math.floor(
|
|
|
|
moment()
|
2020-02-10 20:43:24 +01:00
|
|
|
.subtract(1, CS.FRESH_YEAR)
|
2020-01-24 21:38:33 +01:00
|
|
|
.startOf('week')
|
|
|
|
.unix()
|
|
|
|
)}`;
|
2020-01-28 18:10:33 +01:00
|
|
|
} else {
|
|
|
|
// Hack for at least the New page until https://github.com/lbryio/lbry-sdk/issues/2591 is fixed
|
|
|
|
options.release_time = `<${Math.floor(
|
|
|
|
moment()
|
|
|
|
.startOf('minute')
|
|
|
|
.unix()
|
|
|
|
)}`;
|
2020-01-24 21:38:33 +01:00
|
|
|
}
|
2019-07-17 22:49:06 +02:00
|
|
|
}
|
2020-01-02 17:30:27 +01:00
|
|
|
|
2020-02-10 20:43:24 +01:00
|
|
|
if (durationParam) {
|
|
|
|
if (durationParam === CS.DURATION_SHORT) {
|
|
|
|
options.duration = '<=1800';
|
|
|
|
} else if (durationParam === CS.DURATION_LONG) {
|
|
|
|
options.duration = '>=1800';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (streamTypeParam) {
|
|
|
|
if (streamTypeParam !== CS.CONTENT_ALL) {
|
|
|
|
options.stream_types = [streamTypeParam];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (claimTypeParam) {
|
|
|
|
if (claimTypeParam !== CS.CONTENT_ALL) {
|
2020-02-28 22:52:42 +01:00
|
|
|
if (Array.isArray(claimTypeParam)) {
|
|
|
|
options.claim_type = claimTypeParam;
|
|
|
|
} else {
|
|
|
|
options.claim_type = [claimTypeParam];
|
|
|
|
}
|
2020-02-10 20:43:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-12 02:43:52 +01:00
|
|
|
if (tagsParam) {
|
|
|
|
if (tagsParam !== CS.TAGS_ALL && tagsParam !== '') {
|
|
|
|
if (tagsParam === CS.TAGS_FOLLOWED) {
|
|
|
|
options.any_tags = followed;
|
|
|
|
} else if (Array.isArray(tagsParam)) {
|
|
|
|
options.any_tags = tagsParam;
|
|
|
|
} else {
|
|
|
|
options.any_tags = tagsParam.split(',');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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 && !options.reposted_claim_id) {
|
|
|
|
// and not claimrepostid
|
|
|
|
if (Array.isArray(options.claim_type)) {
|
|
|
|
if (options.claim_type.length > 1) {
|
|
|
|
options.claim_type = options.claim_type.filter(claimType => claimType !== 'repost');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
options.claim_type = ['stream', 'channel'];
|
|
|
|
}
|
|
|
|
}
|
2020-02-21 17:33:14 +01:00
|
|
|
|
2020-03-12 02:43:52 +01:00
|
|
|
const hasMatureTags = tagsParam && tagsParam.split(',').some(t => MATURE_TAGS.includes(t));
|
2019-07-31 21:07:26 +02:00
|
|
|
const claimSearchCacheQuery = createNormalizedClaimSearchKey(options);
|
2020-03-31 18:07:57 +02:00
|
|
|
const claimSearchResult = claimSearchByQuery[claimSearchCacheQuery];
|
|
|
|
|
2019-07-23 10:05:51 +02:00
|
|
|
const shouldPerformSearch =
|
2020-03-31 18:07:57 +02:00
|
|
|
claimSearchResult === undefined ||
|
2020-01-02 17:30:27 +01:00
|
|
|
didNavigateForward ||
|
2020-03-31 18:07:57 +02:00
|
|
|
(!loading &&
|
|
|
|
claimSearchResult &&
|
|
|
|
claimSearchResult.length < CS.PAGE_SIZE * page &&
|
|
|
|
claimSearchResult.length % CS.PAGE_SIZE === 0);
|
|
|
|
|
2019-07-31 21:07:26 +02:00
|
|
|
// Don't use the query from createNormalizedClaimSearchKey for the effect since that doesn't include page & release_time
|
2019-07-17 22:49:06 +02:00
|
|
|
const optionsStringForEffect = JSON.stringify(options);
|
2019-07-03 06:43:32 +02:00
|
|
|
|
2020-03-31 18:07:57 +02:00
|
|
|
const timedOutMessage = (
|
2019-11-13 19:11:51 +01:00
|
|
|
<div>
|
|
|
|
<p>
|
|
|
|
<I18nMessage
|
|
|
|
tokens={{
|
|
|
|
again: (
|
|
|
|
<Button
|
|
|
|
button="link"
|
2020-02-10 20:43:24 +01:00
|
|
|
label={__('try again in a few seconds.')}
|
2019-11-13 19:11:51 +01:00
|
|
|
onClick={() => setForceRefresh(Date.now())}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
}}
|
|
|
|
>
|
2020-03-31 18:07:57 +02:00
|
|
|
Sorry, your request timed out. Modify your options or %again%
|
2019-11-13 19:11:51 +01:00
|
|
|
</I18nMessage>
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
<I18nMessage
|
|
|
|
tokens={{
|
2019-12-05 19:38:11 +01:00
|
|
|
contact_support: <Button button="link" label={__('contact support')} href="https://lbry.com/faq/support" />,
|
2019-11-13 19:11:51 +01:00
|
|
|
}}
|
|
|
|
>
|
2019-12-05 19:38:11 +01:00
|
|
|
If you continue to have issues, please %contact_support%.
|
2019-11-13 19:11:51 +01:00
|
|
|
</I18nMessage>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
2020-02-10 20:43:24 +01:00
|
|
|
function handleChange(change) {
|
|
|
|
const url = buildUrl(change);
|
2019-09-19 22:25:44 +02:00
|
|
|
setPage(1);
|
2019-07-17 22:49:06 +02:00
|
|
|
history.push(url);
|
|
|
|
}
|
2019-07-01 03:52:38 +02:00
|
|
|
|
2020-03-12 02:43:52 +01:00
|
|
|
function getParamFromTags(t) {
|
|
|
|
if (t === CS.TAGS_ALL || t === CS.TAGS_FOLLOWED) {
|
|
|
|
return t;
|
|
|
|
} else if (Array.isArray(t)) {
|
|
|
|
return t.join(',');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-10 20:43:24 +01:00
|
|
|
function buildUrl(delta) {
|
|
|
|
const newUrlParams = new URLSearchParams();
|
|
|
|
CS.KEYS.forEach(k => {
|
|
|
|
// $FlowFixMe append() can't take null as second arg, but get() can return null
|
|
|
|
if (urlParams.get(k) !== null) newUrlParams.append(k, urlParams.get(k));
|
|
|
|
});
|
|
|
|
|
|
|
|
switch (delta.key) {
|
|
|
|
case CS.ORDER_BY_KEY:
|
|
|
|
newUrlParams.set(CS.ORDER_BY_KEY, delta.value);
|
|
|
|
break;
|
|
|
|
case CS.FRESH_KEY:
|
2020-02-27 23:15:17 +01:00
|
|
|
if (delta.value === defaultFreshness || delta.value === CS.FRESH_DEFAULT) {
|
|
|
|
newUrlParams.delete(CS.FRESH_KEY);
|
|
|
|
} else {
|
|
|
|
newUrlParams.set(CS.FRESH_KEY, delta.value);
|
|
|
|
}
|
2020-02-10 20:43:24 +01:00
|
|
|
break;
|
|
|
|
case CS.CONTENT_KEY:
|
|
|
|
if (delta.value === CS.CLAIM_CHANNEL || delta.value === CS.CLAIM_REPOST) {
|
|
|
|
newUrlParams.delete(CS.DURATION_KEY);
|
|
|
|
newUrlParams.set(CS.CONTENT_KEY, delta.value);
|
|
|
|
} else if (delta.value === CS.CONTENT_ALL) {
|
|
|
|
newUrlParams.delete(CS.CONTENT_KEY);
|
|
|
|
} else {
|
|
|
|
newUrlParams.set(CS.CONTENT_KEY, delta.value);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CS.DURATION_KEY:
|
|
|
|
if (delta.value === CS.DURATION_ALL) {
|
|
|
|
newUrlParams.delete(CS.DURATION_KEY);
|
|
|
|
} else {
|
|
|
|
newUrlParams.set(CS.DURATION_KEY, delta.value);
|
|
|
|
}
|
|
|
|
break;
|
2020-03-12 02:43:52 +01:00
|
|
|
case CS.TAGS_KEY:
|
|
|
|
if (delta.value === CS.TAGS_ALL) {
|
|
|
|
if (defaultTags === CS.TAGS_ALL) {
|
|
|
|
newUrlParams.delete(CS.TAGS_KEY);
|
|
|
|
} else {
|
|
|
|
newUrlParams.set(CS.TAGS_KEY, delta.value);
|
|
|
|
}
|
|
|
|
} else if (delta.value === CS.TAGS_FOLLOWED) {
|
|
|
|
if (defaultTags === CS.TAGS_FOLLOWED) {
|
|
|
|
newUrlParams.delete(CS.TAGS_KEY);
|
|
|
|
} else {
|
|
|
|
newUrlParams.set(CS.TAGS_KEY, delta.value); // redundant but special
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
newUrlParams.set(CS.TAGS_KEY, delta.value);
|
|
|
|
}
|
|
|
|
break;
|
2020-02-10 20:43:24 +01:00
|
|
|
}
|
|
|
|
return `?${newUrlParams.toString()}`;
|
2019-07-09 05:16:06 +02:00
|
|
|
}
|
|
|
|
|
2019-07-17 22:49:06 +02:00
|
|
|
function handleScrollBottom() {
|
2020-04-22 14:07:09 +02:00
|
|
|
if (!loading && infiniteScroll) {
|
2019-09-11 20:29:20 +02:00
|
|
|
setPage(page + 1);
|
2019-07-17 22:49:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (shouldPerformSearch) {
|
|
|
|
const searchOptions = JSON.parse(optionsStringForEffect);
|
|
|
|
doClaimSearch(searchOptions);
|
|
|
|
}
|
2019-11-13 19:11:51 +01:00
|
|
|
}, [doClaimSearch, shouldPerformSearch, optionsStringForEffect, forceRefresh]);
|
2019-07-17 22:49:06 +02:00
|
|
|
|
2020-03-19 17:54:37 +01:00
|
|
|
const defaultHeader = repostedClaimId ? null : (
|
2019-07-21 23:31:22 +02:00
|
|
|
<Fragment>
|
2020-02-10 20:43:24 +01:00
|
|
|
<div className={'claim-search__wrapper'}>
|
|
|
|
<div className={'claim-search__top'}>
|
|
|
|
<div className={'claim-search__top-row'}>
|
|
|
|
{CS.ORDER_BY_TYPES.map(type => (
|
|
|
|
<Button
|
|
|
|
key={type}
|
|
|
|
button="alt"
|
|
|
|
onClick={e =>
|
|
|
|
handleChange({
|
|
|
|
key: CS.ORDER_BY_KEY,
|
|
|
|
value: type,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
className={classnames(`button-toggle button-toggle--${type}`, {
|
|
|
|
'button-toggle--active': orderParam === type,
|
|
|
|
})}
|
|
|
|
disabled={orderBy}
|
|
|
|
icon={toCapitalCase(type)}
|
|
|
|
label={__(toCapitalCase(type))}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
<div>
|
2020-02-28 22:52:42 +01:00
|
|
|
{!hideFilter && (
|
2020-02-10 20:43:24 +01:00
|
|
|
<Button
|
|
|
|
button={'alt'}
|
|
|
|
aria-label={__('More')}
|
|
|
|
className={classnames(`button-toggle button-toggle--top button-toggle--more`, {
|
|
|
|
'button-toggle--custom': isFiltered(),
|
|
|
|
})}
|
2020-04-15 16:12:54 +02:00
|
|
|
icon={ICONS.SLIDERS}
|
2020-02-10 20:43:24 +01:00
|
|
|
onClick={() => setExpanded(!expanded)}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{expanded && (
|
|
|
|
<>
|
|
|
|
<div className={classnames('card--inline', `claim-search__menus`)}>
|
|
|
|
{/* FRESHNESS FIELD */}
|
|
|
|
{orderParam === CS.ORDER_BY_TOP && (
|
|
|
|
<div className={'claim-search__input-container'}>
|
|
|
|
<FormField
|
2020-02-27 23:15:17 +01:00
|
|
|
className={classnames('claim-search__dropdown', {
|
|
|
|
'claim-search__dropdown--selected': freshnessParam !== defaultFreshness,
|
|
|
|
})}
|
2020-02-10 20:43:24 +01:00
|
|
|
type="select"
|
|
|
|
name="trending_time"
|
|
|
|
label={__('How Fresh')}
|
|
|
|
value={freshnessParam}
|
|
|
|
onChange={e =>
|
|
|
|
handleChange({
|
|
|
|
key: CS.FRESH_KEY,
|
|
|
|
value: e.target.value,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{CS.FRESH_TYPES.map(time => (
|
|
|
|
<option key={time} value={time}>
|
|
|
|
{/* i18fixme */}
|
|
|
|
{time === CS.FRESH_DAY && __('Today')}
|
|
|
|
{time !== CS.FRESH_ALL &&
|
2020-03-01 23:51:21 +01:00
|
|
|
time !== CS.FRESH_DEFAULT &&
|
2020-02-10 20:43:24 +01:00
|
|
|
time !== CS.FRESH_DAY &&
|
|
|
|
__('This ' + toCapitalCase(time)) /* yes, concat before i18n, since it is read from const */}
|
|
|
|
{time === CS.FRESH_ALL && __('All time')}
|
2020-03-01 23:51:21 +01:00
|
|
|
{time === CS.FRESH_DEFAULT && __('Default')}
|
2020-02-10 20:43:24 +01:00
|
|
|
</option>
|
|
|
|
))}
|
|
|
|
</FormField>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{/* CONTENT_TYPES FIELD */}
|
2020-03-12 02:43:52 +01:00
|
|
|
{!claimType && (
|
|
|
|
<div
|
|
|
|
className={classnames('claim-search__input-container', {
|
|
|
|
'claim-search__input-container--selected': contentTypeParam,
|
2020-02-10 20:43:24 +01:00
|
|
|
})}
|
|
|
|
>
|
2020-03-12 02:43:52 +01:00
|
|
|
<FormField
|
|
|
|
className={classnames('claim-search__dropdown', {
|
|
|
|
'claim-search__dropdown--selected': contentTypeParam,
|
|
|
|
})}
|
|
|
|
type="select"
|
|
|
|
name="claimType"
|
|
|
|
label={__('Content Type')}
|
|
|
|
value={contentTypeParam || CS.CONTENT_ALL}
|
|
|
|
onChange={e =>
|
|
|
|
handleChange({
|
|
|
|
key: CS.CONTENT_KEY,
|
|
|
|
value: e.target.value,
|
|
|
|
})
|
2020-02-10 20:43:24 +01:00
|
|
|
}
|
2020-03-12 02:43:52 +01:00
|
|
|
>
|
|
|
|
{CS.CONTENT_TYPES.map(type => {
|
|
|
|
if (type !== CS.CLAIM_CHANNEL || (type === CS.CLAIM_CHANNEL && !channelIds)) {
|
|
|
|
return (
|
|
|
|
<option key={type} value={type}>
|
|
|
|
{/* i18fixme */}
|
|
|
|
{type === CS.CLAIM_CHANNEL && __('Channel')}
|
|
|
|
{type === CS.CLAIM_REPOST && __('Repost')}
|
|
|
|
{type === CS.FILE_VIDEO && __('Video')}
|
|
|
|
{type === CS.FILE_AUDIO && __('Audio')}
|
|
|
|
{type === CS.FILE_IMAGE && __('Image')}
|
|
|
|
{type === CS.FILE_MODEL && __('Model')}
|
|
|
|
{type === CS.FILE_BINARY && __('Other')}
|
|
|
|
{type === CS.FILE_DOCUMENT && __('Document')}
|
|
|
|
{type === CS.CONTENT_ALL && __('Any')}
|
|
|
|
</option>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
})}
|
|
|
|
</FormField>
|
|
|
|
</div>
|
|
|
|
)}
|
2020-02-29 18:24:13 +01:00
|
|
|
{/* DURATIONS FIELD */}
|
2020-03-01 23:51:21 +01:00
|
|
|
{showDuration && (
|
|
|
|
<div className={'claim-search__input-container'}>
|
|
|
|
<FormField
|
|
|
|
className={classnames('claim-search__dropdown', {
|
|
|
|
'claim-search__dropdown--selected': durationParam,
|
|
|
|
})}
|
|
|
|
label={__('Duration')}
|
|
|
|
type="select"
|
|
|
|
name="duration"
|
|
|
|
disabled={
|
|
|
|
!(
|
|
|
|
contentTypeParam === null ||
|
|
|
|
streamTypeParam === CS.FILE_AUDIO ||
|
|
|
|
streamTypeParam === CS.FILE_VIDEO
|
|
|
|
)
|
|
|
|
}
|
|
|
|
value={durationParam || CS.DURATION_ALL}
|
|
|
|
onChange={e =>
|
|
|
|
handleChange({
|
|
|
|
key: CS.DURATION_KEY,
|
|
|
|
value: e.target.value,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{CS.DURATION_TYPES.map(dur => (
|
|
|
|
<option key={dur} value={dur}>
|
|
|
|
{/* i18fixme */}
|
|
|
|
{dur === CS.DURATION_SHORT && __('Short')}
|
|
|
|
{dur === CS.DURATION_LONG && __('Long')}
|
|
|
|
{dur === CS.DURATION_ALL && __('Any')}
|
|
|
|
</option>
|
|
|
|
))}
|
|
|
|
</FormField>
|
|
|
|
</div>
|
|
|
|
)}
|
2020-03-12 02:43:52 +01:00
|
|
|
{/* TAGS FIELD */}
|
|
|
|
{!tags && (
|
|
|
|
<div className={'claim-search__input-container'}>
|
|
|
|
<FormField
|
|
|
|
className={classnames('claim-search__dropdown', {
|
|
|
|
'claim-search__dropdown--selected':
|
|
|
|
((!defaultTags || defaultTags === CS.TAGS_ALL) && tagsParam && tagsParam !== CS.TAGS_ALL) ||
|
|
|
|
(defaultTags === CS.TAGS_FOLLOWED && tagsParam !== CS.TAGS_FOLLOWED),
|
|
|
|
})}
|
|
|
|
label={__('Tags')}
|
|
|
|
type="select"
|
|
|
|
name="tags"
|
|
|
|
value={tagsParam || CS.TAGS_ALL}
|
|
|
|
onChange={e =>
|
|
|
|
handleChange({
|
|
|
|
key: CS.TAGS_KEY,
|
|
|
|
value: e.target.value,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{[
|
|
|
|
CS.TAGS_ALL,
|
|
|
|
CS.TAGS_FOLLOWED,
|
|
|
|
...followed,
|
|
|
|
...(followed.includes(tagsParam) || tagsParam === CS.TAGS_ALL || tagsParam === CS.TAGS_FOLLOWED
|
|
|
|
? []
|
|
|
|
: [tagsParam]), // if they unfollow while filtered, add Other
|
|
|
|
].map(tag => (
|
|
|
|
<option
|
|
|
|
key={tag}
|
|
|
|
value={tag}
|
|
|
|
className={classnames({
|
|
|
|
'claim-search__input-special': !followed.includes(tag),
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
{followed.includes(tag) && typeof tag === 'string' && toCapitalCase(__(tag))}
|
|
|
|
{tag === CS.TAGS_ALL && __('Any')}
|
|
|
|
{tag === CS.TAGS_FOLLOWED && __('Following')}
|
|
|
|
{!followed.includes(tag) && tag !== CS.TAGS_ALL && tag !== CS.TAGS_FOLLOWED && __('Other')}
|
|
|
|
</option>
|
|
|
|
))}
|
|
|
|
</FormField>
|
|
|
|
</div>
|
|
|
|
)}
|
2020-02-10 20:43:24 +01:00
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</div>
|
2020-01-02 17:30:27 +01:00
|
|
|
|
2019-10-14 03:19:24 +02:00
|
|
|
{hasMatureTags && hiddenNsfwMessage}
|
2019-07-21 23:31:22 +02:00
|
|
|
</Fragment>
|
2019-06-11 20:10:58 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
2020-01-02 21:36:03 +01:00
|
|
|
<React.Fragment>
|
2019-06-19 07:05:43 +02:00
|
|
|
<ClaimList
|
2019-07-23 10:05:51 +02:00
|
|
|
id={claimSearchCacheQuery}
|
2019-06-17 22:32:38 +02:00
|
|
|
loading={loading}
|
2020-03-31 18:07:57 +02:00
|
|
|
uris={claimSearchResult}
|
2020-02-11 20:04:51 +01:00
|
|
|
header={header || defaultHeader}
|
2020-01-02 21:36:03 +01:00
|
|
|
headerLabel={headerLabel}
|
2019-07-01 03:52:38 +02:00
|
|
|
headerAltControls={meta}
|
2019-07-17 22:49:06 +02:00
|
|
|
onScrollBottom={handleScrollBottom}
|
2019-07-01 06:35:36 +02:00
|
|
|
page={page}
|
2020-02-10 20:43:24 +01:00
|
|
|
pageSize={CS.PAGE_SIZE}
|
2020-03-31 18:07:57 +02:00
|
|
|
timedOutMessage={timedOutMessage}
|
2020-02-11 20:04:51 +01:00
|
|
|
renderProperties={renderProperties}
|
2020-02-12 19:59:48 +01:00
|
|
|
includeSupportAction={includeSupportAction}
|
2020-02-26 20:20:38 +01:00
|
|
|
hideBlock={hideBlock}
|
2020-03-26 22:47:07 +01:00
|
|
|
injectedItem={injectedItem}
|
2019-06-17 22:32:38 +02:00
|
|
|
/>
|
2019-06-27 08:18:45 +02:00
|
|
|
|
2020-03-24 17:31:23 +01:00
|
|
|
{loading && (
|
|
|
|
<div className="card">
|
2020-04-22 21:43:43 +02:00
|
|
|
{new Array(pageSize || CS.PAGE_SIZE).fill(1).map((x, i) => (
|
2020-03-24 17:31:23 +01:00
|
|
|
<ClaimPreview key={i} placeholder="loading" />
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
)}
|
2020-01-02 21:36:03 +01:00
|
|
|
</React.Fragment>
|
2019-06-11 20:10:58 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-07-17 22:49:06 +02:00
|
|
|
export default withRouter(ClaimListDiscover);
|