using FNZCM.Shared.MediaModels; using FNZCM.Shared.MetadataModels; using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; namespace FNZCM.BlazorWasm.UI { public partial class App { [Inject] private NavigationManager nm { get; set; } [Inject] private IJSRuntime js { get; set; } private LoadingProgress? Progress { get; set; } private Dictionary? Libraries { get; set; } private Dictionary? MediaTags { get; set; } private Library CurrentLibrary { get; set; } private string CurrentLibraryKey { get; set; } private Disc? CurrentDisc { get; set; } private string CurrentDiscKey { get; set; } private List> SelectedLibs { get; set; } = new(); protected override async Task OnInitializedAsync() { ApiClient.HellNm = nm; base.OnInitialized(); do { Progress = await ApiClient.GetProgress(); StateHasChanged(); if (Progress?.IsLoading == false) break; Thread.Sleep(1000); } while (true); Libraries = await ApiClient.GetLibraries(); StateHasChanged(); MediaTags = await ApiClient.GetMediaTags(); if (Libraries?.Any() == true) { var f = Libraries.OrderBy(p => p.Key).FirstOrDefault(); CurrentLibraryKey = f.Key; CurrentLibrary = f.Value; } StateHasChanged(); } private void SelectLibrary(string libKey) { CurrentLibrary = Libraries[libKey]; CurrentLibraryKey = libKey; } private void SelectDisc(string discKey) { CurrentDisc = CurrentLibrary.Discs[discKey]; CurrentDiscKey = discKey; js.InvokeVoidAsync("ShowModalDisc"); } private string GetDiscDurationDisplay(string lib, string disc) { var totalSeconds = Libraries[lib].Discs[disc].MainTracks.Sum(p => { var mediaPath = $"/media/{lib}/{disc}/{p.Key}"; return MediaTags.TryGetValue(mediaPath, out var tag) ? tag.Duration : 0; }); var ts = TimeSpan.FromSeconds(totalSeconds); return ts.Hours > 0 ? $"{Math.Floor(ts.TotalHours):00}:{ts.Minutes:00}:{ts.Seconds:00}" : $"{Math.Floor(ts.TotalMinutes):00}:{ts.Seconds:00}"; } public void SelectedLibraryChanged() { if (SelectedLibs.Count > 0) { var f = SelectedLibs.First(); CurrentLibraryKey = f.Key; CurrentLibrary = f.Value; StateHasChanged(); } } } }