lbry-desktop/ui/page/search/index.js
jessopb 5f55603fb2
send recsys powered-by (#6875)
* send recsys powered-by

* update lighthouse call in useLighthouse

* rename select selectors

* update channel search too
2021-08-17 10:03:25 -04:00

49 lines
1.5 KiB
JavaScript

import { connect } from 'react-redux';
import { withRouter } from 'react-router';
import { doSearch } from 'redux/actions/search';
import {
selectIsSearching,
makeSelectSearchUrisForQuery,
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 = makeSelectSearchUrisForQuery(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));