add show media info button to movie and episode detail pages (#1253)
This commit is contained in:
@@ -4,10 +4,13 @@
|
||||
@using System.Globalization
|
||||
@using ErsatzTV.Application.MediaCards
|
||||
@using ErsatzTV.Application.MediaCollections
|
||||
@using ErsatzTV.Application.MediaItems
|
||||
@implements IDisposable
|
||||
@inject IMediator _mediator
|
||||
@inject IDialogService _dialog
|
||||
@inject NavigationManager _navigationManager
|
||||
@inject ILogger<Movie> _logger
|
||||
@inject ISnackbar _snackbar
|
||||
|
||||
<MudContainer MaxWidth="MaxWidth.False" Style="padding: 0" Class="fanart-container">
|
||||
<div class="fanart-tint"></div>
|
||||
@@ -66,13 +69,22 @@
|
||||
</MudCard>
|
||||
}
|
||||
<div>
|
||||
<MudButton Variant="Variant.Filled"
|
||||
<MudButton Class="mb-6"
|
||||
Variant="Variant.Filled"
|
||||
Color="Color.Primary"
|
||||
StartIcon="@Icons.Material.Filled.Add"
|
||||
OnClick="@AddToCollection">
|
||||
Add To Collection
|
||||
</MudButton>
|
||||
</div>
|
||||
<div>
|
||||
<MudButton Variant="Variant.Filled"
|
||||
Color="Color.Secondary"
|
||||
StartIcon="@Icons.Material.Filled.Info"
|
||||
OnClick="@ShowInfo">
|
||||
Show Media Info
|
||||
</MudButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@if (_movie.MediaItemState == MediaItemState.FileNotFound)
|
||||
@@ -253,4 +265,22 @@
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ShowInfo()
|
||||
{
|
||||
Either<BaseError, MediaItemInfo> maybeInfo = await _mediator.Send(new GetMediaItemInfo(MovieId));
|
||||
|
||||
foreach (BaseError error in maybeInfo.LeftToSeq())
|
||||
{
|
||||
_snackbar.Add("Unexpected error loading media info");
|
||||
_logger.LogError("Unexpected error loading media info: {Error}", error.Value);
|
||||
}
|
||||
|
||||
foreach (MediaItemInfo info in maybeInfo.RightToSeq())
|
||||
{
|
||||
var parameters = new DialogParameters { { "MediaItemInfo", info } };
|
||||
var options = new DialogOptions { CloseButton = true, CloseOnEscapeKey = true, MaxWidth = MaxWidth.Medium, FullWidth = true };
|
||||
IDialogReference dialog = await _dialog.ShowAsync<MediaItemInfoDialog>(_movie.Title, parameters, options);
|
||||
DialogResult _ = await dialog.Result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
@using ErsatzTV.Application.Television
|
||||
@using ErsatzTV.Application.MediaCards
|
||||
@using ErsatzTV.Application.MediaCollections
|
||||
@using ErsatzTV.Application.MediaItems
|
||||
@using ErsatzTV.Application.ProgramSchedules
|
||||
@implements IDisposable
|
||||
@inject IMediator _mediator
|
||||
@@ -10,7 +11,6 @@
|
||||
@inject ISnackbar _snackbar
|
||||
@inject IDialogService _dialog
|
||||
@inject NavigationManager _navigationManager
|
||||
@inject ChannelWriter<IBackgroundServiceRequest> _channel
|
||||
@inject IJSRuntime _jsRuntime
|
||||
|
||||
<MudContainer MaxWidth="MaxWidth.False" Style="padding: 0" Class="fanart-container">
|
||||
@@ -109,6 +109,14 @@
|
||||
Add To Collection
|
||||
</MudButton>
|
||||
</div>
|
||||
<div class="mt-6">
|
||||
<MudButton Variant="Variant.Filled"
|
||||
Color="Color.Secondary"
|
||||
StartIcon="@Icons.Material.Filled.Info"
|
||||
OnClick="@(_ => ShowInfo(episode))">
|
||||
Show Media Info
|
||||
</MudButton>
|
||||
</div>
|
||||
</div>
|
||||
</MudCardContent>
|
||||
</div>
|
||||
@@ -258,5 +266,27 @@
|
||||
Right: _ => _snackbar.Add($"Added {episode.Title} to collection {collection.Name}", Severity.Success));
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ShowInfo(TelevisionEpisodeCardViewModel episode)
|
||||
{
|
||||
Either<BaseError, MediaItemInfo> maybeInfo = await _mediator.Send(new GetMediaItemInfo(episode.EpisodeId));
|
||||
|
||||
foreach (BaseError error in maybeInfo.LeftToSeq())
|
||||
{
|
||||
_snackbar.Add("Unexpected error loading media info");
|
||||
_logger.LogError("Unexpected error loading media info: {Error}", error.Value);
|
||||
}
|
||||
|
||||
foreach (MediaItemInfo info in maybeInfo.RightToSeq())
|
||||
{
|
||||
var parameters = new DialogParameters { { "MediaItemInfo", info } };
|
||||
var options = new DialogOptions { CloseButton = true, CloseOnEscapeKey = true, MaxWidth = MaxWidth.Medium, FullWidth = true };
|
||||
IDialogReference dialog = await _dialog.ShowAsync<MediaItemInfoDialog>(
|
||||
$"{episode.ShowTitle} - s{episode.Season:00}e{episode.Episode:00} - {episode.Title}",
|
||||
parameters,
|
||||
options);
|
||||
DialogResult _ = await dialog.Result;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
@using ErsatzTV.Application.MediaItems
|
||||
@using System.Text.Json
|
||||
@using System.Text.Json.Serialization
|
||||
@inject IJSRuntime JsRuntime
|
||||
|
||||
<div>
|
||||
<MudDialog>
|
||||
<DialogContent>
|
||||
<div class="overflow-y-scroll" style="max-height: 500px">
|
||||
<pre>
|
||||
<code @ref="_infoView">@_info</code>
|
||||
</pre>
|
||||
</div>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="(() => CopyToClipboard(_infoView))">
|
||||
Copy
|
||||
</MudButton>
|
||||
<MudButton Color="Color.Primary" OnClick="Close">Close</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
|
||||
[CascadingParameter]
|
||||
MudDialogInstance MudDialog { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public MediaItemInfo MediaItemInfo { get; set; }
|
||||
|
||||
private string _info;
|
||||
private ElementReference _infoView;
|
||||
|
||||
protected override Task OnParametersSetAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
_info = JsonSerializer.Serialize(
|
||||
MediaItemInfo,
|
||||
new JsonSerializerOptions
|
||||
{
|
||||
Converters = { new JsonStringEnumConverter() },
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
WriteIndented = true
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_info = ex.ToString();
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task CopyToClipboard(ElementReference view)
|
||||
{
|
||||
await JsRuntime.InvokeVoidAsync("clipboardCopy.copyText", view);
|
||||
}
|
||||
|
||||
private void Close() => MudDialog.Close(DialogResult.Ok(true));
|
||||
}
|
||||
Reference in New Issue
Block a user