diff --git a/ErsatzTV/Extensions/NavigationManagerExtensions.cs b/ErsatzTV/Extensions/NavigationManagerExtensions.cs new file mode 100644 index 000000000..1597b2254 --- /dev/null +++ b/ErsatzTV/Extensions/NavigationManagerExtensions.cs @@ -0,0 +1,22 @@ +using System; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; + +namespace ErsatzTV.Extensions +{ + public static class NavigationManagerExtensions + { + public static ValueTask NavigateToFragmentAsync(this NavigationManager navigationManager, IJSRuntime jSRuntime) + { + Uri uri = navigationManager.ToAbsoluteUri(navigationManager.Uri); + + if (uri.Fragment.Length == 0) + { + return default; + } + + return jSRuntime.InvokeVoidAsync("blazorHelpers.scrollToFragment", uri.Fragment.Substring(1)); + } + } +} diff --git a/ErsatzTV/Pages/CollectionItems.razor b/ErsatzTV/Pages/CollectionItems.razor index 4d1ac4313..314809fdc 100644 --- a/ErsatzTV/Pages/CollectionItems.razor +++ b/ErsatzTV/Pages/CollectionItems.razor @@ -69,7 +69,7 @@ @foreach (TelevisionEpisodeCardViewModel card in _data.EpisodeCards.OrderBy(e => e.Aired)) { - - - -
- @if (!string.IsNullOrWhiteSpace(_episode.Poster)) - { - - - - } - -
- @_episode.Title - @_season.Name - @_episode.Plot -
- - Add To Collection - -
-
-
-
-
-
- - -@code { - - [Parameter] - public int EpisodeId { get; set; } - - private TelevisionEpisodeViewModel _episode; - private TelevisionSeasonViewModel _season; - - private List _breadcrumbs; - - protected override Task OnParametersSetAsync() => RefreshData(); - - private async Task RefreshData() - { - await Mediator.Send(new GetTelevisionEpisodeById(EpisodeId)) - .IfSomeAsync(vm => _episode = vm); - - await Mediator.Send(new GetTelevisionSeasonById(_episode.SeasonId)) - .IfSomeAsync(vm => _season = vm); - - _breadcrumbs = new List - { - new("TV Shows", "/media/tv/shows"), - new($"{_season.Title} ({_season.Year})", $"/media/tv/shows/{_season.ShowId}"), - new(_season.Name, $"/media/tv/seasons/{_episode.SeasonId}"), - new($"Episode {_episode.Episode}", null, true) - }; - } - - private async Task AddToCollection() - { - 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) - { - await Mediator.Send(new AddEpisodeToCollection(collection.Id, EpisodeId)); - NavigationManager.NavigateTo($"/media/collections/{collection.Id}"); - } - } - -} \ No newline at end of file diff --git a/ErsatzTV/Pages/TelevisionEpisodeList.razor b/ErsatzTV/Pages/TelevisionEpisodeList.razor index 95cae9e85..6099f8a38 100644 --- a/ErsatzTV/Pages/TelevisionEpisodeList.razor +++ b/ErsatzTV/Pages/TelevisionEpisodeList.razor @@ -7,6 +7,7 @@ @using ErsatzTV.Application.MediaCollections.Commands @using ErsatzTV.Application.ProgramSchedules @using ErsatzTV.Application.ProgramSchedules.Commands +@using ErsatzTV.Extensions @using Unit = LanguageExt.Unit @inject IMediator Mediator @inject ILogger Logger @@ -14,6 +15,7 @@ @inject IDialogService Dialog @inject NavigationManager NavigationManager @inject ChannelWriter Channel +@inject IJSRuntime JsRuntime
@@ -57,7 +59,7 @@ @foreach (TelevisionEpisodeCardViewModel episode in _data.Cards) { -
+
@if (!string.IsNullOrWhiteSpace(episode.Poster)) { @@ -95,7 +97,13 @@ private TelevisionEpisodeCardResultsViewModel _data; - private List _breadcrumbs; + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + await NavigationManager.NavigateToFragmentAsync(JsRuntime); + } + } protected override Task OnParametersSetAsync() => RefreshData(); @@ -105,13 +113,6 @@ .IfSomeAsync(vm => _season = vm); _data = await Mediator.Send(new GetTelevisionEpisodeCards(SeasonId, _pageNumber, _pageSize)); - - // _breadcrumbs = new List - // { - // new("TV Shows", "/media/tv/shows"), - // new($"{_season.Title} ({_season.Year})", ), - // new(_season.Name, null, true) - // }; } private async Task AddToCollection() diff --git a/ErsatzTV/Pages/_Host.cshtml b/ErsatzTV/Pages/_Host.cshtml index 36635de67..5e8133f62 100644 --- a/ErsatzTV/Pages/_Host.cshtml +++ b/ErsatzTV/Pages/_Host.cshtml @@ -35,5 +35,17 @@ + \ No newline at end of file