-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
packages/app/app/studio/[organization]/library/components/Pagination.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
'use client'; | ||
import { IPagination } from '@/lib/types'; | ||
import useSearchParams from '@/lib/hooks/useSearchParams'; | ||
import { Input } from '@/components/ui/input'; | ||
import { Button } from '@/components/ui/button'; | ||
import React, { useState } from 'react'; | ||
import { LuArrowLeft, LuArrowRight } from 'react-icons/lu'; | ||
|
||
const Pagination = (props: IPagination) => { | ||
const [jumpPage, setJumpPage] = useState(props.currentPage); | ||
const { handleTermChange, searchParams } = useSearchParams(); | ||
const currentPage = Number(searchParams.get('page')) || 1; | ||
|
||
return ( | ||
<div className="flex flex-row items-center justify-center p-2"> | ||
<div className="flex items-center gap-3"> | ||
<p>Jump to</p> | ||
<Input | ||
type="number" | ||
min={1} | ||
max={props.totalPages} | ||
onChange={(e) => setJumpPage(Number(e.target.value))} | ||
value={jumpPage} | ||
className="w-14 text-center" | ||
/> | ||
<Button | ||
disabled={ | ||
!jumpPage || | ||
jumpPage < 1 || | ||
jumpPage > props.totalPages || | ||
props.totalPages === currentPage || | ||
jumpPage == currentPage | ||
} | ||
onClick={() => | ||
jumpPage && | ||
handleTermChange([ | ||
{ | ||
key: 'page', | ||
value: jumpPage.toString(), | ||
}, | ||
]) | ||
} | ||
variant="primary" | ||
> | ||
Go | ||
</Button> | ||
</div> | ||
<div className="flex flex-row items-center justify-center"> | ||
<button | ||
className="rounded-full p-2 active:hover:bg-gray-100 disabled:text-gray-200" | ||
disabled={props.currentPage === 1} | ||
onClick={() => { | ||
if (currentPage > 1) { | ||
handleTermChange([ | ||
{ | ||
key: 'page', | ||
value: (currentPage - 1).toString(), | ||
}, | ||
]); | ||
} | ||
}} | ||
> | ||
<LuArrowLeft size={24} /> | ||
</button> | ||
<div className="mx-2"> | ||
{currentPage} of {props.totalPages} | ||
</div> | ||
<button | ||
className="rounded-full p-2 active:hover:bg-gray-100 disabled:text-gray-200" | ||
disabled={props.totalPages === currentPage} | ||
onClick={() => { | ||
if (currentPage < props.totalPages) { | ||
handleTermChange([ | ||
{ key: 'page', value: (currentPage + 1).toString() }, | ||
]); | ||
} | ||
}} | ||
> | ||
<LuArrowRight size={24} /> | ||
</button> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Pagination; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters