Merge pull request #32 from lbryio/search

filter search suggestions so the search query isn't suggested twice
This commit is contained in:
Sean Yesmunt 2018-05-29 15:58:04 -04:00 committed by GitHub
commit b8d5f1c8be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 36 deletions

10
dist/bundle.js vendored
View file

@ -3924,12 +3924,6 @@ var getSearchSuggestions = exports.getSearchSuggestions = function getSearchSugg
value: claimName,
type: SEARCH_TYPES.SEARCH
});
// If it's a valid url, don't fetch any extra search results
dispatch({
type: ACTIONS.UPDATE_SEARCH_SUGGESTIONS,
data: { suggestions: suggestions }
});
} catch (e) {
suggestions.push({
value: query,
@ -3953,7 +3947,9 @@ var getSearchSuggestions = exports.getSearchSuggestions = function getSearchSugg
fetch('https://lighthouse.lbry.io/autocomplete?s=' + searchValue).then(_handleFetch2.default).then(function (apiSuggestions) {
// Suggestion could be a channel, uri, or search term
var formattedSuggestions = apiSuggestions.slice(0, 6).map(function (suggestion) {
var formattedSuggestions = apiSuggestions.slice(0, 6).filter(function (suggestion) {
return suggestion !== query;
}).map(function (suggestion) {
if (suggestion.includes(' ')) {
return {
value: suggestion,

View file

@ -107,12 +107,6 @@ export const getSearchSuggestions = (value: string) => dispatch => {
type: SEARCH_TYPES.SEARCH,
}
);
// If it's a valid url, don't fetch any extra search results
dispatch({
type: ACTIONS.UPDATE_SEARCH_SUGGESTIONS,
data: { suggestions },
});
} catch (e) {
suggestions.push({
value: query,
@ -138,31 +132,34 @@ export const getSearchSuggestions = (value: string) => dispatch => {
.then(handleFetchResponse)
.then(apiSuggestions => {
// Suggestion could be a channel, uri, or search term
const formattedSuggestions = apiSuggestions.slice(0, 6).map(suggestion => {
if (suggestion.includes(' ')) {
return {
value: suggestion,
type: SEARCH_TYPES.SEARCH,
};
}
const formattedSuggestions = apiSuggestions
.slice(0, 6)
.filter(suggestion => suggestion !== query)
.map(suggestion => {
if (suggestion.includes(' ')) {
return {
value: suggestion,
type: SEARCH_TYPES.SEARCH,
};
}
try {
const uri = normalizeURI(suggestion);
const { claimName, isChannel } = parseURI(uri);
try {
const uri = normalizeURI(suggestion);
const { claimName, isChannel } = parseURI(uri);
return {
value: uri,
shorthand: isChannel ? claimName.slice(1) : claimName,
type: isChannel ? SEARCH_TYPES.CHANNEL : SEARCH_TYPES.FILE,
};
} catch (e) {
// search result includes some character that isn't valid in claim names
return {
value: suggestion,
type: SEARCH_TYPES.SEARCH,
};
}
});
return {
value: uri,
shorthand: isChannel ? claimName.slice(1) : claimName,
type: isChannel ? SEARCH_TYPES.CHANNEL : SEARCH_TYPES.FILE,
};
} catch (e) {
// search result includes some character that isn't valid in claim names
return {
value: suggestion,
type: SEARCH_TYPES.SEARCH,
};
}
});
suggestions = suggestions.concat(formattedSuggestions);
dispatch({