@page "/media/rerun-collections/{Id:int}/edit" @page "/media/rerun-collections/add" @using ErsatzTV.Application.MediaCollections @using ErsatzTV.Application.MediaItems @using ErsatzTV.Application.Search @implements IDisposable @inject NavigationManager NavigationManager @inject ISnackbar Snackbar @inject IMediator Mediator @inject ILogger Logger @(IsEdit ? "Save Rerun Collection" : "Add Rerun Collection")
Rerun Collection
Name
Collection Type
Collection Television Show Television Season Artist Multi Collection Smart Collection
@if (_model.CollectionType == CollectionType.Collection) {
Collection
Only the first 10 items are shown
} @if (_model.CollectionType == CollectionType.MultiCollection) {
Multi Collection
Only the first 10 items are shown
} @if (_model.CollectionType == CollectionType.SmartCollection) {
Smart Collection
Only the first 10 items are shown
} @if (_model.CollectionType == CollectionType.TelevisionShow) {
Television Show
Only the first 10 items are shown
} @if (_model.CollectionType == CollectionType.TelevisionSeason) {
Television Season
Only the first 20 items are shown
} @if (_model.CollectionType == CollectionType.Artist) {
Artist
Only the first 10 items are shown
}
First Run Playback Order
@switch (_model.CollectionType) { case CollectionType.MultiCollection: Shuffle break; case CollectionType.Collection: case CollectionType.SmartCollection: Chronological Random Shuffle break; case CollectionType.TelevisionShow: Chronological Season, Episode Random Shuffle break; default: Chronological Random Shuffle break; }
Rerun Playback Order
@switch (_model.CollectionType) { case CollectionType.MultiCollection: Shuffle break; case CollectionType.Collection: case CollectionType.SmartCollection: Chronological Random Shuffle break; case CollectionType.TelevisionShow: Chronological Season, Episode Random Shuffle break; default: Chronological Random Shuffle break; }
@code { private CancellationTokenSource _cts; [Parameter] public int Id { get; set; } private readonly RerunCollectionEditViewModel _model = new(); private MudForm _form; private bool _success; public void Dispose() { _cts?.Cancel(); _cts?.Dispose(); } protected override async Task OnParametersSetAsync() { _cts?.Cancel(); _cts?.Dispose(); _cts = new CancellationTokenSource(); var token = _cts.Token; try { if (IsEdit) { Option maybeCollection = await Mediator.Send(new GetRerunCollectionById(Id), token); maybeCollection.IfSome(collection => { _model.Id = collection.Id; _model.Name = collection.Name; _model.CollectionType = collection.CollectionType; _model.Collection = collection.Collection; _model.MultiCollection = collection.MultiCollection; _model.SmartCollection = collection.SmartCollection; _model.MediaItem = collection.MediaItem; _model.FirstRunPlaybackOrder = collection.FirstRunPlaybackOrder; _model.RerunPlaybackOrder = collection.RerunPlaybackOrder; }); } else { _model.Name = "New Rerun Collection"; } } catch (OperationCanceledException) { // do nothing } } private bool IsEdit => Id != 0; private async Task> SearchCollections(string value, CancellationToken cancellationToken) { if (string.IsNullOrWhiteSpace(value)) { return new List(); } return await Mediator.Send(new SearchCollections(value), _cts.Token); } private async Task> SearchMultiCollections(string value, CancellationToken cancellationToken) { if (string.IsNullOrWhiteSpace(value)) { return new List(); } return await Mediator.Send(new SearchMultiCollections(value), _cts.Token); } private async Task> SearchSmartCollections(string value, CancellationToken cancellationToken) { if (string.IsNullOrWhiteSpace(value)) { return new List(); } return await Mediator.Send(new SearchSmartCollections(value), _cts.Token); } private async Task> SearchTelevisionShows(string value, CancellationToken cancellationToken) { if (string.IsNullOrWhiteSpace(value)) { return new List(); } return await Mediator.Send(new SearchTelevisionShows(value), _cts.Token); } private async Task> SearchTelevisionSeasons(string value, CancellationToken cancellationToken) { if (string.IsNullOrWhiteSpace(value)) { return new List(); } return await Mediator.Send(new SearchTelevisionSeasons(value), _cts.Token); } private async Task> SearchArtists(string value, CancellationToken cancellationToken) { if (string.IsNullOrWhiteSpace(value)) { return new List(); } return await Mediator.Send(new SearchArtists(value), _cts.Token); } private async Task HandleSubmitAsync() { await _form.Validate(); if (_success) { Seq errorMessage = IsEdit ? (await Mediator.Send(_model.ToUpdate(), _cts.Token)).LeftToSeq() : (await Mediator.Send(_model.ToCreate(), _cts.Token)).LeftToSeq(); errorMessage.HeadOrNone().Match( error => { Snackbar.Add(error.Value, Severity.Error); Logger.LogError("Error saving collection: {Error}", error.Value); }, () => NavigationManager.NavigateTo("media/rerun-collections")); } } }