lbry-desktop/ui/component/wunderbar/index.js

35 lines
1.4 KiB
JavaScript
Raw Normal View History

import { connect } from 'react-redux';
2020-07-27 22:04:12 +02:00
import { SETTINGS } from 'lbry-redux';
import { doFocusSearchInput, doBlurSearchInput, doUpdateSearchQuery } from 'redux/actions/search';
import { selectSearchValue, selectSearchSuggestions, selectSearchBarFocused } from 'redux/selectors/search';
import { makeSelectClientSetting } from 'redux/selectors/settings';
import { doToast } from 'redux/actions/notifications';
2019-02-05 19:36:40 +01:00
import analytics from 'analytics';
import Wunderbar from './view';
2019-04-04 23:05:23 +02:00
import { withRouter } from 'react-router-dom';
2017-05-04 05:44:08 +02:00
2019-03-28 17:53:13 +01:00
const select = state => ({
suggestions: selectSearchSuggestions(state),
searchQuery: selectSearchValue(state),
isFocused: selectSearchBarFocused(state),
language: makeSelectClientSetting(SETTINGS.LANGUAGE)(state),
2019-03-28 17:53:13 +01:00
});
2017-05-04 05:44:08 +02:00
2019-04-04 23:05:23 +02:00
const perform = (dispatch, ownProps) => ({
doSearch: query => {
let encodedQuery = encodeURIComponent(query);
ownProps.history.push({ pathname: `/$/search`, search: `?q=${encodedQuery}` });
2019-07-04 13:05:21 +02:00
dispatch(doUpdateSearchQuery(query));
2019-02-05 19:36:40 +01:00
analytics.apiLogSearch();
2018-03-26 23:32:43 +02:00
},
navigateToUri: uri => {
ownProps.history.push(uri);
2019-03-28 17:53:13 +01:00
},
2018-03-26 23:32:43 +02:00
updateSearchQuery: query => dispatch(doUpdateSearchQuery(query)),
doShowSnackBar: message => dispatch(doToast({ isError: true, message })),
2018-05-16 20:32:25 +02:00
doFocus: () => dispatch(doFocusSearchInput()),
doBlur: () => dispatch(doBlurSearchInput()),
2017-06-06 06:21:55 +02:00
});
2017-05-04 05:44:08 +02:00
export default withRouter(connect(select, perform)(Wunderbar));