1
0
mirror of synced 2024-12-19 01:46:09 +01:00
TaikoLocalServer/TaikoWebUI/Components/Song/SongLeaderboardCard.razor.cs

58 lines
1.8 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-03 01:55:44 +02:00
2024-06-03 17:03:09 +02:00
private bool isLoading = true;
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;
}
response = await Client.GetFromJsonAsync<SongLeaderboardResponse>($"api/SongLeaderboard/{(uint)SongId}?baid={(uint)Baid}&difficulty={(uint)Difficulty}");
2024-06-03 01:55:44 +02:00
response.ThrowIfNull();
2024-06-03 17:03:09 +02:00
isLoading = false;
2024-06-03 03:00:54 +02:00
}
private async Task OnDifficultyChange(string difficulty)
{
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);
response = await Client.GetFromJsonAsync<SongLeaderboardResponse>($"api/SongLeaderboard/{(uint)SongId}?baid={(uint)Baid}&difficulty={(uint)Difficulty}");
2024-06-03 03:00:54 +02:00
response.ThrowIfNull();
2024-06-03 17:03:09 +02:00
isLoading = false;
2024-06-03 01:55:44 +02:00
}
}