2024-05-27 00:06:51 +02:00
|
|
|
|
namespace TaikoWebUI.Pages;
|
2022-09-11 18:28:12 +02:00
|
|
|
|
|
2024-03-27 04:08:12 +01:00
|
|
|
|
public partial class SongList
|
2022-09-11 18:28:12 +02:00
|
|
|
|
{
|
|
|
|
|
[Parameter]
|
|
|
|
|
public int Baid { get; set; }
|
2024-05-17 00:32:46 +02:00
|
|
|
|
|
2024-03-14 05:38:26 +01:00
|
|
|
|
private string Search { get; set; } = string.Empty;
|
|
|
|
|
private string GenreFilter { get; set; } = string.Empty;
|
2024-05-27 00:06:51 +02:00
|
|
|
|
private string? SongNameLanguage { get; set; }
|
2024-03-14 05:38:26 +01:00
|
|
|
|
|
2022-09-11 18:28:12 +02:00
|
|
|
|
private SongBestResponse? response;
|
2024-03-09 07:07:34 +01:00
|
|
|
|
private UserSetting? userSetting;
|
2022-09-11 18:28:12 +02:00
|
|
|
|
|
2024-03-09 17:59:21 +01:00
|
|
|
|
private readonly List<BreadcrumbItem> breadcrumbs = new();
|
2024-05-25 19:12:30 +02:00
|
|
|
|
|
|
|
|
|
private Dictionary<uint, MusicDetail> musicDetailDictionary = new();
|
2024-03-14 03:27:55 +01:00
|
|
|
|
|
2022-09-11 18:28:12 +02:00
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
|
{
|
|
|
|
|
await base.OnInitializedAsync();
|
2024-05-25 19:12:30 +02:00
|
|
|
|
|
|
|
|
|
if (AuthService.LoginRequired && !AuthService.IsLoggedIn)
|
|
|
|
|
{
|
|
|
|
|
await AuthService.LoginWithAuthToken();
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-11 18:28:12 +02:00
|
|
|
|
response = await Client.GetFromJsonAsync<SongBestResponse>($"api/PlayData/{Baid}");
|
|
|
|
|
response.ThrowIfNull();
|
2024-03-08 21:11:54 +01:00
|
|
|
|
|
2024-03-09 07:07:34 +01:00
|
|
|
|
userSetting = await Client.GetFromJsonAsync<UserSetting>($"api/UserSettings/{Baid}");
|
2024-05-25 19:12:30 +02:00
|
|
|
|
musicDetailDictionary = await GameDataService.GetMusicDetailDictionary();
|
2024-03-14 03:27:55 +01:00
|
|
|
|
|
2024-05-27 00:06:51 +02:00
|
|
|
|
SongNameLanguage = await LocalStorage.GetItemAsync<string>("songNameLanguage");
|
2024-03-09 00:42:56 +01:00
|
|
|
|
|
2024-05-17 00:32:46 +02:00
|
|
|
|
if (AuthService.IsLoggedIn && !AuthService.IsAdmin)
|
2024-03-09 17:59:21 +01:00
|
|
|
|
{
|
2024-05-01 17:13:47 +02:00
|
|
|
|
breadcrumbs.Add(new BreadcrumbItem(Localizer["Dashboard"], href: "/"));
|
2024-03-09 17:59:21 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-05-01 17:13:47 +02:00
|
|
|
|
breadcrumbs.Add(new BreadcrumbItem(Localizer["Users"], href: "/Users"));
|
2024-03-09 17:59:21 +01:00
|
|
|
|
};
|
2024-03-09 07:07:34 +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["Song List"], href: $"/Users/{Baid}/Songs", disabled: false));
|
2022-09-11 18:28:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-14 05:38:26 +01:00
|
|
|
|
private bool FilterSongs(MusicDetail musicDetail)
|
2022-09-23 04:53:35 +02:00
|
|
|
|
{
|
2024-03-14 05:38:26 +01:00
|
|
|
|
var stringsToCheck = new List<string>
|
|
|
|
|
{
|
|
|
|
|
musicDetail.SongName,
|
|
|
|
|
musicDetail.SongNameEN,
|
|
|
|
|
musicDetail.SongNameCN,
|
|
|
|
|
musicDetail.SongNameKO,
|
|
|
|
|
musicDetail.ArtistName,
|
|
|
|
|
musicDetail.ArtistNameEN,
|
|
|
|
|
musicDetail.ArtistNameCN,
|
|
|
|
|
musicDetail.ArtistNameKO
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(Search) && !stringsToCheck.Any(s => s.Contains(Search, StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(GenreFilter) && musicDetail.Genre != Enum.Parse<SongGenre>(GenreFilter))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
2022-09-11 18:28:12 +02:00
|
|
|
|
}
|
2024-07-01 16:51:49 +02:00
|
|
|
|
|
|
|
|
|
private async Task OnFavoriteToggled(MusicDetail 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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-09-11 18:28:12 +02:00
|
|
|
|
}
|