Skip to content

Commit

Permalink
Fix pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
u4aew committed Sep 2, 2024
1 parent 9e0fbed commit 4f5f999
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
8 changes: 1 addition & 7 deletions components/StocksList/Pagination/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@ export const Pagination = ({
const calculateEnd = (page: number) => page * itemsPerPage;

const isActivePage = (page: number) => {
const pageStart = calculateStart(page);
const pageEnd = calculateEnd(page);
return (
(currentStart >= pageStart && currentStart < pageEnd) ||
(currentEnd > pageStart && currentEnd <= pageEnd) ||
(currentStart <= pageStart && currentEnd >= pageEnd)
);
return page === currentEnd / itemsPerPage;
};

return (
Expand Down
6 changes: 3 additions & 3 deletions components/StocksList/StocksList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import styles from './shares.module.scss';
import { serviceStocks } from '@/services';
import { Pagination } from '@/components/StocksList/Pagination';

const ITEMS_PER_PAGE = 25;
const ITEMS_PER_PAGE = 24;

export const StocksList = async ({
searchParams,
Expand All @@ -15,7 +15,7 @@ export const StocksList = async ({

const responseShares = await serviceStocks.getList({ start, end });

const currentPage = Math.floor(start / ITEMS_PER_PAGE) + 1;
const currentPage = Math.floor(end / ITEMS_PER_PAGE);
// @ts-ignore
const totalPages = Math.ceil(responseShares.total / ITEMS_PER_PAGE);

Expand All @@ -32,7 +32,7 @@ export const StocksList = async ({
<Pagination
currentPage={currentPage}
totalPages={totalPages}
itemsPerPage={25}
itemsPerPage={ITEMS_PER_PAGE}
currentStart={start}
currentEnd={end}
/>
Expand Down
2 changes: 1 addition & 1 deletion services/stocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { IPagination } from '@/typing';
class ServiceStocks {
constructor() {}

async getList({ start = 1, end = 10 }: IPagination) {
async getList({ start = 1, end = 24 }: IPagination) {
try {
const res = await getStocks({ start, end });
return res;
Expand Down

0 comments on commit 4f5f999

Please sign in to comment.