- );
- } else {
+ renderPaginationControls: function () {
+ if (!this.state.totalBrews) {
return null;
}
+
+ const size = parseInt(this.state.pageSize);
+ const { page, totalBrews } = this.state;
+ const totalPages = Math.ceil(totalBrews / size);
+
+ let startPage, endPage;
+ if (page <= 6) {
+ startPage = 1;
+ endPage = Math.min(totalPages, 10);
+ } else if (page + 4 >= totalPages) {
+ startPage = Math.max(1, totalPages - 9);
+ endPage = totalPages;
+ } else {
+ startPage = page - 5;
+ endPage = page + 4;
+ }
+
+ const pagesAroundCurrent = new Array(endPage - startPage + 1)
+ .fill()
+ .map((_, index) => (
+