2017-12-21 22:08:54 +01:00
|
|
|
import { connect } from 'react-redux';
|
2020-10-28 20:18:58 +01:00
|
|
|
import { withRouter } from 'react-router';
|
2020-07-27 22:04:12 +02:00
|
|
|
import { doSearch } from 'redux/actions/search';
|
2020-12-03 22:31:38 +01:00
|
|
|
import {
|
|
|
|
selectIsSearching,
|
2021-08-17 16:03:25 +02:00
|
|
|
makeSelectSearchUrisForQuery,
|
2020-12-03 22:31:38 +01:00
|
|
|
selectSearchOptions,
|
2021-03-26 09:33:30 +01:00
|
|
|
makeSelectHasReachedMaxResultsLength,
|
2020-12-03 22:31:38 +01:00
|
|
|
} from 'redux/selectors/search';
|
2021-03-31 22:55:26 +02:00
|
|
|
import { selectShowMatureContent } from 'redux/selectors/settings';
|
2021-07-13 08:28:09 +02:00
|
|
|
import { getSearchQueryString } from 'util/query-params';
|
2017-12-21 22:08:54 +01:00
|
|
|
import SearchPage from './view';
|
2017-05-05 10:01:16 +02:00
|
|
|
|
2020-10-28 20:18:58 +01:00
|
|
|
const select = (state, props) => {
|
2021-03-31 22:55:26 +02:00
|
|
|
const showMature = selectShowMatureContent(state);
|
2020-10-28 20:18:58 +01:00
|
|
|
const urlParams = new URLSearchParams(props.location.search);
|
2021-07-13 08:28:09 +02:00
|
|
|
|
2021-02-01 05:33:46 +01:00
|
|
|
let urlQuery = urlParams.get('q') || null;
|
|
|
|
if (urlQuery) {
|
|
|
|
urlQuery = urlQuery.replace(/^lbry:\/\//i, '').replace(/\//, ' ');
|
|
|
|
}
|
2021-03-24 17:58:19 +01:00
|
|
|
|
2021-07-13 08:28:09 +02:00
|
|
|
const searchOptions = {
|
|
|
|
...selectSearchOptions(state),
|
|
|
|
isBackgroundSearch: false,
|
|
|
|
nsfw: showMature,
|
|
|
|
};
|
|
|
|
|
|
|
|
const query = getSearchQueryString(urlQuery, searchOptions);
|
2021-08-17 16:03:25 +02:00
|
|
|
const uris = makeSelectSearchUrisForQuery(query)(state);
|
2021-03-26 09:33:30 +01:00
|
|
|
const hasReachedMaxResultsLength = makeSelectHasReachedMaxResultsLength(query)(state);
|
2020-01-30 08:09:12 +01:00
|
|
|
|
|
|
|
return {
|
2021-07-13 08:28:09 +02:00
|
|
|
urlQuery,
|
|
|
|
searchOptions,
|
2020-01-30 08:09:12 +01:00
|
|
|
isSearching: selectIsSearching(state),
|
|
|
|
uris: uris,
|
2021-03-26 09:33:30 +01:00
|
|
|
hasReachedMaxResultsLength: hasReachedMaxResultsLength,
|
2020-01-30 08:09:12 +01:00
|
|
|
};
|
|
|
|
};
|
2017-05-05 10:01:16 +02:00
|
|
|
|
2021-03-31 22:55:26 +02:00
|
|
|
const perform = (dispatch) => ({
|
2020-01-30 08:09:12 +01:00
|
|
|
search: (query, options) => dispatch(doSearch(query, options)),
|
2019-06-11 20:10:58 +02:00
|
|
|
});
|
2017-05-05 10:01:16 +02:00
|
|
|
|
2020-10-28 20:18:58 +01:00
|
|
|
export default withRouter(connect(select, perform)(SearchPage));
|