Add pagination controls to UserManagement

Uses the shared Pagination component instead of rendering every
fetched user in one unpaginated list.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Gabriel20xxandClaude Sonnet 5 committed 2026-09-11 23:25:25 +02:00
1 parent 097442f4b0
commit 965910eecc
1 file changed
+19 -1
@@ -11,6 +11,7 @@
UserUpdateRequest
} from '../types';
import Button from './Button.svelte';
import Pagination from './Pagination.svelte';
let {
currentRole = 'user',
@@ -37,9 +38,16 @@
let newUser = $state<UserCreateInput>({ username: '', email: '', password: '', role: 'user' });
let editingId = $state<UserId | null>(null);
let editUser = $state<UserUpdateInput>({});
let page = $state(1);
let pageSize = $state(24);
const canManage = $derived(currentRole === 'admin' || currentRole === 'superadmin');
const canAssignAdmin = $derived(currentRole === 'superadmin');
const pageCount = $derived(Math.max(1, Math.ceil(users.length / pageSize)));
const currentPage = $derived(Math.min(page, pageCount));
const pagedUsers = $derived(
users.slice((currentPage - 1) * pageSize, (currentPage - 1) * pageSize + pageSize)
);
function roleForForm(role: UserRole | undefined): UserRole {
return canAssignAdmin && role ? role : 'user';
@@ -176,7 +184,7 @@
<p class="sc-muted">No users found.</p>
{:else}
<div class="sc-user-list">
{#each users as user (user.id)}
{#each pagedUsers as user (user.id)}
{#if String(editingId) === String(user.id)}
<form class="sc-user-row sc-user-edit-row" onsubmit={updateUser}>
<input aria-label="Username" class="sc-input" required type="text" bind:value={editUser.username} />
@@ -202,6 +210,16 @@
{/if}
{/each}
</div>
<Pagination
page={currentPage}
{pageSize}
pageLength={pagedUsers.length}
totalLength={users.length}
onPaging={(change) => {
page = change.page;
pageSize = change.pageSize;
}}
/>
{/if}
</section>
{/if}