lbry-desktop/ui/page/search/index.js
infinite-persistence b822ae39e1
Remove hardcoded filters in doSearch
## Issue
6414 <Don't use "exact match" setting outside of main search - cuases no results in related>

`doSearch` was used in Wunderbar and Recommended, but it was adding in Wunderbar options all the time.

## Changes
- Fix `doSearch` to not use hardcoded options (take from arguments).
- Refactors the searchOption-creation code so that we don't duplicate the logic in both .js and .jsx.
2021-07-14 11:16:19 +08:00

48 lines
1.5 KiB
JavaScript

import { connect } from 'react-redux';
import { withRouter } from 'react-router';
import { doSearch } from 'redux/actions/search';
import {
selectIsSearching,
makeSelectSearchUris,
selectSearchOptions,
makeSelectHasReachedMaxResultsLength,
} from 'redux/selectors/search';
import { selectShowMatureContent } from 'redux/selectors/settings';
import { selectUserVerifiedEmail } from 'redux/selectors/user';
import { getSearchQueryString } from 'util/query-params';
import SearchPage from './view';
const select = (state, props) => {
const showMature = selectShowMatureContent(state);
const urlParams = new URLSearchParams(props.location.search);
let urlQuery = urlParams.get('q') || null;
if (urlQuery) {
urlQuery = urlQuery.replace(/^lbry:\/\//i, '').replace(/\//, ' ');
}
const searchOptions = {
...selectSearchOptions(state),
isBackgroundSearch: false,
nsfw: showMature,
};
const query = getSearchQueryString(urlQuery, searchOptions);
const uris = makeSelectSearchUris(query)(state);
const hasReachedMaxResultsLength = makeSelectHasReachedMaxResultsLength(query)(state);
return {
urlQuery,
searchOptions,
isSearching: selectIsSearching(state),
uris: uris,
isAuthenticated: selectUserVerifiedEmail(state),
hasReachedMaxResultsLength: hasReachedMaxResultsLength,
};
};
const perform = (dispatch) => ({
search: (query, options) => dispatch(doSearch(query, options)),
});
export default withRouter(connect(select, perform)(SearchPage));