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

45 lines
1.2 KiB
JavaScript
Raw Normal View History

import { connect } from 'react-redux';
2018-04-18 00:03:01 -04:00
import {
2018-05-16 14:32:25 -04:00
doFocusSearchInput,
doBlurSearchInput,
2019-03-28 12:53:13 -04:00
doUpdateSearchQuery,
doToast,
2019-03-28 12:53:13 -04:00
selectSearchValue,
selectSearchSuggestions,
selectSearchBarFocused,
2018-04-18 00:03:01 -04:00
} from 'lbry-redux';
2019-02-05 13:36:40 -05:00
import analytics from 'analytics';
import Wunderbar from './view';
2019-04-04 17:05:23 -04:00
import { withRouter } from 'react-router-dom';
import { formatLbryUrlForWeb } from 'util/url';
2017-05-03 23:44:08 -04:00
2019-03-28 12:53:13 -04:00
const select = state => ({
suggestions: selectSearchSuggestions(state),
searchQuery: selectSearchValue(state),
isFocused: selectSearchBarFocused(state),
});
2017-05-03 23:44:08 -04:00
2019-04-04 17:05:23 -04:00
const perform = (dispatch, ownProps) => ({
2019-02-18 12:24:56 -05:00
onSearch: query => {
2019-04-19 14:47:25 -04:00
ownProps.history.push({ pathname: `/$/search`, search: `?q=${encodeURIComponent(query)}` });
2019-07-04 12:05:21 +01:00
dispatch(doUpdateSearchQuery(query));
2019-02-05 13:36:40 -05:00
analytics.apiLogSearch();
2018-03-26 14:32:43 -07:00
},
2019-03-28 12:53:13 -04:00
onSubmit: uri => {
const path = formatLbryUrlForWeb(uri);
2019-04-04 17:05:23 -04:00
ownProps.history.push(path);
2019-03-28 12:53:13 -04:00
dispatch(doUpdateSearchQuery(''));
},
2018-03-26 14:32:43 -07:00
updateSearchQuery: query => dispatch(doUpdateSearchQuery(query)),
doShowSnackBar: message => dispatch(doToast({ isError: true, message })),
2018-05-16 14:32:25 -04:00
doFocus: () => dispatch(doFocusSearchInput()),
doBlur: () => dispatch(doBlurSearchInput()),
2017-06-05 21:21:55 -07:00
});
2017-05-03 23:44:08 -04:00
2019-04-04 17:05:23 -04:00
export default withRouter(
connect(
select,
perform
)(Wunderbar)
);