Skip to content

Commit

Permalink
Allow user to show pagination somewhere else
Browse files Browse the repository at this point in the history
  • Loading branch information
amir-hadzic committed Oct 26, 2017
1 parent f6ff8fa commit 01e768b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/PaginationContainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react';
import { connect } from 'react-redux';
import makeSelectors from './selectors';
import { tablePageChanged } from './actions';
import Pagination from './Pagination';

const mapStateToProps = (state, { tableName }) => {
const selectors = makeSelectors(tableName);
const isInitialized = selectors.getIsInitialized(state);

if (!isInitialized) {
return {
isInitialized,
};
}

const pageInfo = selectors.getPageInfo(state);

return {
isInitialized,
...pageInfo,
};
};

const mapDispatchToProps = (dispatch, { tableName }) => ({
onPageChange: (page) => dispatch(tablePageChanged(tableName, page)),
});

export default connect(mapStateToProps, mapDispatchToProps)(({
isInitialized,
...otherProps
}) => {
if (!isInitialized) { return null; }
return <Pagination {...otherProps} />;
});
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import TableRow from './TableRow.js';
import Table from './Table.js';
import FilterContainer from './FilterContainer.js';
import PageSizeContainer from './PageSizeContainer.js';
import PaginationContainer from './PaginationContainer.js';
import makeSelectors from './selectors.js';
import reducer from './reducer.js';
import { tableDestroyState, tableSetFilter } from './actions.js';
Expand All @@ -18,6 +19,7 @@ export {
TableRow,
FilterContainer,
PageSizeContainer,
PaginationContainer,
makeSelectors,
tableDestroyState,
tableSetFilter,
Expand Down

0 comments on commit 01e768b

Please sign in to comment.