Add pages to photos page

This commit is contained in:
jvyden 2021-11-22 19:12:53 -05:00
commit 2b5f91c1cd
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
3 changed files with 20 additions and 6 deletions

View file

@ -28,7 +28,7 @@ namespace LBPUnion.ProjectLighthouse.Pages.Layouts
public readonly List<PageNavigationItem> NavigationItems = new()
{
new PageNavigationItem("Home", "/", "home"),
new PageNavigationItem("Photos", "/photos", "camera"),
new PageNavigationItem("Photos", "/photos/0", "camera"),
};
}

View file

@ -1,4 +1,4 @@
@page "/photos"
@page "/photos/{pageNumber:int}"
@using LBPUnion.ProjectLighthouse.Types
@model LBPUnion.ProjectLighthouse.Pages.PhotosPage
@ -12,7 +12,8 @@
@foreach (Photo photo in Model.Photos)
{
<div class="ui segment">
<img src="/gameAssets/@photo.LargeHash" style="width: 100%; height: auto; border-radius: .28571429rem;"><br>
<img src="/gameAssets/@photo.LargeHash" style="width: 100%; height: auto; border-radius: .28571429rem;">
<br>
<p>
<i>
@ -31,4 +32,12 @@
<a href="/users/@subject.UserId">@subject.User.Username</a>
}
</div>
}
}
@if (Model.PageNumber != 0)
{
<a href="/photos/@(Model.PageNumber - 1)">Previous Page</a>
}
<a href="/photos/@(Model.PageNumber + 1)">Next Page</a>
<div style="height: 100px; width: 1px;"></div> @* solves quirk with footer *@

View file

@ -19,11 +19,16 @@ namespace LBPUnion.ProjectLighthouse.Pages
public List<Photo> Photos;
public async Task<IActionResult> OnGet()
public int PageNumber;
public async Task<IActionResult> OnGet([FromRoute] int pageNumber)
{
const int pageSize = 20;
this.PhotoCount = await StatisticsHelper.PhotoCount();
this.Photos = await this.Database.Photos.Include(p => p.Creator).Take(20).ToListAsync();
this.PageNumber = pageNumber;
this.Photos = await this.Database.Photos.Include(p => p.Creator).Skip(pageNumber * pageSize).Take(pageSize).ToListAsync();
return this.Page();
}