1
0
mirror of synced 2024-12-11 06:16:01 +01:00
TaikoLocalServer/TaikoWebUI/Pages/SongList.razor.cs

97 lines
3.2 KiB
C#
Raw Normal View History

namespace TaikoWebUI.Pages;
2022-09-11 18:28:12 +02: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;
private string? SongNameLanguage { get; set; }
2024-03-14 05:38:26 +01:00
2022-09-11 18:28:12 +02:00
private SongBestResponse? response;
private UserSetting? userSetting;
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();
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();
userSetting = await Client.GetFromJsonAsync<UserSetting>($"api/UserSettings/{Baid}");
musicDetailDictionary = await GameDataService.GetMusicDetailDictionary();
2024-03-14 03:27:55 +01:00
SongNameLanguage = await LocalStorage.GetItemAsync<string>("songNameLanguage");
2024-03-09 00:42:56 +01:00
foreach (var best in response.SongBestData)
foreach (var song in musicDetailDictionary)
if (best.SongId == song.Value.SongId)
song.Value.IsFavorite = best.IsFavorite;
2024-08-13 17:07:39 +02:00
BreadcrumbsStateContainer.breadcrumbs.Clear();
2024-05-17 00:32:46 +02:00
if (AuthService.IsLoggedIn && !AuthService.IsAdmin)
2024-03-09 17:59:21 +01:00
{
2024-08-13 17:07:39 +02:00
BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Dashboard"], href: "/"));
2024-03-09 17:59:21 +01:00
}
else
{
2024-08-13 17:07:39 +02:00
BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Users"], href: "/Users"));
2024-03-09 17:59:21 +01:00
};
2024-08-13 17:07:39 +02:00
BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem($"{userSetting?.MyDonName}", href: null, disabled: true));
BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Song List"], href: $"/Users/{Baid}/Songs", disabled: false));
BreadcrumbsStateContainer.NotifyStateChanged();
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 (musicDetail.IsFavorite) stringsToCheck.Add("Favorite");
2024-03-14 05:38:26 +01:00
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
}
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
}