lbry-desktop/ui/page/search/index.js

47 lines
1.4 KiB
JavaScript
Raw Normal View History

import { connect } from 'react-redux';
import { withRouter } from 'react-router';
2020-07-27 22:04:12 +02:00
import { doSearch } from 'redux/actions/search';
import {
selectIsSearching,
makeSelectSearchUrisForQuery,
selectSearchOptions,
2021-03-26 09:33:30 +01:00
makeSelectHasReachedMaxResultsLength,
} from 'redux/selectors/search';
2021-03-31 22:55:26 +02:00
import { selectShowMatureContent } from 'redux/selectors/settings';
import { getSearchQueryString } from 'util/query-params';
import SearchPage from './view';
2017-05-05 10:01:16 +02:00
const select = (state, props) => {
2021-03-31 22:55:26 +02:00
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);
2021-03-26 09:33:30 +01:00
const hasReachedMaxResultsLength = makeSelectHasReachedMaxResultsLength(query)(state);
return {
urlQuery,
searchOptions,
isSearching: selectIsSearching(state),
uris: uris,
2021-03-26 09:33:30 +01:00
hasReachedMaxResultsLength: hasReachedMaxResultsLength,
};
};
2017-05-05 10:01:16 +02:00
2021-03-31 22:55:26 +02:00
const perform = (dispatch) => ({
search: (query, options) => dispatch(doSearch(query, options)),
2019-06-11 20:10:58 +02:00
});
2017-05-05 10:01:16 +02:00
export default withRouter(connect(select, perform)(SearchPage));