Fix the people tag.

This commit is contained in:
gaba
2017-02-28 22:10:14 -08:00
parent da3c812dc1
commit 6dfd3fc4ef
3 changed files with 28 additions and 48 deletions
@@ -13,6 +13,7 @@ import {
import coralApi from '../../../coral-framework/helpers/response'; import coralApi from '../../../coral-framework/helpers/response';
export const fetchAccounts = (query = {}) => dispatch => { export const fetchAccounts = (query = {}) => dispatch => {
dispatch(requestFetchAccounts()); dispatch(requestFetchAccounts());
coralApi(`/users?${qs.stringify(query)}`) coralApi(`/users?${qs.stringify(query)}`)
.then(({result, page, count, limit, totalPages}) =>{ .then(({result, page, count, limit, totalPages}) =>{
@@ -1,10 +1,11 @@
import React, {Component} from 'react'; import React, {Component} from 'react';
import {connect} from 'react-redux'; import {connect} from 'react-redux';
import {modUserFlaggedQuery} from 'coral-admin/src/graphql/queries';
import {compose} from 'react-apollo';
import { import {
fetchAccounts, fetchAccounts,
updateSorting, updateSorting,
newPage, newPage
fetchFlaggedAccounts,
} from '../../actions/community'; } from '../../actions/community';
import CommunityMenu from './components/CommunityMenu'; import CommunityMenu from './components/CommunityMenu';
@@ -33,6 +34,10 @@ class CommunityContainer extends Component {
this.onNewPageHandler = this.onNewPageHandler.bind(this); this.onNewPageHandler = this.onNewPageHandler.bind(this);
} }
componentWillMount() {
this.props.fetchAccounts({});
}
onKeyDownHandler(e) { onKeyDownHandler(e) {
if (e.key === 'Enter') { if (e.key === 'Enter') {
e.preventDefault(); e.preventDefault();
@@ -49,23 +54,15 @@ class CommunityContainer extends Component {
search(query = {}) { search(query = {}) {
const {community} = this.props; const {community} = this.props;
this.props.dispatch(fetchAccounts({ this.props.fetchAccounts({
value: this.state.searchValue, value: this.state.searchValue,
field: community.fieldPeople, field: community.fieldPeople,
asc: community.ascPeople, asc: community.ascPeople,
...query ...query
})); });
} }
componentWillMount() {
this.props.dispatch(fetchFlaggedAccounts());
}
componentDidMount() {
this.search();
}
onHeaderClickHandler(sort) { onHeaderClickHandler(sort) {
this.props.dispatch(updateSorting(sort)); this.props.dispatch(updateSorting(sort));
this.search(); this.search();
@@ -76,9 +73,9 @@ class CommunityContainer extends Component {
this.search({page}); this.search({page});
} }
getTabContent(searchValue) { getTabContent(searchValue, props) {
const {community} = this.props; const {community, data} = props;
const activeTab = this.props.route.path === ':id' ? 'flagged' : this.props.route.path; const activeTab = props.route.path === ':id' ? 'flagged' : props.route.path;
if (activeTab === 'people') { if (activeTab === 'people') {
return ( return (
@@ -96,18 +93,18 @@ class CommunityContainer extends Component {
return ( return (
<FlaggedAccounts <FlaggedAccounts
commenters={community.flaggedAccounts} commenters={data.usersFlagged}
isFetching={community.isFetchingFlagged} isFetching={data.loading}
error={community.errorFlagged} error={data.error}
{...this} {...this}
/> />
); );
} }
render() { render() {
const {searchValue, activeTab} = this.state; const {searchValue} = this.state;
const tab = this.getTabContent(activeTab, searchValue, this.props); const tab = this.getTabContent(searchValue, this.props);
return ( return (
<div> <div>
@@ -124,4 +121,11 @@ const mapStateToProps = state => ({
community: state.community.toJS() community: state.community.toJS()
}); });
export default connect(mapStateToProps)(CommunityContainer); const mapDispatchToProps = dispatch => ({
fetchAccounts: query => dispatch(fetchAccounts(query))
});
export default compose(
connect(mapStateToProps, mapDispatchToProps),
modUserFlaggedQuery
)(CommunityContainer);
+2 -27
View File
@@ -6,10 +6,7 @@ import {
FETCH_COMMENTERS_SUCCESS, FETCH_COMMENTERS_SUCCESS,
SORT_UPDATE, SORT_UPDATE,
SET_ROLE, SET_ROLE,
SET_COMMENTER_STATUS, SET_COMMENTER_STATUS
FETCH_FLAGGED_COMMENTERS_REQUEST,
FETCH_FLAGGED_COMMENTERS_SUCCESS,
FETCH_FLAGGED_COMMENTERS_FAILURE
} from '../constants/community'; } from '../constants/community';
const initialState = Map({ const initialState = Map({
@@ -20,10 +17,7 @@ const initialState = Map({
fieldPeople: 'created_at', fieldPeople: 'created_at',
ascPeople: false, ascPeople: false,
totalPagesPeople: 0, totalPagesPeople: 0,
pagePeople: 0, pagePeople: 0
isFetchingFlagged: false,
errorFlagged: '',
flaggedAccounts: [],
}); });
export default function community (state = initialState, action) { export default function community (state = initialState, action) {
@@ -69,25 +63,6 @@ export default function community (state = initialState, action) {
return state return state
.set('fieldPeople', action.sort.field) .set('fieldPeople', action.sort.field)
.set('ascPeople', !state.get('ascPeople')); .set('ascPeople', !state.get('ascPeople'));
case FETCH_FLAGGED_COMMENTERS_REQUEST : {
return state
.set('isFetchingFlagged', true);
}
case FETCH_FLAGGED_COMMENTERS_SUCCESS : {
const {flaggedAccounts, type, ...rest} = action; // eslint-disable-line
return state
.merge({
isFetchingFlagged: false,
errorFlagged: '',
...rest
})
.set('flaggedAccounts', flaggedAccounts); // Sets to normal array
}
case FETCH_FLAGGED_COMMENTERS_FAILURE : {
return state
.set('isFetchingFlagged', false)
.set('errorFlagged', action.error);
}
default : default :
return state; return state;
} }