Files
ersatztv/ErsatzTV/Pages/EmbyLibrariesEditor.razor
T
Jason DoveandGitHub a87ec2d75d cleanup (#1708)
* fix blazor naming

* code cleanup

* update dependencies
2024-05-06 17:00:52 -05:00

55 lines
2.1 KiB
Plaintext

@page "/media/sources/emby/{Id:int}/libraries"
@using ErsatzTV.Application.Emby
@using ErsatzTV.Application.MediaSources
@implements IDisposable
@inject IMediator Mediator
@inject ChannelWriter<IScannerBackgroundServiceRequest> ScannerWorkerChannel
<RemoteMediaSourceLibrariesEditor
Id="@Id"
Name="Emby"
GetUpdateLibraryRequest="GetUpdateLibraryRequest"
GetLibrariesBySourceId="GetLibrariesBySourceId"
GetMediaSourceById="GetMediaSourceById"
SynchronizeLibraryByIdIfNeeded="SynchronizeLibraryByIdIfNeeded"/>
@code {
private readonly CancellationTokenSource _cts = new();
[Parameter]
public int Id { get; set; }
public void Dispose()
{
_cts.Cancel();
_cts.Dispose();
}
private IRequest<Either<BaseError, Unit>> GetUpdateLibraryRequest(List<RemoteMediaSourceLibraryEditViewModel> libraries) =>
new UpdateEmbyLibraryPreferences(
libraries.Map(l => new EmbyLibraryPreference(l.Id, l.ShouldSyncItems)).ToList());
private Task<List<RemoteMediaSourceLibraryEditViewModel>> GetLibrariesBySourceId(int mediaSourceId) =>
Mediator.Send(new GetEmbyLibrariesBySourceId(Id))
.Map(list => list.Map(ProjectToEditViewModel).OrderBy(x => x.MediaKind).ThenBy(x => x.Name).ToList());
private Task<Option<RemoteMediaSourceViewModel>> GetMediaSourceById(int mediaSourceId) =>
Mediator.Send(new GetEmbyMediaSourceById(Id))
.MapT(vm => new RemoteMediaSourceViewModel(vm.Id, vm.Name, vm.Address));
private RemoteMediaSourceLibraryEditViewModel ProjectToEditViewModel(EmbyLibraryViewModel library) => new()
{
Id = library.Id,
Name = library.Name,
MediaKind = library.MediaKind,
ShouldSyncItems = library.ShouldSyncItems
};
private async Task<Unit> SynchronizeLibraryByIdIfNeeded(RemoteMediaSourceLibrariesEditor.SynchronizeParameters parameters)
{
await ScannerWorkerChannel.WriteAsync(new SynchronizeEmbyLibraries(parameters.MediaSourceId), _cts.Token);
await ScannerWorkerChannel.WriteAsync(new SynchronizeEmbyLibraryByIdIfNeeded(parameters.LibraryId), _cts.Token);
return Unit.Default;
}
}