@page "/media/other/videos" @page "/media/other/videos/page/{PageNumber:int}" @using ErsatzTV.Application.MediaCards @using ErsatzTV.Application.MediaCollections @using ErsatzTV.Application.Search @using ErsatzTV.Extensions @inherits MultiSelectBase @inject NavigationManager NavigationManager
@if (_data.PageMap is not null) { } @code { private static int PageSize => 100; [Parameter] public int PageNumber { get; set; } private OtherVideoCardResultsViewModel _data = new(0, new List(), null); private string _query; protected override async Task OnParametersSetAsync() { if (PageNumber == 0) { PageNumber = 1; } _query = NavigationManager.Uri.GetSearchQuery(); await RefreshData(CancellationToken); } protected override async Task RefreshData(CancellationToken cancellationToken) { string searchQuery = string.IsNullOrWhiteSpace(_query) ? "type:other_video" : $"type:other_video AND ({_query})"; _data = await Mediator.Send(new QuerySearchIndexOtherVideos(searchQuery, PageNumber, PageSize), cancellationToken); } private void PrevPage() { var uri = $"media/other/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/other/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 GetSortedItems() { return _data.Cards.OrderBy(m => m.SortTitle).ToList(); } SelectClicked(GetSortedItems, card, e); } private async Task AddToCollection(MediaCardViewModel card) { if (card is OtherVideoCardViewModel otherVideo) { var parameters = new DialogParameters { { "EntityType", "other video" }, { "EntityName", otherVideo.Title } }; var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.ExtraSmall }; IDialogReference dialog = await Dialog.ShowAsync("Add To Collection", parameters, options); DialogResult result = await dialog.Result; if (result is { Canceled: false, Data: MediaCollectionViewModel collection }) { var request = new AddOtherVideoToCollection(collection.Id, otherVideo.OtherVideoId); Either addResult = await Mediator.Send(request, CancellationToken); addResult.Match( Left: error => { Snackbar.Add($"Unexpected error adding other video to collection: {error.Value}"); Logger.LogError("Unexpected error adding other video to collection: {Error}", error.Value); }, Right: _ => Snackbar.Add($"Added {otherVideo.Title} to collection {collection.Name}", Severity.Success)); } } } }