349 lines
15 KiB
Plaintext
349 lines
15 KiB
Plaintext
@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 Microsoft.AspNetCore.WebUtilities
|
|
@using Microsoft.Extensions.Primitives
|
|
@using Unit = LanguageExt.Unit
|
|
@inherits MultiSelectBase<Search>
|
|
@inject NavigationManager _navigationManager
|
|
@inject ChannelWriter<IBackgroundServiceRequest> _channel
|
|
|
|
<MudPaper Square="true" Style="display: flex; height: 64px; left: 240px; padding: 0; position: fixed; right: 0; z-index: 100;">
|
|
<div style="display: flex; flex-direction: row; margin-bottom: auto; margin-top: auto; width: 100%" class="ml-6 mr-6">
|
|
@if (IsSelectMode())
|
|
{
|
|
<MudText Typo="Typo.h6" Color="Color.Primary">@SelectionLabel()</MudText>
|
|
<div style="margin-left: auto">
|
|
<MudButton Variant="Variant.Filled"
|
|
Color="Color.Primary"
|
|
StartIcon="@Icons.Material.Filled.Add"
|
|
OnClick="@(_ => AddSelectionToCollection())">
|
|
Add To Collection
|
|
</MudButton>
|
|
<MudButton Class="ml-3"
|
|
Variant="Variant.Filled"
|
|
Color="Color.Secondary"
|
|
StartIcon="@Icons.Material.Filled.Check"
|
|
OnClick="@(_ => ClearSelection())">
|
|
Clear Selection
|
|
</MudButton>
|
|
</div>
|
|
}
|
|
else
|
|
{
|
|
<MudText Style="margin-bottom: auto; margin-top: auto">@_query</MudText>
|
|
if (_movies.Count > 0)
|
|
{
|
|
<MudLink Class="ml-4" Href="@(_navigationManager.Uri.Split("#").Head() + "#movies")" Style="margin-bottom: auto; margin-top: auto">@_movies.Count Movies</MudLink>
|
|
}
|
|
|
|
if (_shows.Count > 0)
|
|
{
|
|
<MudLink Class="ml-4" Href="@(_navigationManager.Uri.Split("#").Head() + "#shows")" Style="margin-bottom: auto; margin-top: auto">@_shows.Count Shows</MudLink>
|
|
}
|
|
|
|
if (_artists.Count > 0)
|
|
{
|
|
<MudLink Class="ml-4" Href="@(_navigationManager.Uri.Split("#").Head() + "#artists")" Style="margin-bottom: auto; margin-top: auto">@_artists.Count Artists</MudLink>
|
|
}
|
|
|
|
if (_musicVideos.Count > 0)
|
|
{
|
|
<MudLink Class="ml-4" Href="@(_navigationManager.Uri.Split("#").Head() + "#music_videos")" Style="margin-bottom: auto; margin-top: auto">@_musicVideos.Count Music Videos</MudLink>
|
|
}
|
|
<div style="margin-left: auto">
|
|
<MudButton Variant="Variant.Filled"
|
|
Color="Color.Primary"
|
|
StartIcon="@Icons.Material.Filled.Add"
|
|
OnClick="@AddAllToCollection">
|
|
Add All To Collection
|
|
</MudButton>
|
|
</div>
|
|
}
|
|
</div>
|
|
</MudPaper>
|
|
<MudContainer MaxWidth="MaxWidth.ExtraLarge" Style="margin-top: 96px">
|
|
@if (_movies.Count > 0)
|
|
{
|
|
<div class="mb-4" style="align-items: baseline; display: flex; flex-direction: row;">
|
|
<MudText Typo="Typo.h4"
|
|
Style="scroll-margin-top: 160px"
|
|
UserAttributes="@(new Dictionary<string, object> { { "id", "movies" } })">
|
|
Movies
|
|
</MudText>
|
|
@if (_movies.Count > 50)
|
|
{
|
|
<MudLink Href="@GetMoviesLink()" Class="ml-4">See All >></MudLink>
|
|
}
|
|
</div>
|
|
|
|
<MudContainer MaxWidth="MaxWidth.False" Class="media-card-grid">
|
|
@foreach (MovieCardViewModel card in _movies.Cards.OrderBy(m => m.SortTitle))
|
|
{
|
|
<MediaCard Data="@card"
|
|
Link="@($"/media/movies/{card.MovieId}")"
|
|
AddToCollectionClicked="@AddToCollection"
|
|
SelectClicked="@(e => SelectClicked(card, e))"
|
|
IsSelected="@IsSelected(card)"
|
|
IsSelectMode="@IsSelectMode()"/>
|
|
}
|
|
</MudContainer>
|
|
}
|
|
|
|
@if (_shows.Count > 0)
|
|
{
|
|
<div class="mb-4" style="align-items: baseline; display: flex; flex-direction: row;">
|
|
<MudText Typo="Typo.h4"
|
|
Style="scroll-margin-top: 160px"
|
|
UserAttributes="@(new Dictionary<string, object> { { "id", "shows" } })">
|
|
Shows
|
|
</MudText>
|
|
@if (_shows.Count > 50)
|
|
{
|
|
<MudLink Href="@GetShowsLink()" Class="ml-4">See All >></MudLink>
|
|
}
|
|
</div>
|
|
|
|
<MudContainer MaxWidth="MaxWidth.False" Class="media-card-grid">
|
|
@foreach (TelevisionShowCardViewModel card in _shows.Cards.OrderBy(s => s.SortTitle))
|
|
{
|
|
<MediaCard Data="@card"
|
|
Link="@($"/media/tv/shows/{card.TelevisionShowId}")"
|
|
AddToCollectionClicked="@AddToCollection"
|
|
SelectClicked="@(e => SelectClicked(card, e))"
|
|
IsSelected="@IsSelected(card)"
|
|
IsSelectMode="@IsSelectMode()"/>
|
|
}
|
|
</MudContainer>
|
|
}
|
|
|
|
@if (_artists.Count > 0)
|
|
{
|
|
<div class="mb-4" style="align-items: baseline; display: flex; flex-direction: row;">
|
|
<MudText Typo="Typo.h4"
|
|
Style="scroll-margin-top: 160px"
|
|
UserAttributes="@(new Dictionary<string, object> { { "id", "artists" } })">
|
|
Artists
|
|
</MudText>
|
|
@if (_artists.Count > 50)
|
|
{
|
|
<MudLink Href="@GetArtistsLink()" Class="ml-4">See All >></MudLink>
|
|
}
|
|
</div>
|
|
|
|
<MudContainer MaxWidth="MaxWidth.False" Class="media-card-grid">
|
|
@foreach (ArtistCardViewModel card in _artists.Cards.OrderBy(s => s.SortTitle))
|
|
{
|
|
<MediaCard Data="@card"
|
|
Link="@($"/media/music/artists/{card.ArtistId}")"
|
|
ArtworkKind="ArtworkKind.Thumbnail"
|
|
AddToCollectionClicked="@AddToCollection"
|
|
SelectClicked="@(e => SelectClicked(card, e))"
|
|
IsSelected="@IsSelected(card)"
|
|
IsSelectMode="@IsSelectMode()"/>
|
|
}
|
|
</MudContainer>
|
|
}
|
|
|
|
@if (_musicVideos.Count > 0)
|
|
{
|
|
<div class="mb-4" style="align-items: baseline; display: flex; flex-direction: row;">
|
|
<MudText Typo="Typo.h4"
|
|
Style="scroll-margin-top: 160px"
|
|
UserAttributes="@(new Dictionary<string, object> { { "id", "music_videos" } })">
|
|
Music Videos
|
|
</MudText>
|
|
@if (_musicVideos.Count > 50)
|
|
{
|
|
<MudLink Href="@GetMusicVideosLink()" Class="ml-4">See All >></MudLink>
|
|
}
|
|
</div>
|
|
|
|
<MudContainer MaxWidth="MaxWidth.False" Class="media-card-grid">
|
|
@foreach (MusicVideoCardViewModel card in _musicVideos.Cards.OrderBy(s => s.SortTitle))
|
|
{
|
|
<MediaCard Data="@card"
|
|
Link=""
|
|
ArtworkKind="ArtworkKind.Thumbnail"
|
|
AddToCollectionClicked="@AddToCollection"
|
|
SelectClicked="@(e => SelectClicked(card, e))"
|
|
IsSelected="@IsSelected(card)"
|
|
IsSelectMode="@IsSelectMode()"/>
|
|
}
|
|
</MudContainer>
|
|
}
|
|
</MudContainer>
|
|
|
|
@code {
|
|
private string _query;
|
|
private MovieCardResultsViewModel _movies;
|
|
private TelevisionShowCardResultsViewModel _shows;
|
|
private MusicVideoCardResultsViewModel _musicVideos;
|
|
private ArtistCardResultsViewModel _artists;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
string query = new Uri(_navigationManager.Uri).Query;
|
|
|
|
if (QueryHelpers.ParseQuery(query).TryGetValue("query", out StringValues value))
|
|
{
|
|
_query = value;
|
|
|
|
_movies = await Mediator.Send(new QuerySearchIndexMovies($"type:movie AND ({_query})", 1, 50));
|
|
_shows = await Mediator.Send(new QuerySearchIndexShows($"type:show AND ({_query})", 1, 50));
|
|
_musicVideos = await Mediator.Send(new QuerySearchIndexMusicVideos($"type:music_video AND ({_query})", 1, 50));
|
|
_artists = await Mediator.Send(new QuerySearchIndexArtists($"type:artist AND ({_query})", 1, 50));
|
|
}
|
|
}
|
|
|
|
private void SelectClicked(MediaCardViewModel card, MouseEventArgs e)
|
|
{
|
|
List<MediaCardViewModel> GetSortedItems()
|
|
{
|
|
return _movies.Cards.OrderBy(m => m.SortTitle)
|
|
.Append<MediaCardViewModel>(_shows.Cards.OrderBy(s => s.SortTitle))
|
|
.Append(_artists.Cards.OrderBy(a => a.SortTitle))
|
|
.Append(_musicVideos.Cards.OrderBy(mv => mv.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<AddToCollectionDialog>("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<BaseError, Unit> 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<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));
|
|
}
|
|
}
|
|
|
|
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<AddToCollectionDialog>("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<BaseError, Unit> 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<AddToCollectionDialog>("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<BaseError, Unit> 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));
|
|
}
|
|
}
|
|
}
|
|
|
|
private string GetMoviesLink()
|
|
{
|
|
var uri = "/media/movies/page/1";
|
|
if (!string.IsNullOrWhiteSpace(_query))
|
|
{
|
|
uri = QueryHelpers.AddQueryString(uri, "query", _query);
|
|
}
|
|
return uri;
|
|
}
|
|
|
|
private string GetShowsLink()
|
|
{
|
|
var uri = "/media/tv/shows/page/1";
|
|
if (!string.IsNullOrWhiteSpace(_query))
|
|
{
|
|
uri = QueryHelpers.AddQueryString(uri, "query", _query);
|
|
}
|
|
return uri;
|
|
}
|
|
|
|
private string GetArtistsLink()
|
|
{
|
|
var uri = "/media/music/artists/page/1";
|
|
if (!string.IsNullOrWhiteSpace(_query))
|
|
{
|
|
uri = QueryHelpers.AddQueryString(uri, "query", _query);
|
|
}
|
|
return uri;
|
|
}
|
|
|
|
private string GetMusicVideosLink()
|
|
{
|
|
var uri = "/media/music/videos/page/1";
|
|
if (!string.IsNullOrWhiteSpace(_query))
|
|
{
|
|
uri = QueryHelpers.AddQueryString(uri, "query", _query);
|
|
}
|
|
return uri;
|
|
}
|
|
|
|
private async Task AddAllToCollection(MouseEventArgs _)
|
|
{
|
|
SearchResultAllItemsViewModel results = await Mediator.Send(new QuerySearchIndexAllItems(_query));
|
|
await AddItemsToCollection(results.MovieIds, results.ShowIds, results.ArtistIds, results.MusicVideoIds, "search results");
|
|
}
|
|
|
|
} |