Improved a bit of the pagination

This commit is contained in:
Tiago Ribeiro
2024-09-07 22:48:52 +01:00
parent b4ab620c78
commit 15cc7c8cc9

View File

@@ -63,13 +63,13 @@ export default function UserList({
const userHash = useMemo( const userHash = useMemo(
() => ({ () => ({
type, type,
size: 25, size: 16,
page, page,
}), }),
[type, page], [type, page],
); );
const {users, total, reload} = useUsers(userHash); const {users, total, isLoading, reload} = useUsers(userHash);
const {permissions} = usePermissions(user?.id || ""); const {permissions} = usePermissions(user?.id || "");
const {balance} = useUserBalance(); const {balance} = useUserBalance();
const {groups} = useGroups({ const {groups} = useGroups({
@@ -625,13 +625,26 @@ export default function UserList({
</Button> </Button>
</div> </div>
<div className="w-full flex gap-2 justify-between"> <div className="w-full flex gap-2 justify-between">
<Button className="w-full max-w-[200px]" disabled={page === 0} onClick={() => setPage((prev) => prev - 1)}> <Button
isLoading={isLoading}
className="w-full max-w-[200px]"
disabled={page === 0}
onClick={() => setPage((prev) => prev - 1)}>
Previous Page Previous Page
</Button> </Button>
<Button className="w-full max-w-[200px]" disabled={page * 25 >= total} onClick={() => setPage((prev) => prev + 1)}> <div className="flex items-center gap-4 w-fit">
<span className="opacity-80">
{page * 16 + 1} - {(page + 1) * 16 > total ? total : (page + 1) * 16} / {total}
</span>
<Button
isLoading={isLoading}
className="w-[200px]"
disabled={page * 16 >= total}
onClick={() => setPage((prev) => prev + 1)}>
Next Page Next Page
</Button> </Button>
</div> </div>
</div>
<table className="rounded-xl bg-mti-purple-ultralight/40 w-full"> <table className="rounded-xl bg-mti-purple-ultralight/40 w-full">
<thead> <thead>
{table.getHeaderGroups().map((headerGroup) => ( {table.getHeaderGroups().map((headerGroup) => (
@@ -644,7 +657,7 @@ export default function UserList({
</tr> </tr>
))} ))}
</thead> </thead>
<tbody className="px-2"> <tbody className="px-2 w-full">
{table.getRowModel().rows.map((row) => ( {table.getRowModel().rows.map((row) => (
<tr className="odd:bg-white even:bg-mti-purple-ultralight/40 rounded-lg py-2" key={row.id}> <tr className="odd:bg-white even:bg-mti-purple-ultralight/40 rounded-lg py-2" key={row.id}>
{row.getVisibleCells().map((cell) => ( {row.getVisibleCells().map((cell) => (