Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add pagination to protocol history table #205

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Skeleton, useBreakpointValue } from '@chakra-ui/react';
import { useState } from 'react';

import { Button, HStack, Skeleton, Spacer, VStack, useBreakpointValue } from '@chakra-ui/react';

Check warning on line 3 in src/app/components/protocol-history-table/protocol-history-table.tsx

View workflow job for this annotation

GitHub Actions / lint-eslint

'Button' is defined but never used

Check warning on line 3 in src/app/components/protocol-history-table/protocol-history-table.tsx

View workflow job for this annotation

GitHub Actions / lint-eslint

'HStack' is defined but never used

Check warning on line 3 in src/app/components/protocol-history-table/protocol-history-table.tsx

View workflow job for this annotation

GitHub Actions / lint-eslint

'Spacer' is defined but never used

Check warning on line 3 in src/app/components/protocol-history-table/protocol-history-table.tsx

View workflow job for this annotation

GitHub Actions / lint-eslint

'VStack' is defined but never used

Check failure on line 3 in src/app/components/protocol-history-table/protocol-history-table.tsx

View workflow job for this annotation

GitHub Actions / typecheck

'Button' is declared but its value is never read.

Check failure on line 3 in src/app/components/protocol-history-table/protocol-history-table.tsx

View workflow job for this annotation

GitHub Actions / typecheck

'HStack' is declared but its value is never read.

Check failure on line 3 in src/app/components/protocol-history-table/protocol-history-table.tsx

View workflow job for this annotation

GitHub Actions / typecheck

'Spacer' is declared but its value is never read.

Check failure on line 3 in src/app/components/protocol-history-table/protocol-history-table.tsx

View workflow job for this annotation

GitHub Actions / typecheck

'VStack' is declared but its value is never read.
import { GenericTableBody } from '@components/generic-table/components/generic-table-body';
import { GenericTableHeader } from '@components/generic-table/components/generic-table-header';
import { GenericTableHeaderText } from '@components/generic-table/components/generic-table-header-text';
Expand All @@ -10,11 +12,24 @@
}

export function ProtocolHistoryTable({ items }: ProtocolHistoryTableProps): React.JSX.Element {
const dynamicHeight = items ? items.length * 59 + 20 : 20;
const [currentPage, setCurrentPage] = useState(1);
const itemsPerPage = 10;
const isMobile = useBreakpointValue({ base: true, md: false });

const totalPages = Math.ceil((items?.length || 0) / itemsPerPage);

const currentItems = items?.slice((currentPage - 1) * itemsPerPage, currentPage * itemsPerPage);

Check warning on line 21 in src/app/components/protocol-history-table/protocol-history-table.tsx

View workflow job for this annotation

GitHub Actions / lint-eslint

'currentItems' is assigned a value but never used

Check failure on line 21 in src/app/components/protocol-history-table/protocol-history-table.tsx

View workflow job for this annotation

GitHub Actions / typecheck

'currentItems' is declared but its value is never read.

const handlePageChange = (direction: number) => {

Check warning on line 23 in src/app/components/protocol-history-table/protocol-history-table.tsx

View workflow job for this annotation

GitHub Actions / lint-eslint

'handlePageChange' is assigned a value but never used

Check failure on line 23 in src/app/components/protocol-history-table/protocol-history-table.tsx

View workflow job for this annotation

GitHub Actions / typecheck

'handlePageChange' is declared but its value is never read.
setCurrentPage(prevPage => {
const newPage = prevPage + direction;
if (newPage < 1 || newPage > totalPages) return prevPage;
return newPage;
});
};

return (
<GenericTableLayout height={`${dynamicHeight}px`} width={'70%'} isMobile={isMobile}>

Check failure on line 32 in src/app/components/protocol-history-table/protocol-history-table.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Cannot find name 'dynamicHeight'.
<GenericTableHeader>
{isMobile ? (
<>
Expand Down
Loading