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 : Component where TQuery : IFilterQuery { #region PARAMETERS [Parameter] public required string Title { get; set; } [Parameter] public required TQuery Query { get; set; } [Parameter] public required Func>> GetItemsMethod { get; set; } [Parameter] public required Func IdFunc { get; set; } [Parameter] public required Func NameFunc { get; set; } [Parameter] public Func AdditionalNameInfoFunc { get; set; } = _ => null; [Parameter] public required Func> PictureFunc { get; set; } [Parameter] public required Func 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> GetGlobalRatingMethod { get; set; } [Parameter] public Func>? GetSecondaryRatingMethod { get; set; } [Parameter] public Func>? GetYourRatingMethod { get; set; } [Parameter] public Func? PutYourRatingMethod { get; set; } [Parameter] public Func? 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 _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 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 }