You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
156 lines
4.0 KiB
156 lines
4.0 KiB
7 years ago
|
import PropTypes from 'prop-types';
|
||
|
import React, { Component } from 'react';
|
||
|
import { connect } from 'react-redux';
|
||
|
import { createSelector } from 'reselect';
|
||
4 years ago
|
import * as commandNames from 'Commands/commandNames';
|
||
6 years ago
|
import withCurrentPage from 'Components/withCurrentPage';
|
||
3 years ago
|
import * as blocklistActions from 'Store/Actions/blocklistActions';
|
||
7 years ago
|
import { executeCommand } from 'Store/Actions/commandActions';
|
||
4 years ago
|
import createCommandExecutingSelector from 'Store/Selectors/createCommandExecutingSelector';
|
||
|
import { registerPagePopulator, unregisterPagePopulator } from 'Utilities/pagePopulator';
|
||
3 years ago
|
import Blocklist from './Blocklist';
|
||
7 years ago
|
|
||
|
function createMapStateToProps() {
|
||
|
return createSelector(
|
||
3 years ago
|
(state) => state.blocklist,
|
||
4 years ago
|
(state) => state.authors,
|
||
3 years ago
|
createCommandExecutingSelector(commandNames.CLEAR_BLOCKLIST),
|
||
|
(blocklist, authors, isClearingBlocklistExecuting) => {
|
||
7 years ago
|
return {
|
||
4 years ago
|
isAuthorFetching: authors.isFetching,
|
||
|
isAuthorPopulated: authors.isPopulated,
|
||
3 years ago
|
isClearingBlocklistExecuting,
|
||
|
...blocklist
|
||
7 years ago
|
};
|
||
|
}
|
||
|
);
|
||
|
}
|
||
|
|
||
|
const mapDispatchToProps = {
|
||
3 years ago
|
...blocklistActions,
|
||
7 years ago
|
executeCommand
|
||
|
};
|
||
|
|
||
3 years ago
|
class BlocklistConnector extends Component {
|
||
7 years ago
|
|
||
|
//
|
||
|
// Lifecycle
|
||
|
|
||
|
componentDidMount() {
|
||
6 years ago
|
const {
|
||
|
useCurrentPage,
|
||
3 years ago
|
fetchBlocklist,
|
||
|
gotoBlocklistFirstPage
|
||
6 years ago
|
} = this.props;
|
||
|
|
||
7 years ago
|
registerPagePopulator(this.repopulate);
|
||
6 years ago
|
|
||
|
if (useCurrentPage) {
|
||
3 years ago
|
fetchBlocklist();
|
||
6 years ago
|
} else {
|
||
3 years ago
|
gotoBlocklistFirstPage();
|
||
6 years ago
|
}
|
||
7 years ago
|
}
|
||
|
|
||
|
componentDidUpdate(prevProps) {
|
||
3 years ago
|
if (prevProps.isClearingBlocklistExecuting && !this.props.isClearingBlocklistExecuting) {
|
||
|
this.props.gotoBlocklistFirstPage();
|
||
7 years ago
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
componentWillUnmount() {
|
||
3 years ago
|
this.props.clearBlocklist();
|
||
7 years ago
|
unregisterPagePopulator(this.repopulate);
|
||
|
}
|
||
|
|
||
|
//
|
||
|
// Control
|
||
|
|
||
|
repopulate = () => {
|
||
3 years ago
|
this.props.fetchBlocklist();
|
||
7 years ago
|
}
|
||
7 years ago
|
//
|
||
|
// Listeners
|
||
|
|
||
|
onFirstPagePress = () => {
|
||
3 years ago
|
this.props.gotoBlocklistFirstPage();
|
||
7 years ago
|
}
|
||
|
|
||
|
onPreviousPagePress = () => {
|
||
3 years ago
|
this.props.gotoBlocklistPreviousPage();
|
||
7 years ago
|
}
|
||
|
|
||
|
onNextPagePress = () => {
|
||
3 years ago
|
this.props.gotoBlocklistNextPage();
|
||
7 years ago
|
}
|
||
|
|
||
|
onLastPagePress = () => {
|
||
3 years ago
|
this.props.gotoBlocklistLastPage();
|
||
7 years ago
|
}
|
||
|
|
||
|
onPageSelect = (page) => {
|
||
3 years ago
|
this.props.gotoBlocklistPage({ page });
|
||
7 years ago
|
}
|
||
|
|
||
4 years ago
|
onRemoveSelected = (ids) => {
|
||
3 years ago
|
this.props.removeBlocklistItems({ ids });
|
||
4 years ago
|
}
|
||
|
|
||
7 years ago
|
onSortPress = (sortKey) => {
|
||
3 years ago
|
this.props.setBlocklistSort({ sortKey });
|
||
7 years ago
|
}
|
||
|
|
||
|
onTableOptionChange = (payload) => {
|
||
3 years ago
|
this.props.setBlocklistTableOption(payload);
|
||
7 years ago
|
|
||
|
if (payload.pageSize) {
|
||
3 years ago
|
this.props.gotoBlocklistFirstPage();
|
||
7 years ago
|
}
|
||
|
}
|
||
|
|
||
3 years ago
|
onClearBlocklistPress = () => {
|
||
|
this.props.executeCommand({ name: commandNames.CLEAR_BLOCKLIST });
|
||
7 years ago
|
}
|
||
|
|
||
|
//
|
||
|
// Render
|
||
|
|
||
|
render() {
|
||
|
return (
|
||
3 years ago
|
<Blocklist
|
||
7 years ago
|
onFirstPagePress={this.onFirstPagePress}
|
||
|
onPreviousPagePress={this.onPreviousPagePress}
|
||
|
onNextPagePress={this.onNextPagePress}
|
||
|
onLastPagePress={this.onLastPagePress}
|
||
|
onPageSelect={this.onPageSelect}
|
||
4 years ago
|
onRemoveSelected={this.onRemoveSelected}
|
||
7 years ago
|
onSortPress={this.onSortPress}
|
||
|
onTableOptionChange={this.onTableOptionChange}
|
||
3 years ago
|
onClearBlocklistPress={this.onClearBlocklistPress}
|
||
7 years ago
|
{...this.props}
|
||
|
/>
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
3 years ago
|
BlocklistConnector.propTypes = {
|
||
6 years ago
|
useCurrentPage: PropTypes.bool.isRequired,
|
||
3 years ago
|
isClearingBlocklistExecuting: PropTypes.bool.isRequired,
|
||
7 years ago
|
items: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||
3 years ago
|
fetchBlocklist: PropTypes.func.isRequired,
|
||
|
gotoBlocklistFirstPage: PropTypes.func.isRequired,
|
||
|
gotoBlocklistPreviousPage: PropTypes.func.isRequired,
|
||
|
gotoBlocklistNextPage: PropTypes.func.isRequired,
|
||
|
gotoBlocklistLastPage: PropTypes.func.isRequired,
|
||
|
gotoBlocklistPage: PropTypes.func.isRequired,
|
||
|
removeBlocklistItems: PropTypes.func.isRequired,
|
||
|
setBlocklistSort: PropTypes.func.isRequired,
|
||
|
setBlocklistTableOption: PropTypes.func.isRequired,
|
||
|
clearBlocklist: PropTypes.func.isRequired,
|
||
7 years ago
|
executeCommand: PropTypes.func.isRequired
|
||
|
};
|
||
|
|
||
6 years ago
|
export default withCurrentPage(
|
||
3 years ago
|
connect(createMapStateToProps, mapDispatchToProps)(BlocklistConnector)
|
||
6 years ago
|
);
|