1
0
mirror of synced 2025-02-17 19:19:18 +01:00

Add pagination to Leaderboard UI card

This commit is contained in:
shiibe 2024-06-04 22:33:52 -04:00
parent 29fc204536
commit 5e237a8e23
2 changed files with 28 additions and 5 deletions

View File

@ -64,7 +64,7 @@
<MudTd>
@if (context.BestScoreRank is not ScoreRank.None)
{
<img src="@($"/images/rank_{context.BestScoreRank}.png")" alt="@(ScoreUtils.GetRankText(context.BestScoreRank))" title="@(ScoreUtils.GetRankText(context.BestScoreRank))" style="@Constants.ICON_STYLE"/>
<img src="@($"/images/rank_{context.BestScoreRank}.png")" alt="@(ScoreUtils.GetRankText(context.BestScoreRank))" title="@(ScoreUtils.GetRankText(context.BestScoreRank))" style="@Constants.ICON_STYLE"/>
}
else
{
@ -75,6 +75,11 @@
<img src="@($"/images/crown_{context.BestCrown}.png")" alt="@(ScoreUtils.GetCrownText(context.BestCrown))" title="@(ScoreUtils.GetCrownText(context.BestCrown))" style="@Constants.ICON_STYLE"/>
</MudTd>
</RowTemplate>
<PagerContent>
<div class="d-flex flex-column align-center">
<MudPagination Class="pa-4" Count="@TotalPages" Selected="currentPage" SelectedChanged="(page) => OnPageChange(page)" BoundaryCount="1" MiddleCount="3" />
</div>
</PagerContent>
</MudTable>
}
</MudCardContent>

View File

@ -15,8 +15,21 @@ public partial class SongLeaderboardCard
public Difficulty Difficulty { get; set; } = Difficulty.None;
private string SelectedDifficulty { get; set; } = "None";
private int TotalPages { get; set; } = 0;
private bool isLoading = true;
private int currentPage = 1;
private int pageSize = 10;
private async Task GetLeaderboardData()
{
isLoading = true;
response = await Client.GetFromJsonAsync<SongLeaderboardResponse>($"api/SongLeaderboard/{(uint)SongId}?baid={(uint)Baid}&difficulty={(uint)Difficulty}&page={currentPage}&limit={pageSize}");
response.ThrowIfNull();
TotalPages = response.TotalPages;
isLoading = false;
}
protected override async Task OnInitializedAsync()
{
@ -37,8 +50,7 @@ public partial class SongLeaderboardCard
Difficulty = Difficulty.Easy;
}
response = await Client.GetFromJsonAsync<SongLeaderboardResponse>($"api/SongLeaderboard/{(uint)SongId}?baid={(uint)Baid}&difficulty={(uint)Difficulty}");
response.ThrowIfNull();
await GetLeaderboardData();
isLoading = false;
}
@ -50,11 +62,17 @@ public partial class SongLeaderboardCard
Difficulty = Enum.Parse<Difficulty>(SelectedDifficulty);
await LocalStorage.SetItemAsync("songPageDifficulty", SelectedDifficulty);
await GetLeaderboardData();
response = await Client.GetFromJsonAsync<SongLeaderboardResponse>($"api/SongLeaderboard/{(uint)SongId}?baid={(uint)Baid}&difficulty={(uint)Difficulty}");
response.ThrowIfNull();
currentPage = 1;
isLoading = false;
}
private async Task OnPageChange(int page)
{
currentPage = page;
await GetLeaderboardData();
}
private string GetActiveRowClass(SongLeaderboard leaderboard, int index)
{