2017-12-21 22:08:54 +01:00
|
|
|
import { connect } from 'react-redux';
|
2020-07-27 22:04:12 +02:00
|
|
|
import { doToast, SETTINGS } from 'lbry-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,
|
|
|
|
makeSelectSearchUris,
|
|
|
|
makeSelectQueryWithOptions,
|
|
|
|
selectSearchOptions,
|
|
|
|
} from 'redux/selectors/search';
|
2020-01-30 08:09:12 +01:00
|
|
|
import { makeSelectClientSetting } from 'redux/selectors/settings';
|
2020-06-15 22:33:03 +02:00
|
|
|
import { selectUserVerifiedEmail } from 'redux/selectors/user';
|
2019-06-11 20:10:58 +02:00
|
|
|
import analytics from 'analytics';
|
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) => {
|
2020-01-30 08:09:12 +01:00
|
|
|
const showMature = makeSelectClientSetting(SETTINGS.SHOW_MATURE)(state);
|
2020-10-28 20:18:58 +01:00
|
|
|
const urlParams = new URLSearchParams(props.location.search);
|
2021-02-01 05:33:46 +01:00
|
|
|
let urlQuery = urlParams.get('q') || null;
|
|
|
|
if (urlQuery) {
|
|
|
|
urlQuery = urlQuery.replace(/^lbry:\/\//i, '').replace(/\//, ' ');
|
|
|
|
}
|
|
|
|
|
2020-01-30 08:09:12 +01:00
|
|
|
const query = makeSelectQueryWithOptions(
|
2020-10-28 20:18:58 +01:00
|
|
|
urlQuery,
|
2020-01-30 08:09:12 +01:00
|
|
|
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,
|
2020-03-26 22:47:07 +01:00
|
|
|
isAuthenticated: selectUserVerifiedEmail(state),
|
2020-12-03 22:31:38 +01:00
|
|
|
searchOptions: selectSearchOptions(state),
|
2020-01-30 08:09:12 +01:00
|
|
|
};
|
|
|
|
};
|
2017-05-05 10:01:16 +02:00
|
|
|
|
2019-06-11 20:10:58 +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
|
|
|
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.'
|
|
|
|
),
|
|
|
|
})
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
2017-05-05 10:01:16 +02:00
|
|
|
|
2020-10-28 20:18:58 +01:00
|
|
|
export default withRouter(connect(select, perform)(SearchPage));
|