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.
132 lines
5.0 KiB
132 lines
5.0 KiB
@page "/media/music/videos" |
|
@page "/media/music/videos/page/{PageNumber:int}" |
|
@using ErsatzTV.Application.MediaCards |
|
@using ErsatzTV.Application.MediaCollections |
|
@using ErsatzTV.Application.Search |
|
@using ErsatzTV.Extensions |
|
@inherits MultiSelectBase<MusicVideoList> |
|
@inject NavigationManager NavigationManager |
|
|
|
<MudForm Style="max-height: 100%"> |
|
<MudPaper Square="true" Style="display: flex; height: 64px; min-height: 64px; width: 100%; z-index: 100;"> |
|
<MediaCardPager Query="@_query" |
|
PageNumber="@PageNumber" |
|
PageSize="@PageSize" |
|
TotalCount="@_data.Count" |
|
NextPage="@NextPage" |
|
PrevPage="@PrevPage" |
|
AddSelectionToCollection="@AddSelectionToCollection" |
|
AddSelectionToPlaylist="@AddSelectionToPlaylist" |
|
ClearSelection="@ClearSelection" |
|
IsSelectMode="@IsSelectMode" |
|
SelectionLabel="@SelectionLabel"/> |
|
</MudPaper> |
|
<div class="d-flex flex-column" style="height: 100vh; overflow-x: auto"> |
|
<MudContainer MaxWidth="MaxWidth.ExtraLarge" Class="pt-8"> |
|
<MudStack Row="true" Wrap="Wrap.Wrap"> |
|
<FragmentLetterAnchor TCard="MusicVideoCardViewModel" Cards="@_data.Cards"> |
|
<MediaCard Data="@context" |
|
Href="" |
|
ArtworkKind="ArtworkKind.Thumbnail" |
|
AddToCollectionClicked="@AddToCollection" |
|
SelectClicked="@(e => SelectClicked(context, e))" |
|
IsSelected="@IsSelected(context)" |
|
IsSelectMode="@IsSelectMode()"/> |
|
</FragmentLetterAnchor> |
|
</MudStack> |
|
</MudContainer> |
|
</div> |
|
</MudForm> |
|
@if (_data.PageMap is not null) |
|
{ |
|
<LetterBar PageMap="@_data.PageMap" |
|
BaseUri="media/music/videos" |
|
Query="@_query"/> |
|
} |
|
|
|
@code { |
|
private static int PageSize => 100; |
|
|
|
[Parameter] |
|
public int PageNumber { get; set; } |
|
|
|
private MusicVideoCardResultsViewModel _data = new(0, new List<MusicVideoCardViewModel>(), null); |
|
private string _query; |
|
|
|
protected override async Task OnParametersSetAsync() |
|
{ |
|
if (PageNumber == 0) |
|
{ |
|
PageNumber = 1; |
|
} |
|
|
|
_query = NavigationManager.Uri.GetSearchQuery(); |
|
|
|
await RefreshData(); |
|
} |
|
|
|
protected override async Task RefreshData() |
|
{ |
|
string searchQuery = string.IsNullOrWhiteSpace(_query) ? "type:music_video" : $"type:music_video AND ({_query})"; |
|
_data = await Mediator.Send(new QuerySearchIndexMusicVideos(searchQuery, PageNumber, PageSize), CancellationToken); |
|
} |
|
|
|
private void PrevPage() |
|
{ |
|
var uri = $"media/music/videos/page/{PageNumber - 1}"; |
|
if (!string.IsNullOrWhiteSpace(_query)) |
|
{ |
|
(string key, string value) = _query.EncodeQuery(); |
|
uri = $"{uri}?{key}={value}"; |
|
} |
|
|
|
NavigationManager.NavigateTo(uri); |
|
} |
|
|
|
private void NextPage() |
|
{ |
|
var uri = $"media/music/videos/page/{PageNumber + 1}"; |
|
if (!string.IsNullOrWhiteSpace(_query)) |
|
{ |
|
(string key, string value) = _query.EncodeQuery(); |
|
uri = $"{uri}?{key}={value}"; |
|
} |
|
|
|
NavigationManager.NavigateTo(uri); |
|
} |
|
|
|
private void SelectClicked(MediaCardViewModel card, MouseEventArgs e) |
|
{ |
|
List<MediaCardViewModel> GetSortedItems() |
|
{ |
|
return _data.Cards.OrderBy(m => m.SortTitle).ToList<MediaCardViewModel>(); |
|
} |
|
|
|
SelectClicked(GetSortedItems, card, e); |
|
} |
|
|
|
private async Task AddToCollection(MediaCardViewModel card) |
|
{ |
|
if (card is MusicVideoCardViewModel musicVideo) |
|
{ |
|
var parameters = new DialogParameters { { "EntityType", "music video" }, { "EntityName", musicVideo.Title } }; |
|
var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.ExtraSmall }; |
|
|
|
IDialogReference dialog = await Dialog.ShowAsync<AddToCollectionDialog>("Add To Collection", parameters, options); |
|
DialogResult result = await dialog.Result; |
|
if (result is { Canceled: false, Data: MediaCollectionViewModel collection }) |
|
{ |
|
var request = new AddMusicVideoToCollection(collection.Id, musicVideo.MusicVideoId); |
|
Either<BaseError, Unit> addResult = await Mediator.Send(request, CancellationToken); |
|
addResult.Match( |
|
Left: error => |
|
{ |
|
Snackbar.Add($"Unexpected error adding music video to collection: {error.Value}"); |
|
Logger.LogError("Unexpected error adding music video to collection: {Error}", error.Value); |
|
}, |
|
Right: _ => Snackbar.Add($"Added {musicVideo.Title} to collection {collection.Name}", Severity.Success)); |
|
} |
|
} |
|
} |
|
|
|
} |