lbry-desktop/src/ui/component/wunderbar/index.js
Sean Yesmunt c6a33c7a90
Merge pull request #2437 from lbryio/fixes
General fixes from routing/lbry.tv changes
2019-04-24 10:01:17 -04:00

45 lines
1.2 KiB
JavaScript

import { connect } from 'react-redux';
import {
doFocusSearchInput,
doBlurSearchInput,
doUpdateSearchQuery,
doSearch,
doToast,
selectSearchValue,
selectSearchSuggestions,
selectSearchBarFocused,
parseURI,
} from 'lbry-redux';
import analytics from 'analytics';
import Wunderbar from './view';
import { withRouter } from 'react-router-dom';
import { formatLbryUriForWeb } from 'util/uri';
const select = state => ({
suggestions: selectSearchSuggestions(state),
searchQuery: selectSearchValue(state),
isFocused: selectSearchBarFocused(state),
});
const perform = (dispatch, ownProps) => ({
onSearch: query => {
ownProps.history.push({ pathname: `/$/search`, search: `?q=${encodeURIComponent(query)}` });
analytics.apiLogSearch();
},
onSubmit: uri => {
const path = formatLbryUriForWeb(uri);
ownProps.history.push(path);
dispatch(doUpdateSearchQuery(''));
},
updateSearchQuery: query => dispatch(doUpdateSearchQuery(query)),
doShowSnackBar: message => dispatch(doToast({ isError: true, message })),
doFocus: () => dispatch(doFocusSearchInput()),
doBlur: () => dispatch(doBlurSearchInput()),
});
export default withRouter(
connect(
select,
perform
)(Wunderbar)
);