kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Store admin log in reducer
rodzic
4fa7f63d05
commit
c6b7a7ca8a
|
@ -1,41 +1,49 @@
|
|||
import React from 'react';
|
||||
import { defineMessages, injectIntl } from 'react-intl';
|
||||
import { connect } from 'react-redux';
|
||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||||
import PropTypes from 'prop-types';
|
||||
import Column from '../ui/components/column';
|
||||
import ScrollableList from 'soapbox/components/scrollable_list';
|
||||
import { fetchModerationLog } from 'soapbox/actions/admin';
|
||||
import { List as ImmutableList, fromJS } from 'immutable';
|
||||
|
||||
const messages = defineMessages({
|
||||
heading: { id: 'column.admin.moderation_log', defaultMessage: 'Moderation Log' },
|
||||
emptyMessage: { id: 'admin.moderation_log.empty_message', defaultMessage: 'You have not performed any moderation actions yet. When you do, a history will be shown here.' },
|
||||
});
|
||||
|
||||
export default @connect()
|
||||
const mapStateToProps = state => ({
|
||||
items: state.getIn(['admin_log', 'index']).map(i => state.getIn(['admin_log', 'items', String(i)])),
|
||||
});
|
||||
|
||||
export default @connect(mapStateToProps)
|
||||
@injectIntl
|
||||
class ModerationLog extends ImmutablePureComponent {
|
||||
|
||||
static propTypes = {
|
||||
intl: PropTypes.object.isRequired,
|
||||
list: ImmutablePropTypes.list,
|
||||
};
|
||||
|
||||
state = {
|
||||
isLoading: true,
|
||||
items: ImmutableList(),
|
||||
lastPage: 0,
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
const { dispatch } = this.props;
|
||||
dispatch(fetchModerationLog())
|
||||
.then(data => this.setState({ isLoading: false, items: fromJS(data.items) }))
|
||||
.then(data => this.setState({
|
||||
isLoading: false,
|
||||
lastPage: 1,
|
||||
}))
|
||||
.catch(() => {});
|
||||
}
|
||||
|
||||
render() {
|
||||
const { intl } = this.props;
|
||||
const { isLoading, items } = this.state;
|
||||
const { intl, items } = this.props;
|
||||
const { isLoading } = this.state;
|
||||
const showLoading = isLoading && items.count() === 0;
|
||||
|
||||
return (
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
import { ADMIN_LOG_FETCH_SUCCESS } from 'soapbox/actions/admin';
|
||||
import {
|
||||
Map as ImmutableMap,
|
||||
OrderedSet as ImmutableOrderedSet,
|
||||
fromJS,
|
||||
} from 'immutable';
|
||||
|
||||
const initialState = ImmutableMap({
|
||||
items: ImmutableMap(),
|
||||
index: ImmutableOrderedSet(),
|
||||
total: 0,
|
||||
});
|
||||
|
||||
const parseItems = items => {
|
||||
let ids = [];
|
||||
let map = {};
|
||||
|
||||
items.forEach(item => {
|
||||
ids.push(item.id);
|
||||
map[item.id] = item;
|
||||
});
|
||||
|
||||
return { ids: ids, map: map };
|
||||
};
|
||||
|
||||
const importItems = (state, items, total) => {
|
||||
const { ids, map } = parseItems(items);
|
||||
|
||||
return state.withMutations(state => {
|
||||
state.update('index', v => v.union(ids));
|
||||
state.update('items', v => v.merge(fromJS(map)));
|
||||
state.set('total', total);
|
||||
});
|
||||
};
|
||||
|
||||
export default function admin_log(state = initialState, action) {
|
||||
switch(action.type) {
|
||||
case ADMIN_LOG_FETCH_SUCCESS:
|
||||
return importItems(state, action.items, action.total);
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
|
@ -50,6 +50,7 @@ import chat_messages from './chat_messages';
|
|||
import chat_message_lists from './chat_message_lists';
|
||||
import profile_hover_card from './profile_hover_card';
|
||||
import backups from './backups';
|
||||
import admin_log from './admin_log';
|
||||
|
||||
const appReducer = combineReducers({
|
||||
dropdown_menu,
|
||||
|
@ -101,6 +102,7 @@ const appReducer = combineReducers({
|
|||
chat_message_lists,
|
||||
profile_hover_card,
|
||||
backups,
|
||||
admin_log,
|
||||
});
|
||||
|
||||
// Clear the state (mostly) when the user logs out
|
||||
|
|
Ładowanie…
Reference in New Issue