@page "/media/sources/jellyfin/{Id:int}/libraries" @using ErsatzTV.Application.Jellyfin @using ErsatzTV.Application.MediaSources @implements IDisposable @inject IMediator _mediator @inject ChannelWriter _channel @code { private readonly CancellationTokenSource _cts = new(); [Parameter] public int Id { get; set; } public void Dispose() { _cts.Cancel(); _cts.Dispose(); } private IRequest> GetUpdateLibraryRequest(List libraries) => new UpdateJellyfinLibraryPreferences( libraries.Map(l => new JellyfinLibraryPreference(l.Id, l.ShouldSyncItems)).ToList()); private async Task> GetLibrariesBySourceId(int mediaSourceId) => await _mediator.Send(new GetJellyfinLibrariesBySourceId(Id), _cts.Token) .Map(list => list.Map(ProjectToEditViewModel).OrderBy(x => x.MediaKind).ThenBy(x => x.Name).ToList()); private async Task> GetMediaSourceById(int mediaSourceId) => await _mediator.Send(new GetJellyfinMediaSourceById(Id), _cts.Token) .MapT(vm => new RemoteMediaSourceViewModel(vm.Id, vm.Name, vm.Address)); private RemoteMediaSourceLibraryEditViewModel ProjectToEditViewModel(JellyfinLibraryViewModel library) => new() { Id = library.Id, Name = library.Name, MediaKind = library.MediaKind, ShouldSyncItems = library.ShouldSyncItems }; private async Task SynchronizeLibraryByIdIfNeeded(RemoteMediaSourceLibrariesEditor.SynchronizeParameters parameters) { await _channel.WriteAsync(new SynchronizeJellyfinLibraries(parameters.MediaSourceId), _cts.Token); await _channel.WriteAsync(new SynchronizeJellyfinLibraryByIdIfNeeded(parameters.LibraryId), _cts.Token); return Unit.Default; } }