From fba46a5a42c30d5187aa7d75c3b8ed63802aaba0 Mon Sep 17 00:00:00 2001 From: busya Date: Wed, 17 Jun 2026 15:22:39 +0300 Subject: [PATCH] refactor(frontend): migrate remaining pagination to Pagination component (4 files) Replaced hand-rolled prev/next buttons and 'Showing X-Y of Z' with from $lib/ui: - translate/+page, translate/history, validation-tasks/history, validation-tasks/[policyId] Fixed latent bug in validation-tasks/history where prev/next always called page=1 instead of the actual page number. --- frontend/src/routes/translate/+page.svelte | 25 ++++++++- .../src/routes/translate/history/+page.svelte | 33 ++++++++---- .../validation-tasks/[policyId]/+page.svelte | 52 ++++++++----------- .../validation-tasks/history/+page.svelte | 50 +++++++++--------- 4 files changed, 92 insertions(+), 68 deletions(-) diff --git a/frontend/src/routes/translate/+page.svelte b/frontend/src/routes/translate/+page.svelte index 847d6c76..e7bcc70b 100644 --- a/frontend/src/routes/translate/+page.svelte +++ b/frontend/src/routes/translate/+page.svelte @@ -6,7 +6,7 @@ import { ROUTES } from '$lib/routes'; import { t, _ } from '$lib/i18n/index.svelte.js'; import { addToast } from '$lib/toasts.svelte.js'; - import { Badge, Button, EmptyState } from '$lib/ui'; + import { Badge, Button, EmptyState, Pagination } from '$lib/ui'; import { fetchJobs, deleteJob, duplicateJob } from '$lib/api/translate.js'; /** @type {string} idle | loading | empty | populated | error */ @@ -18,6 +18,7 @@ let statusFilter = $state(''); let currentPage = $state(1); let pageSize = $state(20); + let total = $state(0); // Count jobs by status for filter pills let statusCounts = $derived.by(() => { @@ -28,6 +29,16 @@ return counts; }); + let page0 = $state(currentPage - 1); + + $effect(() => { + const newPage = page0 + 1; + if (newPage !== currentPage) { + currentPage = newPage; + loadJobs(); + } + }); + let statusPills = $derived([ { label: 'All', value: '', count: jobs.length }, { label: $t.translate?.jobs?.status_draft, value: 'DRAFT', count: statusCounts.DRAFT }, @@ -49,6 +60,7 @@ try { const result = await fetchJobs({ page: currentPage, page_size: pageSize, status: statusFilter || undefined }); jobs = Array.isArray(result) ? result : (result?.results || result?.items || []); + total = result?.total ?? jobs.length; uxState = jobs.length === 0 ? 'empty' : 'populated'; } catch (err) { error = err?.message || $t.translate?.jobs?.load_failed; @@ -62,6 +74,7 @@ function filterByStatus(status) { statusFilter = status; currentPage = 1; + page0 = 0; loadJobs(); } @@ -268,6 +281,16 @@ {/each} + + + { pageSize = size; page0 = 0; loadJobs(); }} + class="mt-4" + /> {/if} diff --git a/frontend/src/routes/translate/history/+page.svelte b/frontend/src/routes/translate/history/+page.svelte index eb929614..9b662ee8 100644 --- a/frontend/src/routes/translate/history/+page.svelte +++ b/frontend/src/routes/translate/history/+page.svelte @@ -6,11 +6,23 @@