1
0
mirror of synced 2024-12-11 22:36:02 +01:00
TaikoLocalServer/TaikoWebUI/Pages/Song.razor.cs

62 lines
2.5 KiB
C#
Raw Normal View History

namespace TaikoWebUI.Pages;
2024-03-10 04:48:26 +01:00
public partial class Song
2024-03-10 04:48:26 +01:00
{
[Parameter]
public int SongId { get; set; }
2024-03-10 04:48:26 +01:00
[Parameter]
public int Baid { get; set; }
2024-03-10 04:48:26 +01:00
private UserSetting? userSetting;
private SongHistoryResponse? response;
private List<SongHistoryData>? songHistoryData;
private readonly List<BreadcrumbItem> breadcrumbs = new();
2024-03-10 04:48:26 +01:00
private string songTitle = string.Empty;
private string songArtist = string.Empty;
2024-03-10 04:48:26 +01:00
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
if (AuthService.LoginRequired && !AuthService.IsLoggedIn)
{
await AuthService.LoginWithAuthToken();
}
2024-03-10 04:48:26 +01:00
response = await Client.GetFromJsonAsync<SongHistoryResponse>($"api/PlayHistory/{(uint)Baid}");
response.ThrowIfNull();
// Get all song best data with SongId
songHistoryData = response.SongHistoryData.Where(data => data.SongId == (uint)SongId).ToList();
2024-03-10 04:48:26 +01:00
// Get user settings
userSetting = await Client.GetFromJsonAsync<UserSetting>($"api/UserSettings/{Baid}");
var musicDetailDictionary = await GameDataService.GetMusicDetailDictionary();
2024-03-10 04:48:26 +01:00
// Get song title and artist
var songNameLanguage = await LocalStorage.GetItemAsync<string>("songNameLanguage");
songTitle = GameDataService.GetMusicNameBySongId(musicDetailDictionary, (uint)SongId, string.IsNullOrEmpty(songNameLanguage) ? "ja" : songNameLanguage);
songArtist = GameDataService.GetMusicArtistBySongId(musicDetailDictionary, (uint)SongId, string.IsNullOrEmpty(songNameLanguage) ? "ja" : songNameLanguage);
2024-03-10 04:48:26 +01:00
// Breadcrumbs
var formattedSongTitle = songTitle;
if (formattedSongTitle.Length > 20)
{
formattedSongTitle = string.Concat(formattedSongTitle.AsSpan(0, 20), "...");
}
2024-03-10 04:48:26 +01:00
if (AuthService.IsLoggedIn && !AuthService.IsAdmin)
{
breadcrumbs.Add(new BreadcrumbItem(Localizer["Dashboard"], href: "/"));
2024-03-10 04:48:26 +01:00
}
else
{
breadcrumbs.Add(new BreadcrumbItem(Localizer["Users"], href: "/Users"));
};
breadcrumbs.Add(new BreadcrumbItem($"{userSetting?.MyDonName}", href: null, disabled: true));
breadcrumbs.Add(new BreadcrumbItem(Localizer["Song List"], href: $"/Users/{Baid}/Songs", disabled: false));
breadcrumbs.Add(new BreadcrumbItem(formattedSongTitle, href: $"/Users/{Baid}/Songs/{SongId}", disabled: false));
2024-03-10 04:48:26 +01:00
}
}