@page "/media/tv/shows/{ShowId:int}" @using ErsatzTV.Application.Television @using ErsatzTV.Application.Television.Queries @using ErsatzTV.Application.MediaCards @using ErsatzTV.Application.MediaCards.Queries @using ErsatzTV.Application.MediaCollections @using ErsatzTV.Application.MediaCollections.Commands @using ErsatzTV.Application.ProgramSchedules @using ErsatzTV.Application.ProgramSchedules.Commands @using Unit = LanguageExt.Unit @inject IMediator Mediator @inject ILogger Logger @inject ISnackbar Snackbar @inject IDialogService Dialog @inject NavigationManager NavigationManager @inject ChannelWriter Channel
@if (!string.IsNullOrWhiteSpace(_show.FanArt)) { fan art }
@if (!string.IsNullOrWhiteSpace(_show.Poster)) { show poster }
@_show.Title @_show.Year @if (!string.IsNullOrWhiteSpace(_show.Plot)) { @_show.Plot }
Add To Collection Add To Schedule
@if (_show.Genres.Any()) { Genres
@foreach (string genre in _show.Genres.OrderBy(g => g)) { }
} @if (_show.Tags.Any()) { Tags
@foreach (string tag in _show.Tags.OrderBy(t => t)) { }
}
@foreach (TelevisionSeasonCardViewModel card in _data.Cards) { } @code { [Parameter] public int ShowId { get; set; } private TelevisionShowViewModel _show; private int _pageSize => 100; private readonly int _pageNumber = 1; private TelevisionSeasonCardResultsViewModel _data; protected override Task OnParametersSetAsync() => RefreshData(); private async Task RefreshData() { await Mediator.Send(new GetTelevisionShowById(ShowId)) .IfSomeAsync(vm => _show = vm); _data = await Mediator.Send(new GetTelevisionSeasonCards(ShowId, _pageNumber, _pageSize)); } private async Task AddToCollection() { var parameters = new DialogParameters { { "EntityType", "show" }, { "EntityName", _show.Title } }; var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.ExtraSmall }; IDialogReference dialog = Dialog.Show("Add To Collection", parameters, options); DialogResult result = await dialog.Result; if (!result.Cancelled && result.Data is MediaCollectionViewModel collection) { await Mediator.Send(new AddShowToCollection(collection.Id, ShowId)); NavigationManager.NavigateTo($"/media/collections/{collection.Id}"); } } private async Task AddToSchedule() { var parameters = new DialogParameters { { "EntityType", "show" }, { "EntityName", _show.Title } }; var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.ExtraSmall }; IDialogReference dialog = Dialog.Show("Add To Schedule", parameters, options); DialogResult result = await dialog.Result; if (!result.Cancelled && result.Data is ProgramScheduleViewModel schedule) { await Mediator.Send(new AddProgramScheduleItem(schedule.Id, StartType.Dynamic, null, PlayoutMode.One, ProgramScheduleItemCollectionType.TelevisionShow, null, ShowId, null, null, null)); NavigationManager.NavigateTo($"/schedules/{schedule.Id}/items"); } } private async Task AddSeasonToCollection(MediaCardViewModel card) { if (card is TelevisionSeasonCardViewModel season) { var parameters = new DialogParameters { { "EntityType", "season" }, { "EntityName", season.Title } }; var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.ExtraSmall }; IDialogReference dialog = Dialog.Show("Add To Collection", parameters, options); DialogResult result = await dialog.Result; if (!result.Cancelled && result.Data is MediaCollectionViewModel collection) { var request = new AddSeasonToCollection(collection.Id, season.TelevisionSeasonId); Either addResult = await Mediator.Send(request); addResult.Match( Left: error => { Snackbar.Add($"Unexpected error adding season to collection: {error.Value}"); Logger.LogError("Unexpected error adding season to collection: {Error}", error.Value); }, Right: _ => Snackbar.Add($"Added {season.Title} to collection {collection.Name}", Severity.Success)); } } } }