fix merge conflicts

This commit is contained in:
Akinwale Ariwodola 2020-01-05 11:37:01 +01:00
commit b272d0f2ce
7 changed files with 92 additions and 55 deletions

42
dist/bundle.es.js vendored
View file

@ -1042,7 +1042,7 @@ function toQueryString(params) {
return parts.join('&'); return parts.join('&');
} }
const getSearchQueryString = (query, options = {}, includeUserOptions = false) => { const getSearchQueryString = (query, options = {}, includeUserOptions = false, additionalOptions = {}) => {
const encodedQuery = encodeURIComponent(query); const encodedQuery = encodeURIComponent(query);
const queryParams = [`s=${encodedQuery}`, `size=${options.size || DEFAULT_SEARCH_SIZE}`, `from=${options.from || DEFAULT_SEARCH_RESULT_FROM}`]; const queryParams = [`s=${encodedQuery}`, `size=${options.size || DEFAULT_SEARCH_SIZE}`, `from=${options.from || DEFAULT_SEARCH_RESULT_FROM}`];
@ -1056,6 +1056,13 @@ const getSearchQueryString = (query, options = {}, includeUserOptions = false) =
} }
} }
if (additionalOptions) {
Object.keys(additionalOptions).forEach(key => {
const option = additionalOptions[key];
queryParams.push(`${key}=${option}`);
});
}
return queryParams.join('&'); return queryParams.join('&');
}; };
@ -1124,7 +1131,7 @@ function parseURI(URL, requireProto = false) {
rest.forEach(urlPiece => { rest.forEach(urlPiece => {
if (urlPiece && urlPiece.includes(' ')) { if (urlPiece && urlPiece.includes(' ')) {
throw new Error('URL can not include a space'); console.error('URL can not include a space');
} }
}); });
@ -1170,7 +1177,7 @@ function parseURIModifier(modSeperator, modValue) {
if (modSeperator) { if (modSeperator) {
if (!modValue) { if (!modValue) {
console.error(__(`No modifier provided after separator %modSeperator%.`, { modSeperator })); throw new Error(__(`No modifier provided after separator %modSeperator%.`, { modSeperator }));
} }
if (modSeperator === '#') { if (modSeperator === '#') {
@ -1183,15 +1190,15 @@ function parseURIModifier(modSeperator, modValue) {
} }
if (claimId && (claimId.length > claimIdMaxLength || !claimId.match(/^[0-9a-f]+$/))) { if (claimId && (claimId.length > claimIdMaxLength || !claimId.match(/^[0-9a-f]+$/))) {
console.error(__(`Invalid claim ID %claimId%.`, { claimId })); throw new Error(__(`Invalid claim ID %claimId%.`, { claimId }));
} }
if (claimSequence && !claimSequence.match(/^-?[1-9][0-9]*$/)) { if (claimSequence && !claimSequence.match(/^-?[1-9][0-9]*$/)) {
console.error(__('Claim sequence must be a number.')); throw new Error(__('Claim sequence must be a number.'));
} }
if (bidPosition && !bidPosition.match(/^-?[1-9][0-9]*$/)) { if (bidPosition && !bidPosition.match(/^-?[1-9][0-9]*$/)) {
console.error(__('Bid position must be a number.')); throw new Error(__('Bid position must be a number.'));
} }
return [claimId, claimSequence, bidPosition]; return [claimId, claimSequence, bidPosition];
@ -1395,11 +1402,11 @@ const selectSearchSuggestions = reselect.createSelector(selectSearchValue, selec
// 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
const makeSelectQueryWithOptions = (customQuery, customSize, customFrom, isBackgroundSearch = false // If it's a background search, don't use the users settings const makeSelectQueryWithOptions = (customQuery, customSize, customFrom, isBackgroundSearch = false, // If it's a background search, don't use the users settings
) => reselect.createSelector(selectSearchValue, selectSearchOptions, (query, options) => { additionalOptions = {}) => reselect.createSelector(selectSearchValue, selectSearchOptions, (query, options) => {
const size = customSize || options[SEARCH_OPTIONS.RESULT_COUNT]; const size = customSize || options[SEARCH_OPTIONS.RESULT_COUNT];
const queryString = getSearchQueryString(customQuery || query, _extends$1({}, options, { size, from: customFrom }), !isBackgroundSearch); const queryString = getSearchQueryString(customQuery || query, _extends$1({}, options, { size, from: customFrom }), !isBackgroundSearch, additionalOptions);
return queryString; return queryString;
}); });
@ -2179,7 +2186,13 @@ const makeSelectRecommendedContentForUri = uri => reselect.createSelector(makeSe
const { title } = claim.value; const { title } = claim.value;
const searchQuery = getSearchQueryString(title ? title.replace(/\//, ' ') : ''); if (!title) {
return;
}
const searchQuery = getSearchQueryString(title.replace(/\//, ' '), undefined, undefined, {
related_to: claim.claim_id
});
let searchUris = searchUrisByQuery[searchQuery]; let searchUris = searchUrisByQuery[searchQuery];
if (searchUris) { if (searchUris) {
@ -2339,6 +2352,8 @@ function doUpdateBalance() {
} }
}); });
} }
}).catch(() => {
walletBalancePromise = null;
}); });
} }
@ -3908,9 +3923,8 @@ const doUpdateSearchQuery = (query, shouldSkipSuggestions) => dispatch => {
} }
}; };
const doSearch = (rawQuery, // pass in a query if you don't want to search for what's in the search bar const doSearch = (rawQuery, size, // only pass in if you don't want to use the users setting (ex: related content)
size, // only pass in if you don't want to use the users setting (ex: related content) from, isBackgroundSearch = false, options = {}, resolveResults = true) => (dispatch, getState) => {
from, isBackgroundSearch = false, resolveResults = true) => (dispatch, getState) => {
const query = rawQuery.replace(/^lbry:\/\//i, '').replace(/\//, ' '); const query = rawQuery.replace(/^lbry:\/\//i, '').replace(/\//, ' ');
if (!query) { if (!query) {
@ -3921,7 +3935,7 @@ from, isBackgroundSearch = false, resolveResults = true) => (dispatch, getState)
} }
const state = getState(); const state = getState();
const queryWithOptions = makeSelectQueryWithOptions(query, size, from, isBackgroundSearch)(state); let queryWithOptions = makeSelectQueryWithOptions(query, size, from, isBackgroundSearch, options)(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);

View file

@ -73,7 +73,7 @@ export function parseURI(URL: string, requireProto: boolean = false): LbryUrlObj
rest.forEach(urlPiece => { rest.forEach(urlPiece => {
if (urlPiece && urlPiece.includes(' ')) { if (urlPiece && urlPiece.includes(' ')) {
throw new Error('URL can not include a space'); console.error('URL can not include a space');
} }
}); });
@ -138,7 +138,7 @@ function parseURIModifier(modSeperator: ?string, modValue: ?string) {
if (modSeperator) { if (modSeperator) {
if (!modValue) { if (!modValue) {
console.error(__(`No modifier provided after separator %modSeperator%.`, { modSeperator })); throw new Error(__(`No modifier provided after separator %modSeperator%.`, { modSeperator }));
} }
if (modSeperator === '#') { if (modSeperator === '#') {
@ -151,15 +151,15 @@ function parseURIModifier(modSeperator: ?string, modValue: ?string) {
} }
if (claimId && (claimId.length > claimIdMaxLength || !claimId.match(/^[0-9a-f]+$/))) { if (claimId && (claimId.length > claimIdMaxLength || !claimId.match(/^[0-9a-f]+$/))) {
console.error(__(`Invalid claim ID %claimId%.`, { claimId })); throw new Error(__(`Invalid claim ID %claimId%.`, { claimId }));
} }
if (claimSequence && !claimSequence.match(/^-?[1-9][0-9]*$/)) { if (claimSequence && !claimSequence.match(/^-?[1-9][0-9]*$/)) {
console.error(__('Claim sequence must be a number.')); throw new Error(__('Claim sequence must be a number.'));
} }
if (bidPosition && !bidPosition.match(/^-?[1-9][0-9]*$/)) { if (bidPosition && !bidPosition.match(/^-?[1-9][0-9]*$/)) {
console.error(__('Bid position must be a number.')); throw new Error(__('Bid position must be a number.'));
} }
return [claimId, claimSequence, bidPosition]; return [claimId, claimSequence, bidPosition];

View file

@ -75,11 +75,14 @@ export const doUpdateSearchQuery = (query: string, shouldSkipSuggestions: ?boole
}; };
export const doSearch = ( export const doSearch = (
rawQuery: string, // pass in a query if you don't want to search for what's in the search bar 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,
resolveResults: boolean = true, options: {
related_to?: string,
} = {},
resolveResults: boolean = true
) => (dispatch: Dispatch, getState: GetState) => { ) => (dispatch: Dispatch, getState: GetState) => {
const query = rawQuery.replace(/^lbry:\/\//i, '').replace(/\//, ' '); const query = rawQuery.replace(/^lbry:\/\//i, '').replace(/\//, ' ');
@ -91,7 +94,9 @@ export const doSearch = (
} }
const state = getState(); const state = getState();
const queryWithOptions = makeSelectQueryWithOptions(query, size, from, isBackgroundSearch)(state); let queryWithOptions = makeSelectQueryWithOptions(query, size, from, isBackgroundSearch, options)(
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);

View file

@ -13,27 +13,31 @@ export function doUpdateBalance() {
} = getState(); } = getState();
if (walletBalancePromise === null) { if (walletBalancePromise === null) {
walletBalancePromise = Lbry.wallet_balance().then(response => { walletBalancePromise = Lbry.wallet_balance()
walletBalancePromise = null; .then(response => {
walletBalancePromise = null;
const { available, reserved, reserved_subtotals, total } = response; const { available, reserved, reserved_subtotals, total } = response;
const { claims, supports, tips } = reserved_subtotals; const { claims, supports, tips } = reserved_subtotals;
const totalFloat = parseFloat(total); const totalFloat = parseFloat(total);
if (totalInStore !== totalFloat) { if (totalInStore !== totalFloat) {
dispatch({ dispatch({
type: ACTIONS.UPDATE_BALANCE, type: ACTIONS.UPDATE_BALANCE,
data: { data: {
totalBalance: totalFloat, totalBalance: totalFloat,
balance: parseFloat(available), balance: parseFloat(available),
reservedBalance: parseFloat(reserved), reservedBalance: parseFloat(reserved),
claimsBalance: parseFloat(claims), claimsBalance: parseFloat(claims),
supportsBalance: parseFloat(supports), supportsBalance: parseFloat(supports),
tipsBalance: parseFloat(tips), tipsBalance: parseFloat(tips),
}, },
}); });
} }
}); })
.catch(() => {
walletBalancePromise = null;
});
} }
return walletBalancePromise; return walletBalancePromise;

View file

@ -212,7 +212,6 @@ export const makeSelectTotalPagesInChannelSearch = (uri: string) =>
} }
); );
export const makeSelectClaimsInChannelForCurrentPageState = (uri: string) => export const makeSelectClaimsInChannelForCurrentPageState = (uri: string) =>
createSelector( createSelector(
selectClaimsById, selectClaimsById,
@ -261,8 +260,8 @@ export const makeSelectDateForUri = (uri: string) =>
(claim.value.release_time (claim.value.release_time
? claim.value.release_time * 1000 ? claim.value.release_time * 1000
: claim.meta && claim.meta.creation_timestamp : claim.meta && claim.meta.creation_timestamp
? claim.meta.creation_timestamp * 1000 ? claim.meta.creation_timestamp * 1000
: null); : null);
if (!timestamp) { if (!timestamp) {
return undefined; return undefined;
} }
@ -473,8 +472,7 @@ export const makeSelectOmittedCountForChannel = (uri: string) =>
(claimsInChannel, claimsInSearch) => { (claimsInChannel, claimsInSearch) => {
if (claimsInChannel && typeof claimsInSearch === 'number' && claimsInSearch >= 0) { if (claimsInChannel && typeof claimsInSearch === 'number' && claimsInSearch >= 0) {
return claimsInChannel - claimsInSearch; return claimsInChannel - claimsInSearch;
} } else return 0;
else return 0;
} }
); );
@ -508,7 +506,13 @@ export const makeSelectRecommendedContentForUri = (uri: string) =>
const { title } = claim.value; const { title } = claim.value;
const searchQuery = getSearchQueryString(title ? title.replace(/\//, ' ') : ''); if (!title) {
return;
}
const searchQuery = getSearchQueryString(title.replace(/\//, ' '), undefined, undefined, {
related_to: claim.claim_id,
});
let searchUris = searchUrisByQuery[searchQuery]; let searchUris = searchUrisByQuery[searchQuery];
if (searchUris) { if (searchUris) {
@ -625,11 +629,9 @@ export const makeSelectMyStreamUrlsForPage = (page: number = 1) =>
createSelector( createSelector(
selectMyClaimUrisWithoutChannels, selectMyClaimUrisWithoutChannels,
urls => { urls => {
const start = ((Number(page) - 1) * Number(PAGE_SIZE)); const start = (Number(page) - 1) * Number(PAGE_SIZE);
const end = (Number(page) * Number(PAGE_SIZE)); const end = Number(page) * Number(PAGE_SIZE);
return (urls && urls.length) return urls && urls.length ? urls.slice(start, end) : [];
? urls.slice(start, end)
: [];
} }
); );

View file

@ -137,7 +137,10 @@ export const makeSelectQueryWithOptions = (
customQuery: ?string, customQuery: ?string,
customSize: ?number, customSize: ?number,
customFrom: ?number, customFrom: ?number,
isBackgroundSearch: boolean = false // If it's a background search, don't use the users settings isBackgroundSearch: boolean = false, // If it's a background search, don't use the users settings
additionalOptions: {
related_to?: string,
} = {}
) => ) =>
createSelector( createSelector(
selectSearchValue, selectSearchValue,
@ -148,7 +151,8 @@ export const makeSelectQueryWithOptions = (
const queryString = getSearchQueryString( const queryString = getSearchQueryString(
customQuery || query, customQuery || query,
{ ...options, size, from: customFrom }, { ...options, size, from: customFrom },
!isBackgroundSearch !isBackgroundSearch,
additionalOptions
); );
return queryString; return queryString;

View file

@ -36,7 +36,8 @@ export function toQueryString(params: { [string]: string | number }) {
export const getSearchQueryString = ( export const getSearchQueryString = (
query: string, query: string,
options: any = {}, options: any = {},
includeUserOptions: boolean = false includeUserOptions: boolean = false,
additionalOptions: {} = {}
) => { ) => {
const encodedQuery = encodeURIComponent(query); const encodedQuery = encodeURIComponent(query);
const queryParams = [ const queryParams = [
@ -67,5 +68,12 @@ export const getSearchQueryString = (
} }
} }
if (additionalOptions) {
Object.keys(additionalOptions).forEach(key => {
const option = additionalOptions[key];
queryParams.push(`${key}=${option}`);
});
}
return queryParams.join('&'); return queryParams.join('&');
}; };