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

37 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-03-26 23:32:43 +02:00
import * as MODALS from 'constants/modal_types';
import { connect } from 'react-redux';
2018-04-18 06:03:01 +02:00
import { normalizeURI } from 'lbry-redux';
import {
selectSearchState as selectSearch,
selectWunderBarAddress,
doUpdateSearchQuery,
2018-04-19 18:51:18 +02:00
doNotify,
2018-04-18 06:03:01 +02:00
} from 'lbry-redux';
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,
};
};
2017-05-04 05:44:08 +02:00
2017-06-06 06:21:55 +02:00
const perform = dispatch => ({
2018-03-26 23:32:43 +02:00
onSearch: query => {
dispatch(doUpdateSearchQuery(query));
2018-04-19 18:51:18 +02:00
dispatch(doNotify({ id: MODALS.SEARCH }));
2018-03-26 23:32:43 +02:00
},
onSubmit: (uri, extraParams) => dispatch(doNavigate('/show', { uri, ...extraParams })),
updateSearchQuery: query => dispatch(doUpdateSearchQuery(query)),
2017-06-06 06:21:55 +02:00
});
2017-05-04 05:44:08 +02:00
2017-06-06 06:21:55 +02:00
export default connect(select, perform)(Wunderbar);