1
0
mirror of synced 2024-12-18 17:35:55 +01:00
TaikoLocalServer/TaikoWebUI/Pages/Song.razor.cs

54 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;
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();
2024-08-13 17:07:39 +02:00
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}");
2024-08-13 17:07:39 +02:00
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;
2024-08-13 17:07:39 +02:00
if (formattedSongTitle.Length > 20) formattedSongTitle = string.Concat(formattedSongTitle.AsSpan(0, 20), "...");
BreadcrumbsStateContainer.breadcrumbs.Clear();
if (AuthService.IsLoggedIn && !AuthService.IsAdmin) BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Dashboard"], href: "/"));
else BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Users"], href: "/Users"));
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.breadcrumbs.Add(new BreadcrumbItem(formattedSongTitle, href: $"/Users/{Baid}/Songs/{SongId}", disabled: false));
BreadcrumbsStateContainer.NotifyStateChanged();
2024-03-10 04:48:26 +01:00
}
}