Add pagination to the Jobs / Shifts / Talent list pages
The list pages loaded EVERY matching listing into one page (/Jobs was a ~2.6MB page with 1000+ cards) — no pagination at all. Add server-side paging (24/page, DB Skip/Take; near-me still sorts all by distance then paginates in memory). The header count now shows the true total, and a shared _Pager partial renders prev/next + a windowed page list that preserves all active filters in the URL. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -17,6 +17,11 @@ public class IndexModel : PageModel
|
||||
[BindProperty(SupportsGet = true)] public int? RoleId { get; set; }
|
||||
[BindProperty(SupportsGet = true)] public Gender? GenderFilter { get; set; }
|
||||
[BindProperty(SupportsGet = true)] public string? Q { get; set; } // deep search
|
||||
[BindProperty(SupportsGet = true)] public int Page { get; set; } = 1;
|
||||
private const int PageSize = 24;
|
||||
public int TotalCount { get; private set; }
|
||||
public int TotalPages { get; private set; }
|
||||
public int CurrentPage { get; private set; }
|
||||
|
||||
public List<TalentListing> Results { get; private set; } = new();
|
||||
public List<City> Cities { get; private set; } = new();
|
||||
@@ -60,7 +65,11 @@ public class IndexModel : PageModel
|
||||
EF.Functions.ILike(t.City.Name, like));
|
||||
}
|
||||
|
||||
Results = await q.OrderByDescending(t => t.CreatedAt).ToListAsync();
|
||||
TotalCount = await q.CountAsync();
|
||||
TotalPages = Math.Max(1, (int)Math.Ceiling(TotalCount / (double)PageSize));
|
||||
CurrentPage = Math.Clamp(Page, 1, TotalPages);
|
||||
Results = await q.OrderByDescending(t => t.CreatedAt)
|
||||
.Skip((CurrentPage - 1) * PageSize).Take(PageSize).ToListAsync();
|
||||
|
||||
var role = Roles.FirstOrDefault(r => r.Id == RoleId)?.Name;
|
||||
var city = Cities.FirstOrDefault(c => c.Id == CityId)?.Name;
|
||||
|
||||
Reference in New Issue
Block a user