1
0
mirror of synced 2025-02-05 06:05:38 +01:00
TaikoLocalServer/TaikoWebUI/Pages/SongList.razor.cs

92 lines
2.8 KiB
C#
Raw Normal View History

2024-03-09 22:48:26 -05:00
using Microsoft.JSInterop;
2024-03-13 22:27:55 -04:00
using TaikoWebUI.Shared.Models;
2022-09-22 22:53:35 -04:00
2024-03-14 00:38:26 -04:00
2024-03-08 18:42:56 -05:00
namespace TaikoWebUI.Pages;
2022-09-12 00:28:12 +08:00
public partial class SongList
2022-09-12 00:28:12 +08:00
{
[Parameter]
public int Baid { get; set; }
private const string IconStyle = "width:25px; height:25px;";
2024-03-08 18:42:56 -05:00
2024-03-14 00:38:26 -04:00
private string Search { get; set; } = string.Empty;
private string GenreFilter { get; set; } = string.Empty;
private string CurrentLanguage { get; set; } = "ja";
2022-09-12 00:28:12 +08:00
private SongBestResponse? response;
private UserSetting? userSetting;
2022-09-12 00:28:12 +08:00
private Dictionary<Difficulty, List<SongBestData>> songBestDataMap = new();
2024-03-09 11:59:21 -05:00
private readonly List<BreadcrumbItem> breadcrumbs = new();
2022-09-12 00:28:12 +08:00
2024-03-13 22:27:55 -04:00
private List<MusicDetail> musicMap = new();
2022-09-12 00:28:12 +08: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-03-13 22:30:15 -04:00
musicMap = GameDataService.GetMusicList();
2024-03-13 22:27:55 -04:00
2024-03-14 00:38:26 -04:00
CurrentLanguage = await JSRuntime.InvokeAsync<string>("blazorCulture.get");
2024-03-08 18:42:56 -05:00
2024-03-09 11:59:21 -05:00
if (LoginService.IsLoggedIn && !LoginService.IsAdmin)
{
breadcrumbs.Add(new BreadcrumbItem("Dashboard", href: "/"));
}
else
{
breadcrumbs.Add(new BreadcrumbItem("Users", href: "/Users"));
};
breadcrumbs.Add(new BreadcrumbItem($"{userSetting?.MyDonName}", href: null, disabled: true));
2024-03-09 22:48:26 -05:00
breadcrumbs.Add(new BreadcrumbItem("Songs", href: $"/Users/{Baid}/Songs", disabled: false));
2022-09-12 00:28:12 +08: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-14 00:38:26 -04:00
private bool FilterSongs(MusicDetail musicDetail)
2022-09-22 22:53:35 -04:00
{
2024-03-14 00:38:26 -04: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-12 00:28:12 +08:00
}
}