Improve pagination of the level listing

This commit is contained in:
Beyley Thomas 2021-12-11 14:56:36 -08:00
commit 36c108e799
No known key found for this signature in database
GPG key ID: 127DDFF5F85ADBD1
2 changed files with 14 additions and 1 deletions

View file

@ -31,4 +31,8 @@
{
<a href="/slots/@(Model.PageNumber - 1)">Previous Page</a>
}
<a href="/slots/@(Model.PageNumber + 1)">Next Page</a>
@(Model.PageNumber + 1) / @(Model.PageAmount)
@if (Model.PageNumber < Model.PageAmount - 1)
{
<a href="/slots/@(Model.PageNumber + 1)">Next Page</a>
}

View file

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
@ -17,6 +18,8 @@ namespace LBPUnion.ProjectLighthouse.Pages
public int PageNumber;
public int SlotCount;
public int PageAmount;
public List<Slot> Slots;
public SlotsPage([NotNull] Database database) : base(database)
@ -27,7 +30,13 @@ namespace LBPUnion.ProjectLighthouse.Pages
this.SlotCount = await StatisticsHelper.SlotCount();
this.PageNumber = pageNumber;
this.PageAmount = (int)Math.Ceiling((double)this.SlotCount / ServerStatics.PageSize);
if (this.PageNumber < 0 || this.PageNumber >= this.PageAmount)
{
return this.Redirect($"/slots/{Math.Clamp(this.PageNumber, 0, this.PageAmount - 1)}");
}
this.Slots = await this.Database.Slots.Include
(p => p.Creator)
.OrderByDescending(p => p.FirstUploaded)