Refactoring, database structure changed
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
@using Blazorise.Extensions
|
||||
@using WatchIt.Website.Components.Subcomponents.Common
|
||||
|
||||
@inherits Component
|
||||
|
||||
@typeparam TItem
|
||||
@typeparam TQuery where TQuery : WatchIt.DTO.Query.IFilterQuery
|
||||
|
||||
|
||||
|
||||
<div class="panel">
|
||||
<div class="container-grid">
|
||||
<div class="row mb-4">
|
||||
<div class="col">
|
||||
<h4 class="m-0"><strong>@(Title)</strong></h4>
|
||||
</div>
|
||||
</div>
|
||||
@if (_loaded)
|
||||
{
|
||||
if (!_items.IsNullOrEmpty())
|
||||
{
|
||||
for (int i = 0; i < _items.Count; i++)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<hr/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
@{
|
||||
int iCopy = i;
|
||||
TItem item = _items[iCopy];
|
||||
string url = string.Format(UrlIdTemplate, IdFunc(item));
|
||||
}
|
||||
<VerticalListItem Name="@(NameFunc(item))"
|
||||
AdditionalInfo="@(AdditionalNameInfoFunc(item))"
|
||||
PicturePlaceholder="@(PicturePlaceholder)"
|
||||
PictureFunc="@(() => PictureFunc(item))"
|
||||
GlobalRating="@(GlobalRatingFunc(item))"
|
||||
SecondaryRatingTitle="@(SecondaryRatingTitle)"
|
||||
GetGlobalRatingMethod="@(() => GetGlobalRatingMethod(item))"
|
||||
GetSecondaryRatingMethod="@(() => GetSecondaryRatingMethod(item))"
|
||||
GetYourRatingMethod="@(GetYourRatingMethod is not null ? async userId => (int?)(await GetYourRatingMethod(item, userId))?.Rating : null)"
|
||||
PutYourRatingMethod="@(PutYourRatingMethod is not null ? request => PutYourRatingMethod(item, request) : null)"
|
||||
DeleteYourRatingMethod="@(DeleteYourRatingMethod is not null ? () => DeleteYourRatingMethod(item) : null)"
|
||||
ItemUrl="@(url)"/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
if (!_allItemsLoaded)
|
||||
{
|
||||
<div class="row mt-3">
|
||||
<div class="col">
|
||||
<div class="d-flex justify-content-center">
|
||||
<button class="btn btn-secondary" @onclick="DownloadItems">
|
||||
@if (!_itemsLoading)
|
||||
{
|
||||
<span>Load more</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
|
||||
<span>Loading...</span>
|
||||
}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="d-flex justify-content-center">
|
||||
No items found
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<Loading Color="@(Loading.Colors.Light)"/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,89 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using WatchIt.DTO.Models.Generics.Image;
|
||||
using WatchIt.DTO.Models.Generics.Rating;
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.Website.Components.Panels.Pages.SearchPage;
|
||||
|
||||
public partial class StandardSearchResultPanel<TItem, TQuery> : Component where TQuery : IFilterQuery
|
||||
{
|
||||
#region PARAMETERS
|
||||
|
||||
[Parameter] public required string Title { get; set; }
|
||||
[Parameter] public required TQuery Query { get; set; }
|
||||
|
||||
[Parameter] public required Func<TQuery, OrderQuery, PagingQuery, Task<IEnumerable<TItem>>> GetItemsMethod { get; set; }
|
||||
|
||||
[Parameter] public required Func<TItem, long> IdFunc { get; set; }
|
||||
[Parameter] public required Func<TItem, string> NameFunc { get; set; }
|
||||
[Parameter] public Func<TItem, string?> AdditionalNameInfoFunc { get; set; } = _ => null;
|
||||
[Parameter] public required Func<TItem, Task<ImageResponse?>> PictureFunc { get; set; }
|
||||
[Parameter] public required Func<TItem, RatingOverallResponse> GlobalRatingFunc { get; set; }
|
||||
|
||||
[Parameter] public required string UrlIdTemplate { get; set; }
|
||||
[Parameter] public required string PicturePlaceholder { get; set; }
|
||||
|
||||
[Parameter] public string? SecondaryRatingTitle { get; set; }
|
||||
|
||||
[Parameter] public required Func<TItem, Task<RatingOverallResponse?>> GetGlobalRatingMethod { get; set; }
|
||||
[Parameter] public Func<TItem, Task<IRatingResponse?>>? GetSecondaryRatingMethod { get; set; }
|
||||
[Parameter] public Func<TItem, long, Task<IRatingUserResponse?>>? GetYourRatingMethod { get; set; }
|
||||
[Parameter] public Func<TItem, RatingRequest, Task>? PutYourRatingMethod { get; set; }
|
||||
[Parameter] public Func<TItem, Task>? DeleteYourRatingMethod { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region FIELDS
|
||||
|
||||
private static readonly OrderQuery _orderQuery = new OrderQuery
|
||||
{
|
||||
OrderBy = "rating.average"
|
||||
};
|
||||
private readonly PagingQuery _pagingQuery = new PagingQuery
|
||||
{
|
||||
First = 5
|
||||
};
|
||||
private readonly List<TItem> _items = [];
|
||||
|
||||
private bool _loaded;
|
||||
private bool _allItemsLoaded;
|
||||
private bool _itemsLoading;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PRIVATE METHODS
|
||||
|
||||
protected override async Task OnFirstRenderAsync()
|
||||
{
|
||||
await DownloadItems();
|
||||
_pagingQuery.After = 5;
|
||||
|
||||
_loaded = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task DownloadItems()
|
||||
{
|
||||
_itemsLoading = true;
|
||||
IEnumerable<TItem> items = await GetItemsMethod(Query, _orderQuery, _pagingQuery);
|
||||
_items.AddRange(items);
|
||||
if (items.Count() < 5)
|
||||
{
|
||||
_allItemsLoaded = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_pagingQuery.After ??= 0;
|
||||
_pagingQuery.After += 5;
|
||||
}
|
||||
_itemsLoading = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
@using Blazorise.Extensions
|
||||
@using WatchIt.Website.Components.Subcomponents.Common
|
||||
|
||||
@inherits Component
|
||||
|
||||
|
||||
|
||||
<div class="panel">
|
||||
<div class="container-grid">
|
||||
<div class="row mb-4">
|
||||
<div class="col">
|
||||
<h4 class="m-0"><strong>Users</strong></h4>
|
||||
</div>
|
||||
</div>
|
||||
@if (_loaded)
|
||||
{
|
||||
if (!_items.IsNullOrEmpty())
|
||||
{
|
||||
for (int i = 0; i < _items.Count; i++)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<hr/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
@{
|
||||
int iCopy = i;
|
||||
}
|
||||
<VerticalListUserItem Item="@(_items[iCopy])"
|
||||
ProfilePictureIncluded="@(true)"/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
if (!_allItemsLoaded)
|
||||
{
|
||||
<div class="row mt-3">
|
||||
<div class="col">
|
||||
<div class="d-flex justify-content-center">
|
||||
<button class="btn btn-secondary" @onclick="DownloadItems">
|
||||
@if (!_itemsLoading)
|
||||
{
|
||||
<span>Load more</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
|
||||
<span>Loading...</span>
|
||||
}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="d-flex justify-content-center">
|
||||
No items found
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<Loading Color="@(Loading.Colors.Light)"/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,83 @@
|
||||
using Blazorise.Snackbar;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Refit;
|
||||
using WatchIt.DTO.Models.Controllers.Accounts.Account;
|
||||
using WatchIt.DTO.Query;
|
||||
using WatchIt.Website.Clients;
|
||||
using WatchIt.Website.Components.Layout;
|
||||
|
||||
namespace WatchIt.Website.Components.Panels.Pages.SearchPage;
|
||||
|
||||
public partial class UserSearchResultPanel : Component
|
||||
{
|
||||
#region SERVICES
|
||||
|
||||
[Inject] private IAccountsClient AccountsClient { get; set; } = null!;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PARAMETERS
|
||||
|
||||
[Parameter] public required string Query { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region FIELDS
|
||||
|
||||
|
||||
private readonly AccountFilterQuery _filterQuery = new AccountFilterQuery();
|
||||
private readonly PagingQuery _pagingQuery = new PagingQuery
|
||||
{
|
||||
First = 5
|
||||
};
|
||||
private List<AccountResponse> _items = [];
|
||||
|
||||
private bool _loaded;
|
||||
private bool _allItemsLoaded;
|
||||
private bool _itemsLoading;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PRIVATE METHODS
|
||||
|
||||
protected override async Task OnFirstRenderAsync()
|
||||
{
|
||||
await DownloadItems();
|
||||
_pagingQuery.After = 5;
|
||||
|
||||
_loaded = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task DownloadItems()
|
||||
{
|
||||
_itemsLoading = true;
|
||||
|
||||
IApiResponse<IEnumerable<AccountResponse>> response = await AccountsClient.GetAccounts(_filterQuery, pagingQuery: _pagingQuery, includeProfilePictures: true);
|
||||
if (!response.IsSuccessful)
|
||||
{
|
||||
await Base.SnackbarStack.PushAsync("An error has occured. Users could not be loaded", SnackbarColor.Danger);
|
||||
}
|
||||
IEnumerable<AccountResponse> items = response.Content ?? [];
|
||||
|
||||
_items.AddRange(items);
|
||||
if (items.Count() < 5)
|
||||
{
|
||||
_allItemsLoaded = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_pagingQuery.After ??= 0;
|
||||
_pagingQuery.After += 5;
|
||||
}
|
||||
_itemsLoading = false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user