actor roles panel added

This commit is contained in:
2024-10-13 12:10:52 +02:00
Unverified
parent d50373f4ba
commit f5a72d7a83
9 changed files with 147 additions and 50 deletions

View File

@@ -0,0 +1,16 @@
@if (IsLoading)
{
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
<span>@LoadingContent</span>
}
else
{
if (ChildContent is null)
{
<span>@Content</span>
}
else
{
@(ChildContent)
}
}

View File

@@ -0,0 +1,15 @@
using Microsoft.AspNetCore.Components;
namespace WatchIt.Website.Components;
public partial class LoadingButtonContentComponent : ComponentBase
{
#region PARAMETERS
[Parameter] public bool IsLoading { get; set; }
[Parameter] public string? LoadingContent { get; set; }
[Parameter] public string Content { get; set; }
[Parameter] public RenderFragment ChildContent { get; set; }
#endregion
}

View File

@@ -1,14 +1,10 @@
@using WatchIt.Common.Model.Roles
<div class="panel panel-padding-regular panel-radius-regular panel-background-regular @(Class)"> <div class="panel panel-padding-regular panel-radius-regular panel-background-regular @(Class)">
<div class="vstack"> <div class="vstack">
<span class="panel-text-title">Actors</span> <span class="panel-text-title">Actors</span>
@if (_loaded) <RoleListComponent Id="@(Id)"
{ TRole="WatchIt.Common.Model.Roles.ActorRoleResponse"
<RoleListComponent TRole="ActorRoleResponse"/> TQuery="WatchIt.Common.Model.Roles.ActorRoleMediaQueryParameters"
} GetRolesAction="MediaWebAPIService.GetMediaAllActorRoles"
else AdditionalTextSource="@(data => data.Name)"/>
{
<LoadingComponent/>
}
</div> </div>
</div> </div>

View File

@@ -1,6 +1,4 @@
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using WatchIt.Common.Model.Roles;
using WatchIt.Website.Services.Utility.Configuration;
using WatchIt.Website.Services.WebAPI.Media; using WatchIt.Website.Services.WebAPI.Media;
namespace WatchIt.Website.Components.MediaPage; namespace WatchIt.Website.Components.MediaPage;
@@ -21,37 +19,4 @@ public partial class ActorRolesPanelComponent : ComponentBase
[Parameter] public required long Id { get; set; } [Parameter] public required long Id { get; set; }
#endregion #endregion
#region FIELDS
private bool _loaded;
private IEnumerable<ActorRoleResponse> _roles = [];
#endregion
#region PUBLIC METHODS
protected override async Task OnAfterRenderAsync(bool firstRender)
{
List<Task> endTasks = new List<Task>();
// STEP 0
endTasks.AddRange(
[
MediaWebAPIService.GetMediaAllActorRoles(Id, successAction: data => _roles = data)
]);
// END
await Task.WhenAll(endTasks);
_loaded = true;
StateHasChanged();
}
#endregion
} }

View File

@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Components;
namespace WatchIt.Website.Components.MediaPage;
public partial class RoleComponent : ComponentBase
{
#region PARAMETERS
[Parameter] public string? AdditionalName { get; set; }
#endregion
}

View File

@@ -1,5 +1,27 @@
@typeparam TRole where TRole : WatchIt.Common.Model.Roles.IRoleResponse @typeparam TRole where TRole : WatchIt.Common.Model.Roles.IRoleResponse, WatchIt.Common.Query.IQueryOrderable<TRole>
@typeparam TQuery where TQuery : WatchIt.Common.Query.QueryParameters<TRole>
<div class=""> @if (_loaded)
{
</div> <div class="vstack">
@for (int i = 0; i < _roles.Count; i++)
{
if (i > 0)
{
<hr/>
}
<RoleComponent AdditionalName="@(AdditionalTextSource is not null ? AdditionalTextSource(_roles[i]) : null)"/>
}
<div class="d-flex justify-content-center">
<button class="btn btn-secondary" @onclick="@(async () => await GetRoles())">
<LoadingButtonContentComponent Content="Load more"
LoadingContent="Loading..."
IsLoading="@(_rolesFetching)"/>
</button>
</div>
</div>
}
else
{
<LoadingComponent/>
}

View File

@@ -1,13 +1,82 @@
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using WatchIt.Common.Model.Roles; using WatchIt.Common.Model.Roles;
using WatchIt.Common.Query;
namespace WatchIt.Website.Components.MediaPage; namespace WatchIt.Website.Components.MediaPage;
public partial class RoleListComponent<TRole> : ComponentBase where TRole : IRoleResponse public partial class RoleListComponent<TRole, TQuery> : ComponentBase where TRole : IRoleResponse, IQueryOrderable<TRole> where TQuery : QueryParameters<TRole>
{ {
#region PROPERTIES #region PROPERTIES
[Parameter] public required IEnumerable<TRole> Role { get; set; } [Parameter] public required long Id { get; set; }
[Parameter] public required Func<long, TQuery, Action<IEnumerable<TRole>>, Task> GetRolesAction { get; set; }
[Parameter] public TQuery Query { get; set; } = Activator.CreateInstance<TQuery>();
[Parameter] public Func<TRole, string>? AdditionalTextSource { get; set; }
#endregion
#region FIELDS
private readonly int _pageSize = 20;
private bool _loaded;
private bool _allItemsLoaded;
private List<TRole> _roles = new List<TRole>();
private bool _rolesFetching;
#endregion
#region PRIVATE METHODS
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
List<Task> endTasks = new List<Task>();
// INIT
Query.First = _pageSize;
// STEP 0
endTasks.AddRange(
[
GetRoles(true)
]);
// END
await Task.WhenAll(endTasks);
_loaded = true;
StateHasChanged();
}
}
private async Task GetRoles(bool firstFetch = false)
{
_rolesFetching = true;
await GetRolesAction(Id, Query, data =>
{
_roles.AddRange(data);
if (data.Count() < _pageSize)
{
_allItemsLoaded = true;
}
else
{
if (firstFetch)
{
Query.After = 0;
}
Query.After += _pageSize;
}
_rolesFetching = false;
});
}
#endregion #endregion
} }