@page "/search" @using ErsatzTV.Application.MediaCards @using ErsatzTV.Application.MediaCollections @using ErsatzTV.Application.MediaCollections.Commands @using ErsatzTV.Application.Search @using ErsatzTV.Application.Search.Queries @using ErsatzTV.Extensions @using Unit = LanguageExt.Unit @inherits MultiSelectBase @inject NavigationManager _navigationManager @inject ChannelWriter _channel
@if (IsSelectMode()) { @SelectionLabel()
Add To Collection Clear Selection
} else { @_query if (_movies?.Count > 0) { @_movies.Count Movies } if (_shows?.Count > 0) { @_shows.Count Shows } if (_seasons?.Count > 0) { @_seasons.Count Seasons } if (_episodes?.Count > 0) { @_episodes.Count Episodes } if (_artists?.Count > 0) { @_artists.Count Artists } if (_musicVideos?.Count > 0) { @_musicVideos.Count Music Videos } if (_otherVideos?.Count > 0) { @_otherVideos.Count Other Videos } if (_songs?.Count > 0) { @_songs.Count Songs }
Add All Save As
}
@if (_movies?.Count > 0) {
Movies @if (_movies.Count > 50) { See All >> }
@foreach (MovieCardViewModel card in _movies.Cards.OrderBy(m => m.SortTitle)) { } } @if (_shows?.Count > 0) {
Shows @if (_shows.Count > 50) { See All >> }
@foreach (TelevisionShowCardViewModel card in _shows.Cards.OrderBy(s => s.SortTitle)) { } } @if (_seasons?.Count > 0) {
Seasons @if (_seasons.Count > 50) { See All >> }
@foreach (TelevisionSeasonCardViewModel card in _seasons.Cards.OrderBy(s => s.SortTitle)) { } } @if (_episodes?.Count > 0) {
Episodes @if (_episodes.Count > 50) { See All >> }
@foreach (TelevisionEpisodeCardViewModel card in _episodes.Cards.OrderBy(s => s.SortTitle)) { } } @if (_artists?.Count > 0) {
Artists @if (_artists.Count > 50) { See All >> }
@foreach (ArtistCardViewModel card in _artists.Cards.OrderBy(s => s.SortTitle)) { } } @if (_musicVideos?.Count > 0) {
Music Videos @if (_musicVideos.Count > 50) { See All >> }
@foreach (MusicVideoCardViewModel card in _musicVideos.Cards.OrderBy(s => s.SortTitle)) { } } @if (_otherVideos?.Count > 0) {
Other Videos @if (_otherVideos.Count > 50) { See All >> }
@foreach (OtherVideoCardViewModel card in _otherVideos.Cards.OrderBy(s => s.SortTitle)) { } } @if (_songs?.Count > 0) {
Songs @if (_songs.Count > 50) { See All >> }
@foreach (SongCardViewModel card in _songs.Cards.OrderBy(s => s.SortTitle)) { } }
@code { private string _query; private MovieCardResultsViewModel _movies; private TelevisionShowCardResultsViewModel _shows; private TelevisionSeasonCardResultsViewModel _seasons; private TelevisionEpisodeCardResultsViewModel _episodes; private MusicVideoCardResultsViewModel _musicVideos; private OtherVideoCardResultsViewModel _otherVideos; private SongCardResultsViewModel _songs; private ArtistCardResultsViewModel _artists; protected override async Task OnInitializedAsync() { _query = _navigationManager.Uri.GetSearchQuery(); if (!string.IsNullOrWhiteSpace(_query)) { _movies = await Mediator.Send(new QuerySearchIndexMovies($"type:movie AND ({_query})", 1, 50)); _shows = await Mediator.Send(new QuerySearchIndexShows($"type:show AND ({_query})", 1, 50)); _seasons = await Mediator.Send(new QuerySearchIndexSeasons($"type:season AND ({_query})", 1, 50)); _episodes = await Mediator.Send(new QuerySearchIndexEpisodes($"type:episode AND ({_query})", 1, 50)); _musicVideos = await Mediator.Send(new QuerySearchIndexMusicVideos($"type:music_video AND ({_query})", 1, 50)); _otherVideos = await Mediator.Send(new QuerySearchIndexOtherVideos($"type:other_video AND ({_query})", 1, 50)); _songs = await Mediator.Send(new QuerySearchIndexSongs($"type:song AND ({_query})", 1, 50)); _artists = await Mediator.Send(new QuerySearchIndexArtists($"type:artist AND ({_query})", 1, 50)); } } private void SelectClicked(MediaCardViewModel card, MouseEventArgs e) { List GetSortedItems() { return _movies.Cards.OrderBy(m => m.SortTitle) .Append(_shows.Cards.OrderBy(s => s.SortTitle)) .Append(_seasons.Cards.OrderBy(s => s.SortTitle)) .Append(_episodes.Cards.OrderBy(ep => ep.SortTitle)) .Append(_artists.Cards.OrderBy(a => a.SortTitle)) .Append(_musicVideos.Cards.OrderBy(mv => mv.SortTitle)) .Append(_otherVideos.Cards.OrderBy(ov => ov.SortTitle)) .Append(_songs.Cards.OrderBy(ov => ov.SortTitle)) .ToList(); } SelectClicked(GetSortedItems, card, e); } private async Task AddToCollection(MediaCardViewModel card) { if (card is MovieCardViewModel movie) { var parameters = new DialogParameters { { "EntityType", "movie" }, { "EntityName", movie.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 AddMovieToCollection(collection.Id, movie.MovieId); Either addResult = await Mediator.Send(request); addResult.Match( Left: error => { Snackbar.Add($"Unexpected error adding movie to collection: {error.Value}"); Logger.LogError("Unexpected error adding movie to collection: {Error}", error.Value); }, Right: _ => Snackbar.Add($"Added {movie.Title} to collection {collection.Name}", Severity.Success)); } } 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("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 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)); } } 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)); } } if (card is ArtistCardViewModel artist) { var parameters = new DialogParameters { { "EntityType", "artist" }, { "EntityName", artist.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 AddArtistToCollection(collection.Id, artist.ArtistId); Either addResult = await Mediator.Send(request); addResult.Match( Left: error => { Snackbar.Add($"Unexpected error adding artist to collection: {error.Value}"); Logger.LogError("Unexpected error adding artist to collection: {Error}", error.Value); }, Right: _ => Snackbar.Add($"Added {artist.Title} to collection {collection.Name}", Severity.Success)); } } 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 = Dialog.Show("Add To Collection", parameters, options); DialogResult result = await dialog.Result; if (!result.Cancelled && result.Data is MediaCollectionViewModel collection) { var request = new AddMusicVideoToCollection(collection.Id, musicVideo.MusicVideoId); Either addResult = await Mediator.Send(request); 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)); } } 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 = Dialog.Show("Add To Collection", parameters, options); DialogResult result = await dialog.Result; if (!result.Cancelled && result.Data is MediaCollectionViewModel collection) { var request = new AddOtherVideoToCollection(collection.Id, otherVideo.OtherVideoId); Either addResult = await Mediator.Send(request); 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)); } } } private string GetMoviesLink() { var uri = "/media/movies/page/1"; if (!string.IsNullOrWhiteSpace(_query)) { (string key, string value) = _query.EncodeQuery(); uri = $"{uri}?{key}={value}"; } return uri; } private string GetShowsLink() { var uri = "/media/tv/shows/page/1"; if (!string.IsNullOrWhiteSpace(_query)) { (string key, string value) = _query.EncodeQuery(); uri = $"{uri}?{key}={value}"; } return uri; } private string GetSeasonsLink() { var uri = "/media/tv/seasons/page/1"; if (!string.IsNullOrWhiteSpace(_query)) { (string key, string value) = _query.EncodeQuery(); uri = $"{uri}?{key}={value}"; } return uri; } private string GetEpisodesLink() { var uri = "/media/tv/episodes/page/1"; if (!string.IsNullOrWhiteSpace(_query)) { (string key, string value) = _query.EncodeQuery(); uri = $"{uri}?{key}={value}"; } return uri; } private string GetArtistsLink() { var uri = "/media/music/artists/page/1"; if (!string.IsNullOrWhiteSpace(_query)) { (string key, string value) = _query.EncodeQuery(); uri = $"{uri}?{key}={value}"; } return uri; } private string GetMusicVideosLink() { var uri = "/media/music/videos/page/1"; if (!string.IsNullOrWhiteSpace(_query)) { (string key, string value) = _query.EncodeQuery(); uri = $"{uri}?{key}={value}"; } return uri; } private string GetOtherVideosLink() { var uri = "/media/other/videos/page/1"; if (!string.IsNullOrWhiteSpace(_query)) { (string key, string value) = _query.EncodeQuery(); uri = $"{uri}?{key}={value}"; } return uri; } private string GetSongsLink() { var uri = "/media/music/songs/page/1"; if (!string.IsNullOrWhiteSpace(_query)) { (string key, string value) = _query.EncodeQuery(); uri = $"{uri}?{key}={value}"; } return uri; } private async Task AddAllToCollection(MouseEventArgs _) { SearchResultAllItemsViewModel results = await Mediator.Send(new QuerySearchIndexAllItems(_query)); await AddItemsToCollection( results.MovieIds, results.ShowIds, results.SeasonIds, results.EpisodeIds, results.ArtistIds, results.MusicVideoIds, results.OtherVideoIds, results.SongIds, "search results"); } private async Task SaveAsSmartCollection(MouseEventArgs _) { var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.ExtraSmall }; IDialogReference dialog = Dialog.Show("Save As Smart Collection", options); DialogResult result = await dialog.Result; if (!result.Cancelled && result.Data is SmartCollectionViewModel collection) { var request = new UpdateSmartCollection( collection.Id, _query); Either updateResult = await Mediator.Send(request); updateResult.Match( Left: error => { Snackbar.Add($"Unexpected error saving smart collection: {error.Value}"); Logger.LogError("Unexpected error saving smart collection: {Error}", error.Value); }, Right: _ => { Snackbar.Add( $"Saved smart collection {collection.Name}", Severity.Success); ClearSelection(); }); } } }