Add better pagination to photos page

This commit is contained in:
jvyden 2021-12-11 21:09:27 -05:00
commit ba91a9994f
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
2 changed files with 14 additions and 1 deletions

View file

@ -20,4 +20,8 @@
{
<a href="/photos/@(Model.PageNumber - 1)">Previous Page</a>
}
@(Model.PageNumber + 1) / @(Model.PageAmount)
@if (Model.PageNumber < Model.PageAmount - 1)
{
<a href="/photos/@(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;
@ -18,6 +19,8 @@ namespace LBPUnion.ProjectLighthouse.Pages
public int PhotoCount;
public int PageAmount;
public List<Photo> Photos;
public PhotosPage([NotNull] Database database) : base(database)
{}
@ -27,6 +30,12 @@ namespace LBPUnion.ProjectLighthouse.Pages
this.PhotoCount = await StatisticsHelper.PhotoCount();
this.PageNumber = pageNumber;
this.PageAmount = (int)Math.Ceiling((double)this.PhotoCount / ServerStatics.PageSize);
if (this.PageNumber < 0 || this.PageNumber >= this.PageAmount)
{
return this.Redirect($"/photos/{Math.Clamp(this.PageNumber, 0, this.PageAmount - 1)}");
}
this.Photos = await this.Database.Photos.Include
(p => p.Creator)