This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
//Styles | |
import { UsersPageContainer } from './styles'; | |
//Components | |
import UserTable from '../UserTable/UserTable'; | |
const UsersPage = () => { | |
return ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, useEffect } from 'react'; | |
//Styles | |
import { | |
UserTableContainer, | |
UserCardContainer, | |
UserTableHeader, | |
Age, | |
Name, | |
Email, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pageNumberRender = () => { | |
const { totalPages, currentClickedNumber } = this.state; | |
let pages = []; | |
for (let i = 1; i < totalPages + 1; i++) { | |
pages.push( | |
<PageNumber | |
onClick={(e) => { | |
this.setCurrentClickedNumber(e); | |
}} | |
isClicked={currentClickedNumber === i ? true : false} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
componentDidMount() { | |
this.determineNumberOfPages(); | |
} | |
componentDidUpdate(prevProps, prevState) { | |
const { data, setData } = this.props; | |
const { currentClickedNumber, pageData } = this.state; | |
if (data !== prevProps.data) { | |
this.determineNumberOfPages(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
moveOnePageForward = () => { | |
const { dataStartingIndex, totalPages, currentClickedNumber } = this.state; | |
if (dataStartingIndex) { | |
this.setState({ | |
dataStartingIndex: null, | |
currentClickedNumber: 2 | |
}); | |
} else { | |
this.setState({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setCurrentClickedNumber = e => { | |
const { target } = e; | |
this.setState({ | |
currentClickedNumber: parseInt(target.innerText) | |
}); | |
}; | |
moveToLastPage = () => { | |
this.setState({ | |
currentClickedNumber: this.state.totalPages, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.setState({ | |
totalPages: chunkArray.length, | |
dataStartingIndex: itemsPerPage, | |
pageData: paginatedDataObject, | |
clickedOnNumber: 1 | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
determineNumberOfPages = () => { | |
const { data, itemsPerPage } = this.props; | |
let paginatedDataObject = {}; | |
let index = 0; | |
let dataLength = data.length; | |
let chunkArray = []; | |
for (index = 0; index < dataLength; index += itemsPerPage) { | |
let newChunk = data.slice(index, index + itemsPerPage); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Paginate | |
data={data} | |
setData={setDataFunction} | |
itemsPerPage={usersPerPage} | |
/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
constructor(props) { | |
super(props); | |
this.state = { | |
totalPages: null, | |
dataStartingIndex: null, | |
dataLastIndex: 0, | |
currentClickedNumber: 1, | |
pageData: null | |
}; |
NewerOlder