bigbuffet-rw/app/soapbox/features/compose/containers/search_container.js

47 lines
883 B
JavaScript
Raw Normal View History

2020-03-27 13:59:38 -07:00
import { connect } from 'react-redux';
import {
changeSearch,
clearSearch,
submitSearch,
showSearch,
} from '../../../actions/search';
import Search from '../components/search';
2021-10-07 13:19:28 -07:00
import { debounce } from 'lodash';
2020-03-27 13:59:38 -07:00
const mapStateToProps = state => ({
value: state.getIn(['search', 'value']),
submitted: state.getIn(['search', 'submitted']),
});
2021-10-07 13:19:28 -07:00
const mapDispatchToProps = (dispatch, { autoSubmit }) => {
2020-03-27 13:59:38 -07:00
2021-10-07 13:19:28 -07:00
const debouncedSubmit = debounce(() => {
dispatch(submitSearch());
}, 900);
2020-03-27 13:59:38 -07:00
2021-10-07 13:19:28 -07:00
return {
onChange(value) {
dispatch(changeSearch(value));
2020-03-27 13:59:38 -07:00
2021-10-07 13:19:28 -07:00
if (autoSubmit) {
debouncedSubmit();
}
},
2020-03-27 13:59:38 -07:00
2021-10-07 13:19:28 -07:00
onClear() {
dispatch(clearSearch());
},
2020-03-27 13:59:38 -07:00
2021-10-07 13:19:28 -07:00
onSubmit() {
dispatch(submitSearch());
},
onShow() {
dispatch(showSearch());
},
};
};
2020-03-27 13:59:38 -07:00
export default connect(mapStateToProps, mapDispatchToProps)(Search);