Skip to content

Commit

Permalink
fix: Hide pagination if not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
richiemcilroy committed Jul 7, 2024
1 parent 84d03be commit 22e1e01
Showing 1 changed file with 53 additions and 52 deletions.
105 changes: 53 additions & 52 deletions apps/web/app/dashboard/caps/Caps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export const Caps = ({ data, count }: { data: videoData; count: number }) => {
const { refresh } = useRouter();
const params = useSearchParams();
const page = Number(params.get("page")) || 1;
console.log("page: ", page);
const [analytics, setAnalytics] = useState<Record<string, number>>({});
const { user } = useSharedContext();
const limit = 15;
Expand Down Expand Up @@ -364,69 +363,71 @@ export const Caps = ({ data, count }: { data: videoData; count: number }) => {
);
})}
</div>
<div>
<Pagination>
<PaginationContent>
{page > 1 && (
<PaginationItem>
<PaginationPrevious
href={
process.env.NEXT_PUBLIC_URL +
`/dashboard/caps?page=${page === 1 ? page : page - 1}`
}
/>
</PaginationItem>
)}
<PaginationItem>
<PaginationLink
href={
process.env.NEXT_PUBLIC_URL + `/dashboard/caps?page=1`
}
isActive={page === 1}
>
1
</PaginationLink>
</PaginationItem>
{page !== 1 && (
{(data.length > limit || data.length === limit || page !== 1) && (
<div>
<Pagination>
<PaginationContent>
{page > 1 && (
<PaginationItem>
<PaginationPrevious
href={
process.env.NEXT_PUBLIC_URL +
`/dashboard/caps?page=${page === 1 ? page : page - 1}`
}
/>
</PaginationItem>
)}
<PaginationItem>
<PaginationLink
href={
process.env.NEXT_PUBLIC_URL +
`/dashboard/caps?page=${page}`
process.env.NEXT_PUBLIC_URL + `/dashboard/caps?page=1`
}
isActive={true}
isActive={page === 1}
>
{page}
1
</PaginationLink>
</PaginationItem>
)}
{totalPages > page + 1 && (
{page !== 1 && (
<PaginationItem>
<PaginationLink
href={
process.env.NEXT_PUBLIC_URL +
`/dashboard/caps?page=${page}`
}
isActive={true}
>
{page}
</PaginationLink>
</PaginationItem>
)}
{totalPages > page + 1 && (
<PaginationItem>
<PaginationLink
href={
process.env.NEXT_PUBLIC_URL +
`/dashboard/caps?page=${page + 1}`
}
isActive={page === page + 1}
>
{page + 1}
</PaginationLink>
</PaginationItem>
)}
{page > 2 && <PaginationEllipsis />}
<PaginationItem>
<PaginationLink
<PaginationNext
href={
process.env.NEXT_PUBLIC_URL +
`/dashboard/caps?page=${page + 1}`
`/dashboard/caps?page=${
page === totalPages ? page : page + 1
}`
}
isActive={page === page + 1}
>
{page + 1}
</PaginationLink>
/>
</PaginationItem>
)}
{page > 2 && <PaginationEllipsis />}
<PaginationItem>
<PaginationNext
href={
process.env.NEXT_PUBLIC_URL +
`/dashboard/caps?page=${
page === totalPages ? page : page + 1
}`
}
/>
</PaginationItem>
</PaginationContent>
</Pagination>
</div>
</PaginationContent>
</Pagination>
</div>
)}
</div>
)}
</div>
Expand Down

1 comment on commit 22e1e01

@vercel
Copy link

@vercel vercel bot commented on 22e1e01 Jul 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.