Skip to content

Commit

Permalink
increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
hezronkimutai committed Feb 15, 2020
1 parent 31c8a86 commit 321f6d8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 98 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ dist
.DS_Store
coverage/
.vscode/
index.js
80 changes: 0 additions & 80 deletions index.js

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "custom_react_pages",
"version": "1.3.2",
"version": "1.3.3",
"description": "This package makes pagination easier",
"main": "index.js",
"keywords": [
Expand Down
37 changes: 20 additions & 17 deletions src/pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,22 @@ export default ({
}) => {
const [pageNo, setPageNo] = useState(0)

const pages = data ? Paginate(data, itemsPerPage) : []
const pages = data.length && Paginate(data, itemsPerPage)

const allPages = pages.map((item, index) => index)
const allPages = data.length && pages.map((item, index) => index)

const allPageNumbers =
pageNo < Math.round(pageButtons / 2)
data.length &&
(pageNo < Math.round(pageButtons / 2)
? allPages.slice(0, pageButtons)
: allPages.slice(
pageNo - Math.round(pageButtons / 2),
pageNo + Math.round(pageButtons / 2)
)
))
return (
<div className="pagination-container">
{(pages[pageNo] || pages[0]).map((item, index) => onePage(item, index))}
{data.length &&
(pages[pageNo] || pages[0]).map((item, index) => onePage(item, index))}
<div className="pagination-buttons">
<div className="arrows">
<button
Expand All @@ -43,18 +45,19 @@ export default ({
</button>
</div>
<div className="pages">
{allPageNumbers.map((item, index) => (
<div id={index} key={index}>
<button
id='kill'
type="button"
onClick={() => setPageNo(item)}
style={item === pageNo ? activePageStyle : {}}
>
{pageName} {item + 1}
</button>
</div>
))}
{data.length &&
allPageNumbers.map((item, index) => (
<div id={index} key={index}>
<button
id="kill"
type="button"
onClick={() => setPageNo(item)}
style={item === pageNo ? activePageStyle : {}}
>
{pageName} {item + 1}
</button>
</div>
))}
</div>
<div className="arrows">
<button
Expand Down

0 comments on commit 321f6d8

Please sign in to comment.