Files
ersatztv/ErsatzTV/Pages/PlexLibrariesEditor.razor
T
Jason DoveandGitHub 5d081ceeff fix editorconfig and run code cleanup (#2324)
* fix formatting rules

* reformat ersatztv

* reformat ersatztv.application

* reformat ersatztv.core

* refactor ersatztv.core.tests

* reformat ersatztv.ffmpeg

* reformat ersatztv.ffmpeg.tests

* reformat ersatztv.infrastructure

* cleanup infra mysql

* cleanup infra sqlite

* cleanup infra tests

* cleanup ersatztv.scanner

* cleanup ersatztv.scanner.tests

* sln cleanup

* update dependencies
2025-08-16 14:44:48 +00:00

56 lines
2.2 KiB
Plaintext

@page "/media/sources/plex/{Id:int}/libraries"
@using ErsatzTV.Application.MediaSources
@using ErsatzTV.Application.Plex
@implements IDisposable
@inject IMediator Mediator
@inject ChannelWriter<IScannerBackgroundServiceRequest> ScannerWorkerChannel
<RemoteMediaSourceLibrariesEditor
Id="@Id"
Name="Plex"
GetUpdateLibraryRequest="GetUpdateLibraryRequest"
GetLibrariesBySourceId="GetLibrariesBySourceId"
GetMediaSourceById="GetMediaSourceById"
SynchronizeLibraryByIdIfNeeded="SynchronizeLibraryByIdIfNeeded"/>
@code {
private readonly CancellationTokenSource _cts = new();
[Parameter]
public int Id { get; set; }
private IRequest<Either<BaseError, Unit>> GetUpdateLibraryRequest(List<RemoteMediaSourceLibraryEditViewModel> libraries) =>
new UpdatePlexLibraryPreferences(
libraries.Map(l => new PlexLibraryPreference(l.Id, l.ShouldSyncItems)).ToList());
private async Task<List<RemoteMediaSourceLibraryEditViewModel>> GetLibrariesBySourceId(int mediaSourceId) =>
await Mediator.Send(new GetPlexLibrariesBySourceId(Id), _cts.Token)
.Map(list => list.Map(ProjectToEditViewModel).OrderBy(x => x.MediaKind).ThenBy(x => x.Name).ToList());
private async Task<Option<RemoteMediaSourceViewModel>> GetMediaSourceById(int mediaSourceId) =>
await Mediator.Send(new GetPlexMediaSourceById(Id), _cts.Token)
.MapT(vm => new RemoteMediaSourceViewModel(vm.Id, vm.Name, vm.Address));
public void Dispose()
{
_cts.Cancel();
_cts.Dispose();
}
private RemoteMediaSourceLibraryEditViewModel ProjectToEditViewModel(PlexLibraryViewModel 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 SynchronizePlexLibraryByIdIfNeeded(parameters.LibraryId), _cts.Token);
await ScannerWorkerChannel.WriteAsync(new SynchronizePlexNetworks(parameters.LibraryId, false), _cts.Token);
return Unit.Default;
}
}