Refactor task history pagination logic for improved readability and maintainability

This commit is contained in:
2025-12-08 19:44:02 -05:00
parent 9d672d58ef
commit c7678b2028

View File

@@ -1339,27 +1339,29 @@
</div>
<!-- Pagination Navigation -->
@if($this->taskHistoryTotalPages > 1)
@php
$taskTotalPages = $this->taskHistoryTotalPages;
$taskCurrentPage = $taskHistoryCurrentPage;
@endphp
@if($taskTotalPages > 1)
<div class="flex items-center gap-1">
<!-- Previous Button -->
<button wire:click="previousTaskHistoryPage"
@if($taskHistoryCurrentPage <= 1) disabled @endif
@if($taskCurrentPage <= 1) disabled @endif
class="px-3 py-1.5 text-sm border border-neutral rounded-md hover:bg-background/80 disabled:opacity-50 disabled:cursor-not-allowed">
<x-ri-arrow-left-s-line class="size-4" />
</button>
<!-- Page Numbers -->
@php
$totalPages = $this->taskHistoryTotalPages;
$currentPage = $taskHistoryCurrentPage;
$pages = [];
// Always show first page
$pages[] = 1;
// Calculate range around current page
$start = max(2, $currentPage - 1);
$end = min($totalPages - 1, $currentPage + 1);
$start = max(2, $taskCurrentPage - 1);
$end = min($taskTotalPages - 1, $taskCurrentPage + 1);
// Add ellipsis after first page if needed
if ($start > 2) {
@@ -1372,13 +1374,13 @@
}
// Add ellipsis before last page if needed
if ($end < $totalPages - 1) {
if ($end < $taskTotalPages - 1) {
$pages[] = '...';
}
// Always show last page if more than 1 page
if ($totalPages > 1) {
$pages[] = $totalPages;
if ($taskTotalPages > 1) {
$pages[] = $taskTotalPages;
}
@endphp
@@ -1387,7 +1389,7 @@
<span class="px-2 py-1.5 text-sm text-base/50">...</span>
@else
<button wire:click="goToTaskHistoryPage({{ $page }})"
class="px-3 py-1.5 text-sm border rounded-md {{ $currentPage == $page ? 'bg-primary text-white border-primary' : 'border-neutral hover:bg-background/80' }}">
class="px-3 py-1.5 text-sm border rounded-md {{ $taskCurrentPage == $page ? 'bg-primary text-white border-primary' : 'border-neutral hover:bg-background/80' }}">
{{ $page }}
</button>
@endif
@@ -1395,11 +1397,13 @@
<!-- Next Button -->
<button wire:click="nextTaskHistoryPage"
@if($taskHistoryCurrentPage >= $this->taskHistoryTotalPages) disabled @endif
@if($taskCurrentPage >= $taskTotalPages) disabled @endif
class="px-3 py-1.5 text-sm border border-neutral rounded-md hover:bg-background/80 disabled:opacity-50 disabled:cursor-not-allowed">
<x-ri-arrow-right-s-line class="size-4" />
</button>
</div>
@else
<div class="text-sm text-base/50">Page 1 of 1</div>
@endif
</div>
</div>