2017-12-21 22:08:54 +01:00
|
|
|
import { connect } from 'react-redux';
|
2018-04-18 06:03:01 +02:00
|
|
|
import {
|
|
|
|
selectSearchState as selectSearch,
|
|
|
|
selectWunderBarAddress,
|
2018-08-14 23:06:55 +02:00
|
|
|
selectSearchSuggestions,
|
2018-04-18 06:03:01 +02:00
|
|
|
doUpdateSearchQuery,
|
2018-05-16 20:32:25 +02:00
|
|
|
doFocusSearchInput,
|
|
|
|
doBlurSearchInput,
|
2018-05-24 19:54:52 +02:00
|
|
|
doSearch,
|
2018-10-29 18:23:53 +01:00
|
|
|
doToast,
|
2018-04-18 06:03:01 +02:00
|
|
|
} from 'lbry-redux';
|
2019-02-05 19:36:40 +01:00
|
|
|
import analytics from 'analytics';
|
2017-12-21 22:08:54 +01:00
|
|
|
import { doNavigate } from 'redux/actions/navigation';
|
|
|
|
import Wunderbar from './view';
|
2017-05-04 05:44:08 +02:00
|
|
|
|
2018-03-26 23:32:43 +02:00
|
|
|
const select = state => {
|
|
|
|
const { isActive, searchQuery, ...searchState } = selectSearch(state);
|
|
|
|
const address = selectWunderBarAddress(state);
|
|
|
|
|
|
|
|
// if we are on the file/channel page
|
|
|
|
// use the address in the history stack
|
|
|
|
const wunderbarValue = isActive ? searchQuery : searchQuery || address;
|
|
|
|
|
|
|
|
return {
|
|
|
|
...searchState,
|
|
|
|
wunderbarValue,
|
2018-08-14 23:06:55 +02:00
|
|
|
suggestions: selectSearchSuggestions(state),
|
2018-03-26 23:32:43 +02:00
|
|
|
};
|
|
|
|
};
|
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 => {
|
|
|
|
dispatch(doSearch(query));
|
2018-05-24 19:54:52 +02:00
|
|
|
dispatch(doNavigate(`/search`, { query }));
|
2019-02-05 19:36:40 +01:00
|
|
|
analytics.apiLogSearch();
|
2018-03-26 23:32:43 +02:00
|
|
|
},
|
|
|
|
onSubmit: (uri, extraParams) => dispatch(doNavigate('/show', { uri, ...extraParams })),
|
|
|
|
updateSearchQuery: query => dispatch(doUpdateSearchQuery(query)),
|
2018-05-16 20:32:25 +02:00
|
|
|
doFocus: () => dispatch(doFocusSearchInput()),
|
|
|
|
doBlur: () => dispatch(doBlurSearchInput()),
|
2018-12-19 06:44:53 +01:00
|
|
|
doShowSnackBar: props => dispatch(doToast(props)),
|
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);
|