Merge branch 'master' of https://github.com/lbryio/lbry-redux
This commit is contained in:
commit
4d772d875c
9 changed files with 299 additions and 210 deletions
347
dist/bundle.es.js
vendored
347
dist/bundle.es.js
vendored
File diff suppressed because one or more lines are too long
1
dist/flow-typed/Claim.js
vendored
1
dist/flow-typed/Claim.js
vendored
|
@ -33,6 +33,7 @@ declare type GenericClaim = {
|
|||
type: 'claim' | 'update' | 'support',
|
||||
value_type: 'stream' | 'channel',
|
||||
signing_channel?: ChannelClaim,
|
||||
repost_channel_url?: string,
|
||||
meta: {
|
||||
activation_height: number,
|
||||
claims_in_channel?: number,
|
||||
|
|
1
flow-typed/Claim.js
vendored
1
flow-typed/Claim.js
vendored
|
@ -33,6 +33,7 @@ declare type GenericClaim = {
|
|||
type: 'claim' | 'update' | 'support',
|
||||
value_type: 'stream' | 'channel',
|
||||
signing_channel?: ChannelClaim,
|
||||
repost_channel_url?: string,
|
||||
meta: {
|
||||
activation_height: number,
|
||||
claims_in_channel?: number,
|
||||
|
|
|
@ -16,6 +16,8 @@ export const DEFAULT_FOLLOWED_TAGS = [
|
|||
export const MATURE_TAGS = ['porn', 'nsfw', 'mature', 'xxx'];
|
||||
|
||||
export const DEFAULT_KNOWN_TAGS = [
|
||||
'free speech',
|
||||
'censorship',
|
||||
'gaming',
|
||||
'pop culture',
|
||||
'Entertainment',
|
||||
|
|
|
@ -191,7 +191,7 @@ export function doCommentUpdate(comment_id: string, comment: string) {
|
|||
} else {
|
||||
// the result will return null
|
||||
dispatch({
|
||||
type: ACTIONS.COMENT_UPDATE_FAILED,
|
||||
type: ACTIONS.COMMENT_UPDATE_FAILED,
|
||||
});
|
||||
dispatch(
|
||||
doToast({
|
||||
|
|
|
@ -17,6 +17,15 @@ const DEBOUNCED_SEARCH_SUGGESTION_MS = 300;
|
|||
type Dispatch = (action: any) => any;
|
||||
type GetState = () => { search: SearchState };
|
||||
|
||||
type SearchOptions = {
|
||||
size?: number,
|
||||
from?: number,
|
||||
related_to?: string,
|
||||
nsfw?: boolean,
|
||||
isBackgroundSearch?: boolean,
|
||||
resolveResults?: boolean,
|
||||
};
|
||||
|
||||
// We can't use env's because they aren't passed into node_modules
|
||||
let CONNECTION_STRING = 'https://lighthouse.lbry.com/';
|
||||
|
||||
|
@ -75,17 +84,13 @@ export const doUpdateSearchQuery = (query: string, shouldSkipSuggestions: ?boole
|
|||
}
|
||||
};
|
||||
|
||||
export const doSearch = (
|
||||
rawQuery: string,
|
||||
size: ?number, // only pass in if you don't want to use the users setting (ex: related content)
|
||||
from: ?number,
|
||||
isBackgroundSearch: boolean = false,
|
||||
options: {
|
||||
related_to?: string,
|
||||
} = {},
|
||||
resolveResults: boolean = true
|
||||
) => (dispatch: Dispatch, getState: GetState) => {
|
||||
export const doSearch = (rawQuery: string, searchOptions: SearchOptions) => (
|
||||
dispatch: Dispatch,
|
||||
getState: GetState
|
||||
) => {
|
||||
const query = rawQuery.replace(/^lbry:\/\//i, '').replace(/\//, ' ');
|
||||
const resolveResults = searchOptions && searchOptions.resolveResults;
|
||||
const isBackgroundSearch = (searchOptions && searchOptions.isBackgroundSearch) || false;
|
||||
|
||||
if (!query) {
|
||||
dispatch({
|
||||
|
@ -95,9 +100,8 @@ export const doSearch = (
|
|||
}
|
||||
|
||||
const state = getState();
|
||||
let queryWithOptions = makeSelectQueryWithOptions(query, size, from, isBackgroundSearch, options)(
|
||||
state
|
||||
);
|
||||
|
||||
let queryWithOptions = makeSelectQueryWithOptions(query, searchOptions)(state);
|
||||
|
||||
// If we have already searched for something, we don't need to do anything
|
||||
const urisForQuery = makeSelectSearchUris(queryWithOptions)(state);
|
||||
|
@ -162,11 +166,12 @@ export const doSearch = (
|
|||
|
||||
export const doResolvedSearch = (
|
||||
rawQuery: string,
|
||||
size: ?number, // only pass in if you don't want to use the users setting (ex: related content)
|
||||
from: ?number,
|
||||
isBackgroundSearch: boolean = false,
|
||||
size?: number, // only pass in if you don't want to use the users setting (ex: related content)
|
||||
from?: number,
|
||||
isBackgroundSearch?: boolean = false,
|
||||
options: {
|
||||
related_to?: string,
|
||||
// nsfw here
|
||||
} = {}
|
||||
) => (dispatch: Dispatch, getState: GetState) => {
|
||||
const query = rawQuery.replace(/^lbry:\/\//i, '').replace(/\//, ' ');
|
||||
|
@ -178,15 +183,25 @@ export const doResolvedSearch = (
|
|||
return;
|
||||
}
|
||||
|
||||
const optionsWithFrom: SearchOptions = {
|
||||
size,
|
||||
from,
|
||||
isBackgroundSearch,
|
||||
...options,
|
||||
};
|
||||
|
||||
const optionsWithoutFrom: SearchOptions = {
|
||||
size,
|
||||
isBackgroundSearch,
|
||||
...options,
|
||||
};
|
||||
|
||||
const state = getState();
|
||||
let queryWithOptions = makeSelectQueryWithOptions(query, size, from, isBackgroundSearch, options)(
|
||||
state
|
||||
);
|
||||
|
||||
let queryWithOptions = makeSelectQueryWithOptions(query, optionsWithFrom)(state);
|
||||
|
||||
// make from null so that we can maintain a reference to the same query for multiple pages and simply append the found results
|
||||
let queryWithoutFrom = makeSelectQueryWithOptions(query, size, null, isBackgroundSearch, options)(
|
||||
state
|
||||
);
|
||||
let queryWithoutFrom = makeSelectQueryWithOptions(query, optionsWithoutFrom)(state);
|
||||
|
||||
// If we have already searched for something, we don't need to do anything
|
||||
// TODO: Tweak this check for multiple page results
|
||||
|
@ -241,10 +256,10 @@ export const doBlurSearchInput = () => (dispatch: Dispatch) =>
|
|||
type: ACTIONS.SEARCH_BLUR,
|
||||
});
|
||||
|
||||
export const doUpdateSearchOptions = (newOptions: SearchOptions) => (
|
||||
dispatch: Dispatch,
|
||||
getState: GetState
|
||||
) => {
|
||||
export const doUpdateSearchOptions = (
|
||||
newOptions: SearchOptions,
|
||||
additionalOptions: SearchOptions
|
||||
) => (dispatch: Dispatch, getState: GetState) => {
|
||||
const state = getState();
|
||||
const searchValue = selectSearchValue(state);
|
||||
|
||||
|
@ -255,6 +270,6 @@ export const doUpdateSearchOptions = (newOptions: SearchOptions) => (
|
|||
|
||||
if (searchValue) {
|
||||
// After updating, perform a search with the new options
|
||||
dispatch(doSearch(searchValue));
|
||||
dispatch(doSearch(searchValue, additionalOptions));
|
||||
}
|
||||
};
|
||||
|
|
|
@ -114,7 +114,7 @@ export const makeSelectClaimForUri = (uri: string) =>
|
|||
valid = true;
|
||||
} catch (e) {}
|
||||
|
||||
if (valid) {
|
||||
if (valid && byUri) {
|
||||
const claimId = isChannel ? channelClaimId : streamClaimId;
|
||||
const pendingClaim = pendingById[claimId];
|
||||
|
||||
|
@ -122,7 +122,23 @@ export const makeSelectClaimForUri = (uri: string) =>
|
|||
return pendingClaim;
|
||||
}
|
||||
|
||||
return byUri && byUri[normalizeURI(uri)];
|
||||
const claim = byUri[normalizeURI(uri)];
|
||||
if (claim === undefined || claim === null) {
|
||||
// Make sure to return the claim as is so apps can check if it's been resolved before (null) or still needs to be resolved (undefined)
|
||||
return claim;
|
||||
}
|
||||
|
||||
const repostedClaim = claim.reposted_claim;
|
||||
if (repostedClaim) {
|
||||
const channelUrl = claim.signing_channel && claim.signing_channel.canonical_url;
|
||||
|
||||
return {
|
||||
...repostedClaim,
|
||||
repost_channel_url: channelUrl,
|
||||
};
|
||||
} else {
|
||||
return claim;
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
@ -499,7 +515,8 @@ export const makeSelectRecommendedContentForUri = (uri: string) =>
|
|||
createSelector(
|
||||
makeSelectClaimForUri(uri),
|
||||
selectSearchUrisByQuery,
|
||||
(claim, searchUrisByQuery) => {
|
||||
makeSelectClaimIsNsfw(uri),
|
||||
(claim, searchUrisByQuery, isMature) => {
|
||||
const atVanityURI = !uri.includes('#');
|
||||
|
||||
let recommendedContent;
|
||||
|
@ -513,9 +530,16 @@ export const makeSelectRecommendedContentForUri = (uri: string) =>
|
|||
return;
|
||||
}
|
||||
|
||||
const searchQuery = getSearchQueryString(title.replace(/\//, ' '), undefined, undefined, {
|
||||
related_to: claim.claim_id,
|
||||
});
|
||||
const options: {
|
||||
related_to?: string,
|
||||
nsfw?: boolean,
|
||||
isBackgroundSearch?: boolean,
|
||||
} = { related_to: claim.claim_id, isBackgroundSearch: true };
|
||||
|
||||
if (!isMature) {
|
||||
options['nsfw'] = false;
|
||||
}
|
||||
const searchQuery = getSearchQueryString(title.replace(/\//, ' '), options);
|
||||
|
||||
let searchUris = searchUrisByQuery[searchQuery];
|
||||
if (searchUris) {
|
||||
|
@ -647,7 +671,8 @@ export const makeSelectResolvedRecommendedContentForUri = (uri: string, size: nu
|
|||
createSelector(
|
||||
makeSelectClaimForUri(uri),
|
||||
selectResolvedSearchResultsByQuery,
|
||||
(claim, resolvedResultsByQuery) => {
|
||||
makeSelectClaimIsNsfw(uri),
|
||||
(claim, resolvedResultsByQuery, isMature) => {
|
||||
const atVanityURI = !uri.includes('#');
|
||||
|
||||
let recommendedContent;
|
||||
|
@ -661,9 +686,16 @@ export const makeSelectResolvedRecommendedContentForUri = (uri: string, size: nu
|
|||
return;
|
||||
}
|
||||
|
||||
const searchQuery = getSearchQueryString(title.replace(/\//, ' '), { size }, undefined, {
|
||||
related_to: claim.claim_id,
|
||||
});
|
||||
const options: {
|
||||
related_to?: string,
|
||||
nsfw?: boolean,
|
||||
isBackgroundSearch?: boolean,
|
||||
} = { related_to: claim.claim_id, isBackgroundSearch: true };
|
||||
if (!isMature) {
|
||||
options['nsfw'] = false;
|
||||
}
|
||||
|
||||
const searchQuery = getSearchQueryString(title.replace(/\//, ' '), options);
|
||||
|
||||
let results = resolvedResultsByQuery[searchQuery];
|
||||
if (results) {
|
||||
|
|
|
@ -165,26 +165,27 @@ export const selectSearchSuggestions: Array<SearchSuggestion> = createSelector(
|
|||
|
||||
// Creates a query string based on the state in the search reducer
|
||||
// Can be overrided by passing in custom sizes/from values for other areas pagination
|
||||
|
||||
type CustomOptions = {
|
||||
isBackgroundSearch?: boolean,
|
||||
size?: number,
|
||||
from?: number,
|
||||
related_to?: string,
|
||||
nsfw?: boolean,
|
||||
}
|
||||
|
||||
export const makeSelectQueryWithOptions = (
|
||||
customQuery: ?string,
|
||||
customSize: ?number,
|
||||
customFrom: ?number,
|
||||
isBackgroundSearch: boolean = false, // If it's a background search, don't use the users settings
|
||||
additionalOptions: {
|
||||
related_to?: string,
|
||||
} = {}
|
||||
options: CustomOptions,
|
||||
) =>
|
||||
createSelector(
|
||||
selectSearchValue,
|
||||
selectSearchOptions,
|
||||
(query, options) => {
|
||||
const size = customSize || options[SEARCH_OPTIONS.RESULT_COUNT];
|
||||
|
||||
(query, defaultOptions) => {
|
||||
const searchOptions = { ...defaultOptions, ...options };
|
||||
const queryString = getSearchQueryString(
|
||||
customQuery || query,
|
||||
{ ...options, size, from: customFrom },
|
||||
!isBackgroundSearch,
|
||||
additionalOptions
|
||||
searchOptions,
|
||||
);
|
||||
|
||||
return queryString;
|
||||
|
|
|
@ -36,8 +36,6 @@ export function toQueryString(params: { [string]: string | number }) {
|
|||
export const getSearchQueryString = (
|
||||
query: string,
|
||||
options: any = {},
|
||||
includeUserOptions: boolean = false,
|
||||
additionalOptions: {} = {}
|
||||
) => {
|
||||
const encodedQuery = encodeURIComponent(query);
|
||||
const queryParams = [
|
||||
|
@ -45,6 +43,8 @@ export const getSearchQueryString = (
|
|||
`size=${options.size || DEFAULT_SEARCH_SIZE}`,
|
||||
`from=${options.from || DEFAULT_SEARCH_RESULT_FROM}`,
|
||||
];
|
||||
const { isBackgroundSearch } = options;
|
||||
const includeUserOptions = typeof isBackgroundSearch === 'undefined' ? false : !isBackgroundSearch;
|
||||
|
||||
if (includeUserOptions) {
|
||||
const claimType = options[SEARCH_OPTIONS.CLAIM_TYPE];
|
||||
|
@ -68,6 +68,12 @@ export const getSearchQueryString = (
|
|||
}
|
||||
}
|
||||
|
||||
const additionalOptions = {}
|
||||
const { related_to } = options;
|
||||
const { nsfw } = options;
|
||||
if (related_to) additionalOptions['related_to'] = related_to;
|
||||
if (typeof nsfw !== 'undefined') additionalOptions['nsfw'] = nsfw;
|
||||
|
||||
if (additionalOptions) {
|
||||
Object.keys(additionalOptions).forEach(key => {
|
||||
const option = additionalOptions[key];
|
||||
|
|
Loading…
Reference in a new issue