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',
|
type: 'claim' | 'update' | 'support',
|
||||||
value_type: 'stream' | 'channel',
|
value_type: 'stream' | 'channel',
|
||||||
signing_channel?: ChannelClaim,
|
signing_channel?: ChannelClaim,
|
||||||
|
repost_channel_url?: string,
|
||||||
meta: {
|
meta: {
|
||||||
activation_height: number,
|
activation_height: number,
|
||||||
claims_in_channel?: 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',
|
type: 'claim' | 'update' | 'support',
|
||||||
value_type: 'stream' | 'channel',
|
value_type: 'stream' | 'channel',
|
||||||
signing_channel?: ChannelClaim,
|
signing_channel?: ChannelClaim,
|
||||||
|
repost_channel_url?: string,
|
||||||
meta: {
|
meta: {
|
||||||
activation_height: number,
|
activation_height: number,
|
||||||
claims_in_channel?: number,
|
claims_in_channel?: number,
|
||||||
|
|
|
@ -16,6 +16,8 @@ export const DEFAULT_FOLLOWED_TAGS = [
|
||||||
export const MATURE_TAGS = ['porn', 'nsfw', 'mature', 'xxx'];
|
export const MATURE_TAGS = ['porn', 'nsfw', 'mature', 'xxx'];
|
||||||
|
|
||||||
export const DEFAULT_KNOWN_TAGS = [
|
export const DEFAULT_KNOWN_TAGS = [
|
||||||
|
'free speech',
|
||||||
|
'censorship',
|
||||||
'gaming',
|
'gaming',
|
||||||
'pop culture',
|
'pop culture',
|
||||||
'Entertainment',
|
'Entertainment',
|
||||||
|
|
|
@ -191,7 +191,7 @@ export function doCommentUpdate(comment_id: string, comment: string) {
|
||||||
} else {
|
} else {
|
||||||
// the result will return null
|
// the result will return null
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.COMENT_UPDATE_FAILED,
|
type: ACTIONS.COMMENT_UPDATE_FAILED,
|
||||||
});
|
});
|
||||||
dispatch(
|
dispatch(
|
||||||
doToast({
|
doToast({
|
||||||
|
|
|
@ -17,6 +17,15 @@ const DEBOUNCED_SEARCH_SUGGESTION_MS = 300;
|
||||||
type Dispatch = (action: any) => any;
|
type Dispatch = (action: any) => any;
|
||||||
type GetState = () => { search: SearchState };
|
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
|
// We can't use env's because they aren't passed into node_modules
|
||||||
let CONNECTION_STRING = 'https://lighthouse.lbry.com/';
|
let CONNECTION_STRING = 'https://lighthouse.lbry.com/';
|
||||||
|
|
||||||
|
@ -75,17 +84,13 @@ export const doUpdateSearchQuery = (query: string, shouldSkipSuggestions: ?boole
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const doSearch = (
|
export const doSearch = (rawQuery: string, searchOptions: SearchOptions) => (
|
||||||
rawQuery: string,
|
dispatch: Dispatch,
|
||||||
size: ?number, // only pass in if you don't want to use the users setting (ex: related content)
|
getState: GetState
|
||||||
from: ?number,
|
) => {
|
||||||
isBackgroundSearch: boolean = false,
|
|
||||||
options: {
|
|
||||||
related_to?: string,
|
|
||||||
} = {},
|
|
||||||
resolveResults: boolean = true
|
|
||||||
) => (dispatch: Dispatch, getState: GetState) => {
|
|
||||||
const query = rawQuery.replace(/^lbry:\/\//i, '').replace(/\//, ' ');
|
const query = rawQuery.replace(/^lbry:\/\//i, '').replace(/\//, ' ');
|
||||||
|
const resolveResults = searchOptions && searchOptions.resolveResults;
|
||||||
|
const isBackgroundSearch = (searchOptions && searchOptions.isBackgroundSearch) || false;
|
||||||
|
|
||||||
if (!query) {
|
if (!query) {
|
||||||
dispatch({
|
dispatch({
|
||||||
|
@ -95,9 +100,8 @@ export const doSearch = (
|
||||||
}
|
}
|
||||||
|
|
||||||
const state = getState();
|
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
|
// If we have already searched for something, we don't need to do anything
|
||||||
const urisForQuery = makeSelectSearchUris(queryWithOptions)(state);
|
const urisForQuery = makeSelectSearchUris(queryWithOptions)(state);
|
||||||
|
@ -162,11 +166,12 @@ export const doSearch = (
|
||||||
|
|
||||||
export const doResolvedSearch = (
|
export const doResolvedSearch = (
|
||||||
rawQuery: string,
|
rawQuery: string,
|
||||||
size: ?number, // only pass in if you don't want to use the users setting (ex: related content)
|
size?: number, // only pass in if you don't want to use the users setting (ex: related content)
|
||||||
from: ?number,
|
from?: number,
|
||||||
isBackgroundSearch: boolean = false,
|
isBackgroundSearch?: boolean = false,
|
||||||
options: {
|
options: {
|
||||||
related_to?: string,
|
related_to?: string,
|
||||||
|
// nsfw here
|
||||||
} = {}
|
} = {}
|
||||||
) => (dispatch: Dispatch, getState: GetState) => {
|
) => (dispatch: Dispatch, getState: GetState) => {
|
||||||
const query = rawQuery.replace(/^lbry:\/\//i, '').replace(/\//, ' ');
|
const query = rawQuery.replace(/^lbry:\/\//i, '').replace(/\//, ' ');
|
||||||
|
@ -178,15 +183,25 @@ export const doResolvedSearch = (
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const optionsWithFrom: SearchOptions = {
|
||||||
|
size,
|
||||||
|
from,
|
||||||
|
isBackgroundSearch,
|
||||||
|
...options,
|
||||||
|
};
|
||||||
|
|
||||||
|
const optionsWithoutFrom: SearchOptions = {
|
||||||
|
size,
|
||||||
|
isBackgroundSearch,
|
||||||
|
...options,
|
||||||
|
};
|
||||||
|
|
||||||
const state = getState();
|
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
|
// 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)(
|
let queryWithoutFrom = makeSelectQueryWithOptions(query, optionsWithoutFrom)(state);
|
||||||
state
|
|
||||||
);
|
|
||||||
|
|
||||||
// If we have already searched for something, we don't need to do anything
|
// If we have already searched for something, we don't need to do anything
|
||||||
// TODO: Tweak this check for multiple page results
|
// TODO: Tweak this check for multiple page results
|
||||||
|
@ -241,10 +256,10 @@ export const doBlurSearchInput = () => (dispatch: Dispatch) =>
|
||||||
type: ACTIONS.SEARCH_BLUR,
|
type: ACTIONS.SEARCH_BLUR,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const doUpdateSearchOptions = (newOptions: SearchOptions) => (
|
export const doUpdateSearchOptions = (
|
||||||
dispatch: Dispatch,
|
newOptions: SearchOptions,
|
||||||
getState: GetState
|
additionalOptions: SearchOptions
|
||||||
) => {
|
) => (dispatch: Dispatch, getState: GetState) => {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
const searchValue = selectSearchValue(state);
|
const searchValue = selectSearchValue(state);
|
||||||
|
|
||||||
|
@ -255,6 +270,6 @@ export const doUpdateSearchOptions = (newOptions: SearchOptions) => (
|
||||||
|
|
||||||
if (searchValue) {
|
if (searchValue) {
|
||||||
// After updating, perform a search with the new options
|
// 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;
|
valid = true;
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
if (valid) {
|
if (valid && byUri) {
|
||||||
const claimId = isChannel ? channelClaimId : streamClaimId;
|
const claimId = isChannel ? channelClaimId : streamClaimId;
|
||||||
const pendingClaim = pendingById[claimId];
|
const pendingClaim = pendingById[claimId];
|
||||||
|
|
||||||
|
@ -122,7 +122,23 @@ export const makeSelectClaimForUri = (uri: string) =>
|
||||||
return pendingClaim;
|
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(
|
createSelector(
|
||||||
makeSelectClaimForUri(uri),
|
makeSelectClaimForUri(uri),
|
||||||
selectSearchUrisByQuery,
|
selectSearchUrisByQuery,
|
||||||
(claim, searchUrisByQuery) => {
|
makeSelectClaimIsNsfw(uri),
|
||||||
|
(claim, searchUrisByQuery, isMature) => {
|
||||||
const atVanityURI = !uri.includes('#');
|
const atVanityURI = !uri.includes('#');
|
||||||
|
|
||||||
let recommendedContent;
|
let recommendedContent;
|
||||||
|
@ -513,9 +530,16 @@ export const makeSelectRecommendedContentForUri = (uri: string) =>
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const searchQuery = getSearchQueryString(title.replace(/\//, ' '), undefined, undefined, {
|
const options: {
|
||||||
related_to: claim.claim_id,
|
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];
|
let searchUris = searchUrisByQuery[searchQuery];
|
||||||
if (searchUris) {
|
if (searchUris) {
|
||||||
|
@ -647,7 +671,8 @@ export const makeSelectResolvedRecommendedContentForUri = (uri: string, size: nu
|
||||||
createSelector(
|
createSelector(
|
||||||
makeSelectClaimForUri(uri),
|
makeSelectClaimForUri(uri),
|
||||||
selectResolvedSearchResultsByQuery,
|
selectResolvedSearchResultsByQuery,
|
||||||
(claim, resolvedResultsByQuery) => {
|
makeSelectClaimIsNsfw(uri),
|
||||||
|
(claim, resolvedResultsByQuery, isMature) => {
|
||||||
const atVanityURI = !uri.includes('#');
|
const atVanityURI = !uri.includes('#');
|
||||||
|
|
||||||
let recommendedContent;
|
let recommendedContent;
|
||||||
|
@ -661,9 +686,16 @@ export const makeSelectResolvedRecommendedContentForUri = (uri: string, size: nu
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const searchQuery = getSearchQueryString(title.replace(/\//, ' '), { size }, undefined, {
|
const options: {
|
||||||
related_to: claim.claim_id,
|
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];
|
let results = resolvedResultsByQuery[searchQuery];
|
||||||
if (results) {
|
if (results) {
|
||||||
|
|
|
@ -165,26 +165,27 @@ export const selectSearchSuggestions: Array<SearchSuggestion> = createSelector(
|
||||||
|
|
||||||
// Creates a query string based on the state in the search reducer
|
// 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
|
// 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 = (
|
export const makeSelectQueryWithOptions = (
|
||||||
customQuery: ?string,
|
customQuery: ?string,
|
||||||
customSize: ?number,
|
options: CustomOptions,
|
||||||
customFrom: ?number,
|
|
||||||
isBackgroundSearch: boolean = false, // If it's a background search, don't use the users settings
|
|
||||||
additionalOptions: {
|
|
||||||
related_to?: string,
|
|
||||||
} = {}
|
|
||||||
) =>
|
) =>
|
||||||
createSelector(
|
createSelector(
|
||||||
selectSearchValue,
|
selectSearchValue,
|
||||||
selectSearchOptions,
|
selectSearchOptions,
|
||||||
(query, options) => {
|
(query, defaultOptions) => {
|
||||||
const size = customSize || options[SEARCH_OPTIONS.RESULT_COUNT];
|
const searchOptions = { ...defaultOptions, ...options };
|
||||||
|
|
||||||
const queryString = getSearchQueryString(
|
const queryString = getSearchQueryString(
|
||||||
customQuery || query,
|
customQuery || query,
|
||||||
{ ...options, size, from: customFrom },
|
searchOptions,
|
||||||
!isBackgroundSearch,
|
|
||||||
additionalOptions
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return queryString;
|
return queryString;
|
||||||
|
|
|
@ -36,8 +36,6 @@ export function toQueryString(params: { [string]: string | number }) {
|
||||||
export const getSearchQueryString = (
|
export const getSearchQueryString = (
|
||||||
query: string,
|
query: string,
|
||||||
options: any = {},
|
options: any = {},
|
||||||
includeUserOptions: boolean = false,
|
|
||||||
additionalOptions: {} = {}
|
|
||||||
) => {
|
) => {
|
||||||
const encodedQuery = encodeURIComponent(query);
|
const encodedQuery = encodeURIComponent(query);
|
||||||
const queryParams = [
|
const queryParams = [
|
||||||
|
@ -45,6 +43,8 @@ export const getSearchQueryString = (
|
||||||
`size=${options.size || DEFAULT_SEARCH_SIZE}`,
|
`size=${options.size || DEFAULT_SEARCH_SIZE}`,
|
||||||
`from=${options.from || DEFAULT_SEARCH_RESULT_FROM}`,
|
`from=${options.from || DEFAULT_SEARCH_RESULT_FROM}`,
|
||||||
];
|
];
|
||||||
|
const { isBackgroundSearch } = options;
|
||||||
|
const includeUserOptions = typeof isBackgroundSearch === 'undefined' ? false : !isBackgroundSearch;
|
||||||
|
|
||||||
if (includeUserOptions) {
|
if (includeUserOptions) {
|
||||||
const claimType = options[SEARCH_OPTIONS.CLAIM_TYPE];
|
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) {
|
if (additionalOptions) {
|
||||||
Object.keys(additionalOptions).forEach(key => {
|
Object.keys(additionalOptions).forEach(key => {
|
||||||
const option = additionalOptions[key];
|
const option = additionalOptions[key];
|
||||||
|
|
Loading…
Reference in a new issue