mirror of
https://github.com/wassname/talk.git
synced 2026-07-15 11:26:58 +08:00
Get more data into the store.
This commit is contained in:
@@ -7,18 +7,21 @@ import {
|
||||
SORT_UPDATE,
|
||||
COMMENTERS_NEW_PAGE,
|
||||
SET_ROLE,
|
||||
SET_COMMENTER_STATUS
|
||||
SET_COMMENTER_STATUS,
|
||||
FETCH_FLAGGED_COMMENTERS_REQUEST,
|
||||
FETCH_FLAGGED_COMMENTERS_SUCCESS,
|
||||
FETCH_FLAGGED_COMMENTERS_FAILURE
|
||||
} from '../constants/community';
|
||||
|
||||
import coralApi from '../../../coral-framework/helpers/response';
|
||||
|
||||
export const fetchCommenters = (query = {}) => dispatch => {
|
||||
dispatch(requestFetchCommenters());
|
||||
export const fetchAccounts = (query = {}) => dispatch => {
|
||||
dispatch(requestFetchAccounts());
|
||||
coralApi(`/users?${qs.stringify(query)}`)
|
||||
.then(({result, page, count, limit, totalPages}) =>
|
||||
dispatch({
|
||||
type: FETCH_COMMENTERS_SUCCESS,
|
||||
commenters: result,
|
||||
accounts: result,
|
||||
page,
|
||||
count,
|
||||
limit,
|
||||
@@ -28,7 +31,7 @@ export const fetchCommenters = (query = {}) => dispatch => {
|
||||
.catch(error => dispatch({type: FETCH_COMMENTERS_FAILURE, error}));
|
||||
};
|
||||
|
||||
const requestFetchCommenters = () => ({
|
||||
const requestFetchAccounts = () => ({
|
||||
type: FETCH_COMMENTERS_REQUEST
|
||||
});
|
||||
|
||||
@@ -55,3 +58,25 @@ export const setCommenterStatus = (id, status) => (dispatch) => {
|
||||
return dispatch({type: SET_COMMENTER_STATUS, id, status});
|
||||
});
|
||||
};
|
||||
|
||||
// Fetch flagged accounts to display in the moderation queue of the community.
|
||||
|
||||
export const fetchFlaggedAccounts = (query = {}) => dispatch => {
|
||||
dispatch(requestFetchFlaggedAccounts());
|
||||
coralApi(`/users?${qs.stringify(query)}`)
|
||||
.then(({result, page, count, limit, totalPages}) =>
|
||||
dispatch({
|
||||
type: FETCH_FLAGGED_COMMENTERS_SUCCESS,
|
||||
flaggedAccounts: result,
|
||||
page,
|
||||
count,
|
||||
limit,
|
||||
totalPages
|
||||
})
|
||||
)
|
||||
.catch(error => dispatch({type: FETCH_FLAGGED_COMMENTERS_FAILURE, error}));
|
||||
};
|
||||
|
||||
const requestFetchFlaggedAccounts = () => ({
|
||||
type: FETCH_FLAGGED_COMMENTERS_REQUEST
|
||||
});
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
export const SHOW_BANUSER_DIALOG = 'SHOW_BANUSER_DIALOG';
|
||||
export const HIDE_BANUSER_DIALOG = 'HIDE_BANUSER_DIALOG';
|
||||
export const USERS_MODERATION_QUEUE_FETCH_SUCCESS = 'USERS_MODERATION_QUEUE_FETCH_SUCCESS';
|
||||
export const COMMENTS_MODERATION_QUEUE_FETCH_REQUEST = 'COMMENTS_MODERATION_QUEUE_FETCH_REQUEST';
|
||||
export const COMMENTS_MODERATION_QUEUE_FETCH_SUCCESS = 'COMMENTS_MODERATION_QUEUE_FETCH_SUCCESS';
|
||||
export const COMMENT_CREATE_SUCCESS = 'COMMENT_CREATE_SUCCESS';
|
||||
|
||||
@@ -5,3 +5,7 @@ export const SORT_UPDATE = 'SORT_UPDATE';
|
||||
export const COMMENTERS_NEW_PAGE = 'COMMENTERS_NEW_PAGE';
|
||||
export const SET_ROLE = 'SET_ROLE';
|
||||
export const SET_COMMENTER_STATUS = 'SET_COMMENTER_STATUS';
|
||||
|
||||
export const FETCH_FLAGGED_COMMENTERS_REQUEST = 'FETCH_FLAGGED_COMMENTERS_REQUEST';
|
||||
export const FETCH_FLAGGED_COMMENTERS_SUCCESS = 'FETCH_FLAGGED_COMMENTERS_SUCCESS';
|
||||
export const FETCH_FLAGGED_COMMENTERS_FAILURE = 'FETCH_FLAGGED_COMMENTERS_FAILURE';
|
||||
|
||||
@@ -3,4 +3,3 @@ export const UPDATE_STATUS_SUCCESS = 'UPDATE_STATUS_SUCCESS';
|
||||
export const UPDATE_STATUS_FAILURE = 'UPDATE_STATUS_FAILURE';
|
||||
export const USER_EMAIL_FAILURE = 'USER_EMAIL_FAILURE';
|
||||
export const USERNAME_ENABLE_FAILURE = 'USERNAME_ENABLE_FAILURE';
|
||||
export const USERS_MODERATION_QUEUE_FETCH_SUCCESS = 'USERS_MODERATION_QUEUE_FETCH_SUCCESS';
|
||||
|
||||
@@ -15,6 +15,12 @@
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.mainFlaggedContent {
|
||||
width: 100%;
|
||||
padding: 34px 14px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.roleButton {
|
||||
display: block;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React, {Component} from 'react';
|
||||
import {connect} from 'react-redux';
|
||||
import {
|
||||
fetchCommenters,
|
||||
fetchAccounts,
|
||||
updateSorting,
|
||||
newPage,
|
||||
} from '../../actions/community';
|
||||
@@ -15,6 +15,8 @@ class CommunityContainer extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
console.log('DEBUG CONSTRUCTOR CommunityContainer ', props);
|
||||
|
||||
this.state = {
|
||||
searchValue: ''
|
||||
};
|
||||
@@ -41,10 +43,10 @@ class CommunityContainer extends Component {
|
||||
search(query = {}) {
|
||||
const {community} = this.props;
|
||||
|
||||
this.props.dispatch(fetchCommenters({
|
||||
this.props.dispatch(fetchAccounts({
|
||||
value: this.state.searchValue,
|
||||
field: community.field,
|
||||
asc: community.asc,
|
||||
field: community.fieldPeople,
|
||||
asc: community.ascPeople,
|
||||
...query
|
||||
}));
|
||||
}
|
||||
@@ -70,19 +72,26 @@ class CommunityContainer extends Component {
|
||||
if (activeTab === 'people') {
|
||||
return (
|
||||
<People
|
||||
isFetching={community.isFetchingPeople}
|
||||
commenters={community.accounts}
|
||||
searchValue={searchValue}
|
||||
commenters={community.commenters}
|
||||
isFetching={community.isFetching}
|
||||
error={community.error}
|
||||
totalPages={community.totalPages}
|
||||
page={community.page}
|
||||
error={community.errorPeople}
|
||||
totalPages={community.totalPagesPeople}
|
||||
page={community.pagePeople}
|
||||
{...this}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<FlaggedAccounts />
|
||||
<FlaggedAccounts
|
||||
commenters={community.flaggedAccounts}
|
||||
isFetching={community.isFetchingFlagged}
|
||||
error={community.errorFlagged}
|
||||
totalPages={community.totalPagesFlagged}
|
||||
page={community.pageFlagged}
|
||||
{...this}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,22 +6,29 @@ const lang = new I18n(translations);
|
||||
|
||||
import styles from './Community.css';
|
||||
|
||||
import Loading from './Loading';
|
||||
// import Loading from './Loading';
|
||||
import EmptyCard from '../../components/EmptyCard';
|
||||
|
||||
const FlaggedAccounts = ({isFetching}) => {
|
||||
const hasResults = false; // !isFetching && !!commenters.length;
|
||||
const FlaggedAccounts = ({...props}) => {
|
||||
const {commenters, isFetching, error, totalPages, page} = props;
|
||||
const hasResults = !isFetching && !!commenters.length;
|
||||
|
||||
console.log('debug props', props);
|
||||
console.log('debug commenters', commenters);
|
||||
console.log('debug error', error);
|
||||
console.log('debug totalPages', totalPages);
|
||||
console.log('debug page', page);
|
||||
|
||||
return (
|
||||
<div className={styles.container}>
|
||||
<div className={styles.mainContent}>
|
||||
{ isFetching && <Loading /> }
|
||||
{
|
||||
hasResults
|
||||
? <div></div>
|
||||
: <EmptyCard>{lang.t('community.no-flagged-accounts')}</EmptyCard>
|
||||
}
|
||||
</div>
|
||||
<div className={styles.mainFlaggedContent}>
|
||||
{ isFetching && <Loading /> }
|
||||
{
|
||||
hasResults
|
||||
? <div></div>
|
||||
: <EmptyCard>{lang.t('community.no-flagged-accounts')}</EmptyCard>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -58,7 +58,7 @@ const People = ({isFetching, commenters, ...props}) => {
|
||||
hasResults
|
||||
? <Table
|
||||
headers={tableHeaders}
|
||||
data={commenters}
|
||||
commenters={commenters}
|
||||
onHeaderClickHandler={props.onHeaderClickHandler}
|
||||
/>
|
||||
: <EmptyCard>{lang.t('community.no-results')}</EmptyCard>
|
||||
|
||||
@@ -77,4 +77,4 @@ class Table extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
export default connect(state => ({commenters: state.community.get('commenters')}))(Table);
|
||||
export default connect(state => ({commenters: state.community.get('accounts')}))(Table);
|
||||
|
||||
@@ -6,58 +6,88 @@ import {
|
||||
FETCH_COMMENTERS_SUCCESS,
|
||||
SORT_UPDATE,
|
||||
SET_ROLE,
|
||||
SET_COMMENTER_STATUS
|
||||
SET_COMMENTER_STATUS,
|
||||
FETCH_FLAGGED_COMMENTERS_REQUEST,
|
||||
FETCH_FLAGGED_COMMENTERS_SUCCESS,
|
||||
FETCH_FLAGGED_COMMENTERS_FAILURE
|
||||
} from '../constants/community';
|
||||
|
||||
const initialState = Map({
|
||||
community: Map(),
|
||||
isFetching: false,
|
||||
error: '',
|
||||
commenters: [],
|
||||
field: 'created_at',
|
||||
asc: false,
|
||||
totalPages: 0,
|
||||
page: 0
|
||||
isFetchingPeople: false,
|
||||
errorPeople: '',
|
||||
accounts: [],
|
||||
fieldPeople: 'created_at',
|
||||
ascPeople: false,
|
||||
totalPagesPeople: 0,
|
||||
pagePeople: 0,
|
||||
isFetchingFlagged: false,
|
||||
errorFlagged: '',
|
||||
flaggedAccounts: [],
|
||||
});
|
||||
|
||||
export default function community (state = initialState, action) {
|
||||
switch (action.type) {
|
||||
case FETCH_COMMENTERS_REQUEST :
|
||||
return state
|
||||
.set('isFetching', true);
|
||||
.set('isFetchingPeople', true);
|
||||
case FETCH_COMMENTERS_FAILURE :
|
||||
return state
|
||||
.set('isFetching', false)
|
||||
.set('error', action.error);
|
||||
.set('isFetchingPeople', false)
|
||||
.set('errorPeople', action.error);
|
||||
|
||||
case FETCH_COMMENTERS_SUCCESS : {
|
||||
const {commenters, type, ...rest} = action; // eslint-disable-line
|
||||
const {accounts, type, page, count, limit, totalPages, ...rest} = action; // eslint-disable-line
|
||||
return state
|
||||
.merge({
|
||||
isFetching: false,
|
||||
error: '',
|
||||
isFetchingPeople: false,
|
||||
errorPeople: '',
|
||||
pagePeople: page,
|
||||
countPeople: count,
|
||||
limitPeople: limit,
|
||||
totalPagesPeople: totalPages,
|
||||
...rest
|
||||
})
|
||||
.set('commenters', commenters); // Sets to normal array
|
||||
.set('accounts', accounts); // Sets to normal array
|
||||
}
|
||||
case SET_ROLE : {
|
||||
const commenters = state.get('commenters');
|
||||
const commenters = state.get('accounts');
|
||||
const idx = commenters.findIndex(el => el.id === action.id);
|
||||
|
||||
commenters[idx].roles[0] = action.role;
|
||||
return state.set('commenters', commenters.map(id => id));
|
||||
return state.set('accounts', commenters.map(id => id));
|
||||
}
|
||||
case SET_COMMENTER_STATUS: {
|
||||
const commenters = state.get('commenters');
|
||||
const commenters = state.get('accounts');
|
||||
const idx = commenters.findIndex(el => el.id === action.id);
|
||||
|
||||
commenters[idx].status = action.status;
|
||||
return state.set('commenters', commenters.map(id => id));
|
||||
return state.set('accounts', commenters.map(id => id));
|
||||
|
||||
}
|
||||
case SORT_UPDATE :
|
||||
return state
|
||||
.set('field', action.sort.field)
|
||||
.set('asc', !state.get('asc'));
|
||||
.set('fieldPeople', action.sort.field)
|
||||
.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 :
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
"loading": "Loading results",
|
||||
"flaggedaccounts": "Account Flags",
|
||||
"people": "People",
|
||||
"no-flagged-accounts": "No flagged accounts in the queue."
|
||||
"no-flagged-accounts": "The Account Flags queue is currently empty."
|
||||
},
|
||||
"modqueue": {
|
||||
"likes": "likes",
|
||||
|
||||
Reference in New Issue
Block a user