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

57 lines
1.8 KiB
JavaScript
Raw Normal View History

import { connect } from 'react-redux';
2021-03-31 21:07:11 +02:00
import { doToast } from 'lbry-redux';
import { withRouter } from 'react-router';
2020-07-27 22:04:12 +02:00
import { doSearch } from 'redux/actions/search';
import {
selectIsSearching,
makeSelectSearchUris,
makeSelectQueryWithOptions,
selectSearchOptions,
} from 'redux/selectors/search';
2021-03-31 21:07:11 +02:00
import { selectShowMatureContent } from 'redux/selectors/settings';
import { selectUserVerifiedEmail } from 'redux/selectors/user';
2019-06-11 20:10:58 +02:00
import analytics from 'analytics';
import SearchPage from './view';
2017-05-05 10:01:16 +02:00
const select = (state, props) => {
const urlParams = new URLSearchParams(props.location.search);
let urlQuery = urlParams.get('q') || null;
if (urlQuery) {
urlQuery = urlQuery.replace(/^lbry:\/\//i, '').replace(/\//, ' ');
}
const query = makeSelectQueryWithOptions(urlQuery, { nsfw: false, isBackgroundSearch: false })(state);
const uris = makeSelectSearchUris(query)(state);
return {
isSearching: selectIsSearching(state),
2021-03-31 21:07:11 +02:00
showNsfw: selectShowMatureContent(state),
uris: uris,
2020-03-26 22:47:07 +01:00
isAuthenticated: selectUserVerifiedEmail(state),
searchOptions: selectSearchOptions(state),
};
};
2017-05-05 10:01:16 +02:00
const perform = (dispatch) => ({
search: (query, options) => dispatch(doSearch(query, options)),
onFeedbackPositive: (query) => {
2019-06-11 20:10:58 +02:00
analytics.apiSearchFeedback(query, 1);
dispatch(
doToast({
message: __('Thanks for the feedback! You help make the app better for everyone.'),
})
);
},
onFeedbackNegative: (query) => {
2019-06-11 20:10:58 +02:00
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
export default withRouter(connect(select, perform)(SearchPage));