mirror of https://github.com/ErsatzTV/ErsatzTV.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
3.5 KiB
87 lines
3.5 KiB
@page "/media/tv/shows" |
|
@using ErsatzTV.Application.MediaCards |
|
@using ErsatzTV.Application.MediaCards.Queries |
|
@using ErsatzTV.Application.MediaCollections |
|
@using ErsatzTV.Application.MediaCollections.Commands |
|
@using Unit = LanguageExt.Unit |
|
@inject ILogger<TelevisionShowList> Logger |
|
@inject ISnackbar Snackbar |
|
@inject IMediator Mediator |
|
@inject IDialogService Dialog |
|
@inject ChannelWriter<IBackgroundServiceRequest> Channel |
|
|
|
<MudContainer MaxWidth="MaxWidth.ExtraLarge" Class="pt-8"> |
|
<MudContainer MaxWidth="MaxWidth.Small" Class="mb-6" Style="max-width: 300px"> |
|
<MudPaper Style="align-items: center; display: flex; justify-content: center;"> |
|
<MudIconButton Icon="@Icons.Material.Outlined.ChevronLeft" |
|
OnClick="@(() => PrevPage())" |
|
Disabled="@(_pageNumber <= 1)"> |
|
</MudIconButton> |
|
<MudText Style="flex-grow: 1" |
|
Align="Align.Center"> |
|
@Math.Min((_pageNumber - 1) * _pageSize + 1, _data.Count)-@Math.Min(_data.Count, _pageNumber * _pageSize) of @_data.Count |
|
</MudText> |
|
<MudIconButton Icon="@Icons.Material.Outlined.ChevronRight" |
|
OnClick="@(() => NextPage())" Disabled="@(_pageNumber * _pageSize >= _data.Count)"> |
|
</MudIconButton> |
|
</MudPaper> |
|
</MudContainer> |
|
|
|
<MudContainer MaxWidth="MaxWidth.False" Class="media-card-grid"> |
|
@foreach (TelevisionShowCardViewModel card in _data.Cards) |
|
{ |
|
<MediaCard Data="@card" |
|
Link="@($"/media/tv/shows/{card.TelevisionShowId}")" |
|
AddToCollectionClicked="@AddToCollection"/> |
|
} |
|
</MudContainer> |
|
</MudContainer> |
|
|
|
@code { |
|
private int _pageSize => 100; |
|
private int _pageNumber = 1; |
|
|
|
private TelevisionShowCardResultsViewModel _data; |
|
|
|
protected override Task OnParametersSetAsync() => RefreshData(); |
|
|
|
private async Task RefreshData() => |
|
_data = await Mediator.Send(new GetTelevisionShowCards(_pageNumber, _pageSize)); |
|
|
|
private async Task PrevPage() |
|
{ |
|
_pageNumber -= 1; |
|
await RefreshData(); |
|
} |
|
|
|
private async Task NextPage() |
|
{ |
|
_pageNumber += 1; |
|
await RefreshData(); |
|
} |
|
|
|
private async Task AddToCollection(MediaCardViewModel card) |
|
{ |
|
if (card is TelevisionShowCardViewModel show) |
|
{ |
|
var parameters = new DialogParameters { { "EntityType", "show" }, { "EntityName", show.Title } }; |
|
var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.ExtraSmall }; |
|
|
|
IDialogReference dialog = Dialog.Show<AddToCollectionDialog>("Add To Collection", parameters, options); |
|
DialogResult result = await dialog.Result; |
|
if (!result.Cancelled && result.Data is MediaCollectionViewModel collection) |
|
{ |
|
var request = new AddShowToCollection(collection.Id, show.TelevisionShowId); |
|
Either<BaseError, Unit> addResult = await Mediator.Send(request); |
|
addResult.Match( |
|
Left: error => |
|
{ |
|
Snackbar.Add($"Unexpected error adding show to collection: {error.Value}"); |
|
Logger.LogError("Unexpected error adding show to collection: {Error}", error.Value); |
|
}, |
|
Right: _ => Snackbar.Add($"Added {show.Title} to collection {collection.Name}", Severity.Success)); |
|
} |
|
} |
|
} |
|
|
|
} |