Files
talk/client/coral-admin/src/containers/Community/CommunityContainer.js
T
Belén CurcioandDan Zajdband 5b74beabd6 Community Section - Search Commenters (#60)
* Table

* úsers api

* Ádding envs and version

* Community Table Added

* Ádding redux

* Adding loading data state

* Community Actions

* Adding Inmutable

* Fetching commenters

* Search commenters

* Linting and translations

* Ádding Sort

* sortBuilder

* pagr

* request per page, pager and mor

* package.json

* new Page actiokn

* éslint

* Changes and cleaner comps

* removed console.log
2016-11-11 11:14:26 -05:00

81 lines
1.7 KiB
JavaScript

import React, {Component} from 'react';
import {connect} from 'react-redux';
import {
fetchCommenters,
updateSorting,
newPage,
} from '../../actions/community';
import Community from './Community';
class CommunityContainer extends Component {
constructor(props) {
super(props);
this.state = {
searchValue: ''
};
this.onKeyDownHandler = this.onKeyDownHandler.bind(this);
this.onChangeHandler = this.onChangeHandler.bind(this);
this.onHeaderClickHandler = this.onHeaderClickHandler.bind(this);
this.onNewPageHandler = this.onNewPageHandler.bind(this);
}
onKeyDownHandler(e) {
if (e.key === 'Enter') {
e.preventDefault();
this.search();
}
}
onChangeHandler(e) {
this.setState({
searchValue: e.target.value
});
}
search(query = {}) {
const {community} = this.props;
this.props.dispatch(fetchCommenters({
value: this.state.searchValue,
field: community.get('field'),
asc: community.get('asc'),
...query
}));
}
componentDidMount() {
this.search();
}
onHeaderClickHandler(sort) {
this.props.dispatch(updateSorting(sort));
this.search();
}
onNewPageHandler(page) {
this.props.dispatch(newPage(page));
this.search({page});
}
render() {
const {searchValue} = this.state;
const {community} = this.props;
return (
<Community
searchValue={searchValue}
commenters={community.get('commenters')}
isFetching={community.get('isFetching')}
error={community.get('error')}
totalPages={community.get('totalPages')}
page={community.get('page')}
{...this}
/>
);
}
}
export default connect(({community}) => ({community}))(CommunityContainer);