From 5a777aa80d94e0539cce39d7fb617b57eeb7b98e Mon Sep 17 00:00:00 2001 From: Jason Dove Date: Mon, 1 Mar 2021 16:34:52 -0600 Subject: [PATCH] quick add episode to collection --- ErsatzTV/Pages/TelevisionEpisodeList.razor | 29 +++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/ErsatzTV/Pages/TelevisionEpisodeList.razor b/ErsatzTV/Pages/TelevisionEpisodeList.razor index 6ef6cab04..430d83b55 100644 --- a/ErsatzTV/Pages/TelevisionEpisodeList.razor +++ b/ErsatzTV/Pages/TelevisionEpisodeList.razor @@ -7,7 +7,10 @@ @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 @@ -53,7 +56,7 @@ @@ -119,5 +122,29 @@ NavigationManager.NavigateTo($"/schedules/{schedule.Id}/items"); } } + + private async Task AddEpisodeToCollection(MediaCardViewModel card) + { + if (card is TelevisionEpisodeCardViewModel episode) + { + var parameters = new DialogParameters { { "EntityType", "episode" }, { "EntityName", episode.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 AddEpisodeToCollection(collection.Id, episode.EpisodeId); + Either addResult = await Mediator.Send(request); + addResult.Match( + Left: error => + { + Snackbar.Add($"Unexpected error adding episode to collection: {error.Value}"); + Logger.LogError("Unexpected error adding episode to collection: {Error}", error.Value); + }, + Right: _ => Snackbar.Add($"Added {episode.Title} to collection {collection.Name}", Severity.Success)); + } + } + } } \ No newline at end of file