Merge pull request #164 from lbryio/search-tag

add 'tag' as search suggestion
This commit is contained in:
Thomas Zarebczan 2019-07-16 23:12:08 -04:00 committed by GitHub
commit 2e2383afb8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 90 additions and 30 deletions

62
dist/bundle.es.js vendored
View file

@ -629,7 +629,8 @@ var transaction_types = /*#__PURE__*/Object.freeze({
const SEARCH_TYPES = {
FILE: 'file',
CHANNEL: 'channel',
SEARCH: 'search'
SEARCH: 'search',
TAG: 'tag'
};
const SEARCH_OPTIONS = {
@ -893,7 +894,7 @@ const channelNameMinLength = 1;
const claimIdMaxLength = 40;
// see https://spec.lbry.com/#urls
const regexInvalidURI = exports.regexInvalidURI = /[=&#:$@%?\u{0000}-\u{0008}\u{000b}-\u{000c}\u{000e}-\u{001F}\u{D800}-\u{DFFF}\u{FFFE}-\u{FFFF}]/gu;
const regexInvalidURI = /[ =&#:$@%?\u{0000}-\u{0008}\u{000b}-\u{000c}\u{000e}-\u{001F}\u{D800}-\u{DFFF}\u{FFFE}-\u{FFFF}]/gu;
const regexAddress = /^(b|r)(?=[^0OIl]{32,33})[0-9A-Za-z]{32,33}$/;
/**
@ -1138,6 +1139,11 @@ const selectSearchSuggestions = reselect.createSelector(selectSearchValue, selec
});
}
searchSuggestions.push({
value: query,
type: SEARCH_TYPES.TAG
});
const apiSuggestions = suggestions[query] || [];
if (apiSuggestions.length) {
searchSuggestions = searchSuggestions.concat(apiSuggestions.filter(suggestion => suggestion !== query).map(suggestion => {
@ -1271,8 +1277,14 @@ const selectPendingById = reselect.createSelector(selectState$1, state => state.
const selectPendingClaims = reselect.createSelector(selectState$1, state => Object.values(state.pendingById || []));
const makeSelectClaimIsPending = uri => reselect.createSelector(selectPendingById, pendingById => {
const { claimId } = parseURI(uri);
return Boolean(pendingById[claimId]);
let claimId;
try {
({ claimId } = parseURI(uri));
} catch (e) {}
if (claimId) {
return Boolean(pendingById[claimId]);
}
});
const makeSelectPendingByUri = uri => reselect.createSelector(selectPendingById, pendingById => {
@ -1283,13 +1295,21 @@ const makeSelectPendingByUri = uri => reselect.createSelector(selectPendingById,
const makeSelectClaimForUri = uri => reselect.createSelector(selectClaimsByUri, selectPendingById, (byUri, pendingById) => {
// Check if a claim is pending first
// It won't be in claimsByUri because resolving it will return nothing
const { claimId } = parseURI(uri);
const pendingClaim = pendingById[claimId];
if (pendingClaim) {
return pendingClaim;
}
return byUri && byUri[normalizeURI(uri)];
let claimId;
try {
({ claimId } = parseURI(uri));
} catch (e) {}
if (claimId) {
const pendingClaim = pendingById[claimId];
if (pendingClaim) {
return pendingClaim;
}
return byUri && byUri[normalizeURI(uri)];
}
});
const selectMyClaimsRaw = reselect.createSelector(selectState$1, state => state.myClaims);
@ -1299,8 +1319,20 @@ const selectAbandoningIds = reselect.createSelector(selectState$1, state => Obje
const selectMyActiveClaims = reselect.createSelector(selectMyClaimsRaw, selectAbandoningIds, (claims, abandoningIds) => new Set(claims && claims.map(claim => claim.claim_id).filter(claimId => Object.keys(abandoningIds).indexOf(claimId) === -1)));
const makeSelectClaimIsMine = rawUri => {
const uri = normalizeURI(rawUri);
return reselect.createSelector(selectClaimsByUri, selectMyActiveClaims, (claims, myClaims) => claims && claims[uri] && claims[uri].claim_id && myClaims.has(claims[uri].claim_id));
let uri;
try {
uri = normalizeURI(rawUri);
} catch (e) {}
return reselect.createSelector(selectClaimsByUri, selectMyActiveClaims, (claims, myClaims) => {
try {
parseURI(uri);
} catch (e) {
return false;
}
return claims && claims[uri] && claims[uri].claim_id && myClaims.has(claims[uri].claim_id);
});
};
const selectAllFetchingChannelClaims = reselect.createSelector(selectState$1, state => state.fetchingChannelClaims || {});
@ -2303,7 +2335,7 @@ function doFetchChannelListMine() {
};
}
function doClaimSearch(amount = 20, options = {}) {
function doClaimSearch(options = {}) {
return dispatch => {
dispatch({
type: CLAIM_SEARCH_STARTED
@ -2330,9 +2362,7 @@ function doClaimSearch(amount = 20, options = {}) {
});
};
lbryProxy.claim_search(_extends$3({
page_size: amount
}, options)).then(success, failure);
lbryProxy.claim_search(_extends$3({}, options)).then(success, failure);
};
}

View file

@ -2,6 +2,7 @@ export const SEARCH_TYPES = {
FILE: 'file',
CHANNEL: 'channel',
SEARCH: 'search',
TAG: 'tag',
};
export const SEARCH_OPTIONS = {

View file

@ -2,7 +2,7 @@ const channelNameMinLength = 1;
const claimIdMaxLength = 40;
// see https://spec.lbry.com/#urls
export const regexInvalidURI = (exports.regexInvalidURI = /[=&#:$@%?\u{0000}-\u{0008}\u{000b}-\u{000c}\u{000e}-\u{001F}\u{D800}-\u{DFFF}\u{FFFE}-\u{FFFF}]/gu);
export const regexInvalidURI = /[ =&#:$@%?\u{0000}-\u{0008}\u{000b}-\u{000c}\u{000e}-\u{001F}\u{D800}-\u{DFFF}\u{FFFE}-\u{FFFF}]/gu;
export const regexAddress = /^(b|r)(?=[^0OIl]{32,33})[0-9A-Za-z]{32,33}$/;
/**

View file

@ -299,7 +299,7 @@ export function doFetchChannelListMine() {
};
}
export function doClaimSearch(amount: number = 20, options: { page?: number } = {}) {
export function doClaimSearch(options: { page_size?: number, page?: number } = {}) {
return (dispatch: Dispatch) => {
dispatch({
type: ACTIONS.CLAIM_SEARCH_STARTED,
@ -327,7 +327,6 @@ export function doClaimSearch(amount: number = 20, options: { page?: number } =
};
Lbry.claim_search({
page_size: amount,
...options,
}).then(success, failure);
};

View file

@ -60,8 +60,14 @@ export const makeSelectClaimIsPending = (uri: string) =>
createSelector(
selectPendingById,
pendingById => {
const { claimId } = parseURI(uri);
return Boolean(pendingById[claimId]);
let claimId;
try {
({ claimId } = parseURI(uri));
} catch (e) {}
if (claimId) {
return Boolean(pendingById[claimId]);
}
}
);
@ -81,13 +87,21 @@ export const makeSelectClaimForUri = (uri: string) =>
(byUri, pendingById) => {
// Check if a claim is pending first
// It won't be in claimsByUri because resolving it will return nothing
const { claimId } = parseURI(uri);
const pendingClaim = pendingById[claimId];
if (pendingClaim) {
return pendingClaim;
}
return byUri && byUri[normalizeURI(uri)];
let claimId;
try {
({ claimId } = parseURI(uri));
} catch (e) {}
if (claimId) {
const pendingClaim = pendingById[claimId];
if (pendingClaim) {
return pendingClaim;
}
return byUri && byUri[normalizeURI(uri)];
}
}
);
@ -114,12 +128,23 @@ export const selectMyActiveClaims = createSelector(
);
export const makeSelectClaimIsMine = (rawUri: string) => {
const uri = normalizeURI(rawUri);
let uri;
try {
uri = normalizeURI(rawUri);
} catch (e) {}
return createSelector(
selectClaimsByUri,
selectMyActiveClaims,
(claims, myClaims) =>
claims && claims[uri] && claims[uri].claim_id && myClaims.has(claims[uri].claim_id)
(claims, myClaims) => {
try {
parseURI(uri);
} catch (e) {
return false;
}
return claims && claims[uri] && claims[uri].claim_id && myClaims.has(claims[uri].claim_id);
}
);
};

View file

@ -96,6 +96,11 @@ export const selectSearchSuggestions: Array<SearchSuggestion> = createSelector(
});
}
searchSuggestions.push({
value: query,
type: SEARCH_TYPES.TAG,
});
const apiSuggestions = suggestions[query] || [];
if (apiSuggestions.length) {
searchSuggestions = searchSuggestions.concat(