2024-03-17 20:46:47 +01:00
|
|
|
|
using static MudBlazor.Colors;
|
|
|
|
|
using System;
|
|
|
|
|
using Microsoft.JSInterop;
|
|
|
|
|
|
2024-05-17 00:32:46 +02:00
|
|
|
|
|
2024-03-17 20:46:47 +01:00
|
|
|
|
namespace TaikoWebUI.Pages;
|
|
|
|
|
|
|
|
|
|
public partial class HighScores
|
|
|
|
|
{
|
|
|
|
|
[Parameter]
|
|
|
|
|
public int Baid { get; set; }
|
|
|
|
|
|
|
|
|
|
private SongBestResponse? response;
|
|
|
|
|
private UserSetting? userSetting;
|
|
|
|
|
private Dictionary<Difficulty, List<SongBestData>> songBestDataMap = new();
|
|
|
|
|
|
|
|
|
|
private readonly List<BreadcrumbItem> breadcrumbs = new();
|
2024-03-27 04:08:12 +01:00
|
|
|
|
private int selectedDifficultyTab = 0;
|
2024-03-17 20:46:47 +01:00
|
|
|
|
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
|
{
|
|
|
|
|
await base.OnInitializedAsync();
|
|
|
|
|
response = await Client.GetFromJsonAsync<SongBestResponse>($"api/PlayData/{Baid}");
|
|
|
|
|
response.ThrowIfNull();
|
|
|
|
|
|
|
|
|
|
userSetting = await Client.GetFromJsonAsync<UserSetting>($"api/UserSettings/{Baid}");
|
|
|
|
|
|
2024-05-17 00:32:46 +02:00
|
|
|
|
var language = await JsRuntime.InvokeAsync<string>("blazorCulture.get");
|
2024-03-17 20:46:47 +01:00
|
|
|
|
|
|
|
|
|
response.SongBestData.ForEach(data =>
|
|
|
|
|
{
|
|
|
|
|
var songId = data.SongId;
|
|
|
|
|
data.Genre = GameDataService.GetMusicGenreBySongId(songId);
|
|
|
|
|
data.MusicName = GameDataService.GetMusicNameBySongId(songId, string.IsNullOrEmpty(language) ? "ja" : language);
|
|
|
|
|
data.MusicArtist = GameDataService.GetMusicArtistBySongId(songId, string.IsNullOrEmpty(language) ? "ja" : language);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
songBestDataMap = response.SongBestData.GroupBy(data => data.Difficulty)
|
|
|
|
|
.ToDictionary(data => data.Key,
|
|
|
|
|
data => data.ToList());
|
|
|
|
|
foreach (var songBestDataList in songBestDataMap.Values)
|
|
|
|
|
{
|
|
|
|
|
songBestDataList.Sort((data1, data2) => GameDataService.GetMusicIndexBySongId(data1.SongId)
|
|
|
|
|
.CompareTo(GameDataService.GetMusicIndexBySongId(data2.SongId)));
|
|
|
|
|
}
|
2024-05-17 00:32:46 +02:00
|
|
|
|
|
2024-03-27 04:08:12 +01:00
|
|
|
|
// Set last selected tab from local storage
|
2024-05-17 00:32:46 +02:00
|
|
|
|
selectedDifficultyTab = await LocalStorage.GetItemAsync<int>($"highScoresTab");
|
2024-03-27 04:08:12 +01:00
|
|
|
|
|
|
|
|
|
// Breadcrumbs
|
2024-05-17 00:32:46 +02:00
|
|
|
|
if (AuthService.IsLoggedIn && !AuthService.IsAdmin)
|
2024-03-17 20:46:47 +01:00
|
|
|
|
{
|
2024-05-01 17:13:47 +02:00
|
|
|
|
breadcrumbs.Add(new BreadcrumbItem(Localizer["Dashboard"], href: "/"));
|
2024-03-17 20:46:47 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-05-01 17:13:47 +02:00
|
|
|
|
breadcrumbs.Add(new BreadcrumbItem(Localizer["Users"], href: "/Users"));
|
2024-03-17 20:46:47 +01:00
|
|
|
|
};
|
|
|
|
|
breadcrumbs.Add(new BreadcrumbItem($"{userSetting?.MyDonName}", href: null, disabled: true));
|
2024-05-01 17:13:47 +02:00
|
|
|
|
breadcrumbs.Add(new BreadcrumbItem(Localizer["High Scores"], href: $"/Users/{Baid}/HighScores", disabled: false));
|
2024-03-17 20:46:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task OnFavoriteToggled(SongBestData data)
|
|
|
|
|
{
|
|
|
|
|
var request = new SetFavoriteRequest
|
|
|
|
|
{
|
|
|
|
|
Baid = (uint)Baid,
|
|
|
|
|
IsFavorite = !data.IsFavorite,
|
|
|
|
|
SongId = data.SongId
|
|
|
|
|
};
|
|
|
|
|
var result = await Client.PostAsJsonAsync("api/FavoriteSongs", request);
|
|
|
|
|
if (result.IsSuccessStatusCode)
|
|
|
|
|
{
|
|
|
|
|
data.IsFavorite = !data.IsFavorite;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-27 04:08:12 +01:00
|
|
|
|
private async Task OnTabChanged(int index)
|
2024-03-17 20:46:47 +01:00
|
|
|
|
{
|
2024-03-27 04:08:12 +01:00
|
|
|
|
selectedDifficultyTab = index;
|
2024-05-17 00:32:46 +02:00
|
|
|
|
await LocalStorage.SetItemAsync($"highScoresTab", selectedDifficultyTab);
|
2024-03-17 20:46:47 +01:00
|
|
|
|
}
|
|
|
|
|
}
|