From 974aa090836596c738363acc29dc2442476b739f Mon Sep 17 00:00:00 2001 From: Ian Zhang Date: Mon, 24 Jul 2017 08:30:41 -0700 Subject: [PATCH 1/2] Update if else style Thanks for sharing great pagination example. Hopefully, this modification will make code blocks aligned. --- src/components/Pagination.jsx | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/components/Pagination.jsx b/src/components/Pagination.jsx index 5962087..999a725 100644 --- a/src/components/Pagination.jsx +++ b/src/components/Pagination.jsx @@ -66,18 +66,16 @@ class Pagination extends React.Component { // less than 10 total pages so show all startPage = 1; endPage = totalPages; - } else { // more than 10 total pages so calculate start and end pages - if (currentPage <= 6) { - startPage = 1; - endPage = 10; - } else if (currentPage + 4 >= totalPages) { - startPage = totalPages - 9; - endPage = totalPages; - } else { - startPage = currentPage - 5; - endPage = currentPage + 4; - } + } else if (currentPage <= 6) { + startPage = 1; + endPage = 10; + } else if (currentPage + 4 >= totalPages) { + startPage = totalPages - 9; + endPage = totalPages; + } else { + startPage = currentPage - 5; + endPage = currentPage + 4; } // calculate start and end item indexes @@ -135,4 +133,4 @@ class Pagination extends React.Component { Pagination.propTypes = propTypes; Pagination.defaultProps -export default Pagination; \ No newline at end of file +export default Pagination; From 7a1bd628bd85f5997aad135641a6a14360260515 Mon Sep 17 00:00:00 2001 From: Ian Zhang Date: Mon, 24 Jul 2017 08:31:54 -0700 Subject: [PATCH 2/2] Fix indentation --- src/components/Pagination.jsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/Pagination.jsx b/src/components/Pagination.jsx index 999a725..1c32791 100644 --- a/src/components/Pagination.jsx +++ b/src/components/Pagination.jsx @@ -71,11 +71,11 @@ class Pagination extends React.Component { startPage = 1; endPage = 10; } else if (currentPage + 4 >= totalPages) { - startPage = totalPages - 9; - endPage = totalPages; + startPage = totalPages - 9; + endPage = totalPages; } else { - startPage = currentPage - 5; - endPage = currentPage + 4; + startPage = currentPage - 5; + endPage = currentPage + 4; } // calculate start and end item indexes