handle lbry uris in autocomplete results
This commit is contained in:
parent
86530690e9
commit
95124ff521
2 changed files with 49 additions and 16 deletions
34
dist/bundle.js
vendored
34
dist/bundle.js
vendored
|
@ -3840,16 +3840,34 @@ 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) {
|
||||
// This will need to be more robust when the api starts returning lbry uris
|
||||
var isChannel = suggestion.startsWith('@');
|
||||
var suggestionObj = {
|
||||
value: isChannel ? 'lbry://' + suggestion : suggestion,
|
||||
shorthand: isChannel ? suggestion.slice(1) : '',
|
||||
type: isChannel ? 'channel' : 'search'
|
||||
};
|
||||
if (suggestion.includes(' ')) {
|
||||
return {
|
||||
value: suggestion,
|
||||
type: SEARCH_TYPES.SEARCH
|
||||
};
|
||||
}
|
||||
|
||||
return suggestionObj;
|
||||
try {
|
||||
var _uri = (0, _lbryURI.normalizeURI)(suggestion);
|
||||
|
||||
var _parseURI2 = (0, _lbryURI.parseURI)(_uri),
|
||||
_claimName = _parseURI2.claimName,
|
||||
_isChannel = _parseURI2.isChannel;
|
||||
|
||||
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);
|
||||
|
|
|
@ -137,16 +137,31 @@ export const getSearchSuggestions = (value: string) => dispatch => {
|
|||
fetch(`https://lighthouse.lbry.io/autocomplete?s=${searchValue}`)
|
||||
.then(handleFetchResponse)
|
||||
.then(apiSuggestions => {
|
||||
// Suggestion could be a channel, uri, or search term
|
||||
const formattedSuggestions = apiSuggestions.slice(0, 6).map(suggestion => {
|
||||
// This will need to be more robust when the api starts returning lbry uris
|
||||
const isChannel = suggestion.startsWith('@');
|
||||
const suggestionObj = {
|
||||
value: isChannel ? `lbry://${suggestion}` : suggestion,
|
||||
shorthand: isChannel ? suggestion.slice(1) : '',
|
||||
type: isChannel ? 'channel' : 'search',
|
||||
};
|
||||
if (suggestion.includes(' ')) {
|
||||
return {
|
||||
value: suggestion,
|
||||
type: SEARCH_TYPES.SEARCH,
|
||||
};
|
||||
}
|
||||
|
||||
return suggestionObj;
|
||||
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,
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
suggestions = suggestions.concat(formattedSuggestions);
|
||||
|
|
Loading…
Reference in a new issue