Paginate no actualizaba sus props

This commit is contained in:
Daniel Cortes
2020-06-03 20:10:31 -04:00
parent a96d67d54e
commit d321616764

View File

@@ -22,22 +22,27 @@ const range = (from, to, step = 1) => {
export default class Paginate extends Component { export default class Paginate extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
const {totalRecords = 0, pageLimit = 30, pageNeighbours = 0, currentPage = 1} = props;
this.pageLimit = typeof pageLimit === 'number' ? pageLimit : 30;
this.totalRecords = typeof totalRecords === 'number' ? totalRecords : 0;
this.pageNeighbours = typeof pageNeighbours === 'number' ? Math.max(0, Math.min(pageNeighbours, 2)) : 0;
this.totalPages = Math.ceil(this.totalRecords / this.pageLimit);
this.currentPage = typeof currentPage === 'number' ? currentPage : 1
this.state = {currentPage: this.currentPage};
this.loadProps = this.loadProps.bind(this);
this.gotoPage = this.gotoPage.bind(this); this.gotoPage = this.gotoPage.bind(this);
this.handleClick = this.handleClick.bind(this); this.handleClick = this.handleClick.bind(this);
this.handleMoveLeft = this.handleMoveLeft.bind(this); this.handleMoveLeft = this.handleMoveLeft.bind(this);
this.handleMoveRight = this.handleMoveRight.bind(this); this.handleMoveRight = this.handleMoveRight.bind(this);
this.makePageLink = this.makePageLink.bind(this); this.makePageLink = this.makePageLink.bind(this);
this.fetchPageNumbers = this.fetchPageNumbers.bind(this); this.fetchPageNumbers = this.fetchPageNumbers.bind(this);
this.loadProps();
this.state = {currentPage: this.currentPage};
}
loadProps() {
const {totalRecords = 0, pageLimit = 30, pageNeighbours = 0, currentPage = 1} = this.props;
this.pageLimit = typeof pageLimit === 'number' ? pageLimit : 30;
this.totalRecords = typeof totalRecords === 'number' ? totalRecords : 0;
this.pageNeighbours = typeof pageNeighbours === 'number' ? Math.max(0, Math.min(pageNeighbours, 2)) : 0;
this.totalPages = Math.ceil(this.totalRecords / this.pageLimit);
this.currentPage = typeof currentPage === 'number' ? currentPage : 1
} }
gotoPage(page) { gotoPage(page) {
@@ -80,6 +85,8 @@ export default class Paginate extends Component {
* {...x} => represents page neighbours * {...x} => represents page neighbours
*/ */
fetchPageNumbers() { fetchPageNumbers() {
this.loadProps();
const totalPages = this.totalPages; const totalPages = this.totalPages;
const currentPage = this.state.currentPage; const currentPage = this.state.currentPage;
const pageNeighbours = this.pageNeighbours; const pageNeighbours = this.pageNeighbours;