lbry-desktop/ui/page/search/index.js
infiinte-persistence 64874c773b Search: Get uris with same query as doSearch
## Issue
2731: Searches with forward slashes returns no results

## Change
The slash-removal came from (0db20834f9).

Removing the 2 `replace(/\//, ' ')` from lbry-desktop fixes it, but this PR assumes the slash-removal is intentional to cover something else. So, we'll make the Search side do the same thing to match what's happening in `doSearch`.

A little bit ugly, but there's already a comment about this in `makeSelectSearchUris`, so it'll probably get cleaned up in the future.
2021-02-02 15:08:52 -05:00

61 lines
1.9 KiB
JavaScript

import { connect } from 'react-redux';
import { doToast, SETTINGS } from 'lbry-redux';
import { withRouter } from 'react-router';
import { doSearch } from 'redux/actions/search';
import {
selectIsSearching,
makeSelectSearchUris,
makeSelectQueryWithOptions,
selectSearchOptions,
} from 'redux/selectors/search';
import { makeSelectClientSetting } from 'redux/selectors/settings';
import { selectUserVerifiedEmail } from 'redux/selectors/user';
import analytics from 'analytics';
import SearchPage from './view';
const select = (state, props) => {
const showMature = makeSelectClientSetting(SETTINGS.SHOW_MATURE)(state);
const urlParams = new URLSearchParams(props.location.search);
let urlQuery = urlParams.get('q') || null;
if (urlQuery) {
urlQuery = urlQuery.replace(/^lbry:\/\//i, '').replace(/\//, ' ');
}
const query = makeSelectQueryWithOptions(
urlQuery,
showMature === false ? { nsfw: false, isBackgroundSearch: false } : { isBackgroundSearch: false }
)(state);
const uris = makeSelectSearchUris(query)(state);
return {
isSearching: selectIsSearching(state),
showNsfw: makeSelectClientSetting(SETTINGS.SHOW_MATURE)(state),
uris: uris,
isAuthenticated: selectUserVerifiedEmail(state),
searchOptions: selectSearchOptions(state),
};
};
const perform = dispatch => ({
search: (query, options) => dispatch(doSearch(query, options)),
onFeedbackPositive: query => {
analytics.apiSearchFeedback(query, 1);
dispatch(
doToast({
message: __('Thanks for the feedback! You help make the app better for everyone.'),
})
);
},
onFeedbackNegative: query => {
analytics.apiSearchFeedback(query, 0);
dispatch(
doToast({
message: __(
'Thanks for the feedback. Mark has been notified and is currently walking over to his computer to work on this.'
),
})
);
},
});
export default withRouter(connect(select, perform)(SearchPage));