12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- 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<string, Library>? Libraries { get; set; }
- private Dictionary<string, MediaTag>? 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<KeyValuePair<string, Library>> 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();
- }
- }
- }
- }
|