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

42 lines
1 KiB
JavaScript
Raw Normal View History

import { connect } from 'react-redux';
2018-04-18 06:03:01 +02:00
import {
2018-05-16 20:32:25 +02:00
doFocusSearchInput,
doBlurSearchInput,
2019-03-28 17:53:13 +01:00
doUpdateSearchQuery,
2018-05-24 19:54:52 +02:00
doSearch,
2019-03-28 17:53:13 +01:00
selectSearchValue,
selectSearchSuggestions,
selectSearchBarFocused,
parseURI,
2018-04-18 06:03:01 +02:00
} from 'lbry-redux';
2019-02-05 19:36:40 +01:00
import analytics from 'analytics';
import Wunderbar from './view';
2019-03-28 17:53:13 +01:00
import { navigate } from '@reach/router';
import { formatLbryUriForWeb } from 'util/uri';
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),
});
2017-05-04 05:44:08 +02:00
2017-06-06 06:21:55 +02:00
const perform = dispatch => ({
2019-02-18 18:24:56 +01:00
onSearch: query => {
2019-03-28 17:53:13 +01:00
navigate(`/$/search?q=${query}`);
2019-02-05 19:36:40 +01:00
analytics.apiLogSearch();
2018-03-26 23:32:43 +02:00
},
2019-03-28 17:53:13 +01:00
onSubmit: uri => {
const path = formatLbryUriForWeb(uri);
navigate(path);
dispatch(doUpdateSearchQuery(''));
},
2018-03-26 23:32:43 +02:00
updateSearchQuery: query => dispatch(doUpdateSearchQuery(query)),
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
2018-06-20 05:55:25 +02:00
export default connect(
select,
perform
)(Wunderbar);