@@ -254,15 +210,15 @@ function TechNews() {
{
projects.length ?
-
-
- {page}
-
-
+ setCurrentPage(Pagination.StartPage(projects, currentPage, itemsPerPage))} />
+ setCurrentPage(Pagination.PrevPage(projects, currentPage, itemsPerPage))} />
+ {currentPage}
+ setCurrentPage(Pagination.NextPage(projects, currentPage, itemsPerPage))} />
+ setCurrentPage(Pagination.LastPage(projects, currentPage, itemsPerPage))} />
: ""
}
-
+
)
diff --git a/src/utils/Pagination.js b/src/utils/Pagination.js
new file mode 100644
index 0000000..a8aa1a5
--- /dev/null
+++ b/src/utils/Pagination.js
@@ -0,0 +1,36 @@
+// next page
+function NextPage(array = [], currentPage = 1, itemsPerPage = 10) {
+ if (currentPage < (Math.ceil(array.length / itemsPerPage)))
+ return currentPage + 1;
+ return currentPage;
+}
+
+
+// go to last page
+function LastPage(array = [], currentPage = 1, itemsPerPage = 10) {
+ return Math.ceil(array.length / itemsPerPage);
+}
+
+
+// previous page
+function PrevPage(array = [], currentPage = 1, itemsPerPage = 10) {
+ if (currentPage > 1)
+ return currentPage - 1;
+ return currentPage;
+}
+
+
+// go to first page
+function StartPage(array = [], currentPage = 1, itemsPerPage = 10) {
+ return 1;
+}
+
+
+// to make pages
+function Paginate(array = [], currentPage = 1, itemsPerPage = 10) {
+ const last_index = currentPage * itemsPerPage;
+ const start_index = last_index - itemsPerPage;
+ return array.slice(start_index, last_index);
+}
+
+export default { Paginate, NextPage, PrevPage, LastPage, StartPage };
\ No newline at end of file