1
0
mirror of synced 2024-12-22 11:25:54 +01:00
TaikoLocalServer/TaikoWebUI/Components/Song/SongLeaderboardCard.razor.cs

81 lines
2.3 KiB
C#
Raw Normal View History

2024-06-03 01:55:44 +02:00

namespace TaikoWebUI.Components.Song;
public partial class SongLeaderboardCard
{
2024-06-03 03:00:54 +02:00
private SongLeaderboardResponse? response = null;
2024-06-03 01:55:44 +02:00
[Parameter]
public int SongId { get; set; }
[Parameter]
public int Baid { get; set; }
[Parameter]
2024-06-03 17:27:18 +02:00
public Difficulty Difficulty { get; set; } = Difficulty.None;
2024-06-03 03:00:54 +02:00
2024-06-03 17:27:18 +02:00
private string SelectedDifficulty { get; set; } = "None";
2024-06-05 04:33:52 +02:00
private int TotalPages { get; set; } = 0;
2024-06-03 01:55:44 +02:00
2024-06-03 17:03:09 +02:00
private bool isLoading = true;
2024-06-05 04:33:52 +02:00
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;
}
2024-06-03 17:03:09 +02:00
2024-06-03 01:55:44 +02:00
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
2024-06-03 17:27:18 +02:00
// get highScoresTab from LocalStorage
var songPageDifficulty = await LocalStorage.GetItemAsync<string>("songPageDifficulty");
if (songPageDifficulty != null)
{
SelectedDifficulty = songPageDifficulty;
Difficulty = Enum.Parse<Difficulty>(SelectedDifficulty);
}
else
{
// set default difficulty to Easy
SelectedDifficulty = Difficulty.Easy.ToString();
Difficulty = Difficulty.Easy;
}
2024-06-05 04:33:52 +02:00
await GetLeaderboardData();
2024-06-03 17:03:09 +02:00
isLoading = false;
2024-06-03 03:00:54 +02:00
}
2024-06-05 05:44:09 +02:00
private async Task OnDifficultyChange(string difficulty = "None")
2024-06-03 03:00:54 +02:00
{
2024-06-03 17:03:09 +02:00
isLoading = true;
2024-06-03 03:00:54 +02:00
SelectedDifficulty = difficulty;
Difficulty = Enum.Parse<Difficulty>(SelectedDifficulty);
2024-06-03 17:27:18 +02:00
await LocalStorage.SetItemAsync("songPageDifficulty", SelectedDifficulty);
2024-06-05 04:33:52 +02:00
await GetLeaderboardData();
2024-06-03 17:27:18 +02:00
2024-06-05 04:33:52 +02:00
currentPage = 1;
2024-06-03 17:03:09 +02:00
isLoading = false;
2024-06-03 01:55:44 +02:00
}
2024-06-05 04:33:52 +02:00
private async Task OnPageChange(int page)
{
currentPage = page;
await GetLeaderboardData();
}
2024-06-05 01:53:41 +02:00
private string GetActiveRowClass(SongLeaderboard leaderboard, int index)
{
return leaderboard.Baid == Baid ? "is-current-user" : "";
}
2024-06-03 01:55:44 +02:00
}