user searching finished

This commit is contained in:
2024-11-07 00:20:45 +01:00
Unverified
parent 57fd4ba7a1
commit 727c124b1b
6 changed files with 201 additions and 5 deletions

View File

@@ -0,0 +1,77 @@
@using Blazorise.Extensions
@using WatchIt.Website.Components.Pages.SearchPage.Subcomponents
<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;
}
<UserSearchResultItemComponent Item="@(_items[iCopy])"/>
</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">
<LoadingComponent Color="@(LoadingComponent.LoadingComponentColors.Light)"/>
</div>
</div>
}
</div>
</div>

View File

@@ -0,0 +1,97 @@
using Microsoft.AspNetCore.Components;
using WatchIt.Common.Model.Accounts;
using WatchIt.Website.Services.Client.Accounts;
namespace WatchIt.Website.Components.Pages.SearchPage.Panels;
public partial class UsersSearchResultPanelComponent : ComponentBase
{
#region SERVICES
[Inject] private IAccountsClientService AccountsClientService { get; set; } = default!;
#endregion
#region PARAMETERS
[Parameter] public required string Query { get; set; }
#endregion
#region FIELDS
private bool _loaded;
private AccountQueryParameters _query = new AccountQueryParameters
{
First = 5
};
private List<AccountResponse> _items = [];
private bool _allItemsLoaded;
private bool _itemsLoading;
#endregion
#region PRIVATE METHODS
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
// INIT
_query.Username = Query;
List<Task> endTasks = new List<Task>();
// STEP 0
endTasks.AddRange(
[
AccountsClientService.GetAccounts(_query, data =>
{
_items.AddRange(data);
if (data.Count() < 5)
{
_allItemsLoaded = true;
}
else
{
_query.After = 5;
}
})
]);
// END
await Task.WhenAll(endTasks);
_loaded = true;
StateHasChanged();
}
}
private async Task DownloadItems()
{
_itemsLoading = true;
await AccountsClientService.GetAccounts(_query, data =>
{
_items.AddRange(data);
if (data.Count() < 5)
{
_allItemsLoaded = true;
}
else
{
_query.After += 5;
}
_itemsLoading = false;
});
}
#endregion
}

View File

@@ -0,0 +1,7 @@
<a class="text-decoration-none text-reset" href="/user/@(Item.Id)">
<div class="d-flex align-items-center gap-4">
<AccountPictureComponent Id="@(Item.Id)"
Size="90"/>
<h4 class="fw-bold">@(Item.Username)</h4>
</div>
</a>

View File

@@ -0,0 +1,13 @@
using Microsoft.AspNetCore.Components;
using WatchIt.Common.Model.Accounts;
namespace WatchIt.Website.Components.Pages.SearchPage.Subcomponents;
public partial class UserSearchResultItemComponent : ComponentBase
{
#region PROPERTIES
[Parameter] public required AccountResponse Item { get; set; }
#endregion
}

View File

@@ -121,7 +121,7 @@ public partial class MainLayout : LayoutComponentBase
if (!string.IsNullOrWhiteSpace(_searchbarText)) if (!string.IsNullOrWhiteSpace(_searchbarText))
{ {
string query = WebUtility.UrlEncode(_searchbarText); string query = WebUtility.UrlEncode(_searchbarText);
NavigationManager.NavigateTo($"/search/{query}"); NavigationManager.NavigateTo($"/search/{query}", true);
} }
} }

View File

@@ -1,3 +1,4 @@
@using System.Net
@using WatchIt.Common.Model.Movies @using WatchIt.Common.Model.Movies
@using WatchIt.Common.Model.Persons @using WatchIt.Common.Model.Persons
@using WatchIt.Common.Model.Series @using WatchIt.Common.Model.Series
@@ -15,7 +16,7 @@
<div class="rounded-3 panel panel-regular p-3"> <div class="rounded-3 panel panel-regular p-3">
<div class="d-flex justify-content-center"> <div class="d-flex justify-content-center">
<h3 class="m-0"> <h3 class="m-0">
<strong>Search results for phrase:</strong> "@(DecodedQuery)" <strong>Search results for phrase:</strong> "@(WebUtility.UrlDecode(Query))"
</h3> </h3>
</div> </div>
</div> </div>
@@ -27,7 +28,7 @@
NameSource="@(item => item.Title)" NameSource="@(item => item.Title)"
AdditionalNameInfoSource="@(item => item.ReleaseDate.HasValue ? $" ({item.ReleaseDate.Value.Year})" : null)" AdditionalNameInfoSource="@(item => item.ReleaseDate.HasValue ? $" ({item.ReleaseDate.Value.Year})" : null)"
RatingSource="@(item => item.Rating)" RatingSource="@(item => item.Rating)"
Query="@(new MovieQueryParameters { Title = DecodedQuery, OrderBy = "rating.count" })" Query="@(new MovieQueryParameters { Title = WebUtility.UrlDecode(Query), OrderBy = "rating.count" })"
ItemDownloadingTask="@(MoviesClientService.GetAllMovies)" ItemDownloadingTask="@(MoviesClientService.GetAllMovies)"
PictureDownloadingTask="@((id, action) => MediaClientService.GetMediaPoster(id, action))" PictureDownloadingTask="@((id, action) => MediaClientService.GetMediaPoster(id, action))"
PosterPlaceholder="/assets/media_poster.png" PosterPlaceholder="/assets/media_poster.png"
@@ -43,7 +44,7 @@
NameSource="@(item => item.Title)" NameSource="@(item => item.Title)"
AdditionalNameInfoSource="@(item => item.ReleaseDate.HasValue ? $" ({item.ReleaseDate.Value.Year})" : null)" AdditionalNameInfoSource="@(item => item.ReleaseDate.HasValue ? $" ({item.ReleaseDate.Value.Year})" : null)"
RatingSource="@(item => item.Rating)" RatingSource="@(item => item.Rating)"
Query="@(new SeriesQueryParameters { Title = DecodedQuery, OrderBy = "rating.count" })" Query="@(new SeriesQueryParameters { Title = WebUtility.UrlDecode(Query), OrderBy = "rating.count" })"
ItemDownloadingTask="@(SeriesClientService.GetAllSeries)" ItemDownloadingTask="@(SeriesClientService.GetAllSeries)"
PictureDownloadingTask="@((id, action) => MediaClientService.GetMediaPoster(id, action))" PictureDownloadingTask="@((id, action) => MediaClientService.GetMediaPoster(id, action))"
PosterPlaceholder="/assets/media_poster.png" PosterPlaceholder="/assets/media_poster.png"
@@ -58,9 +59,10 @@
IdSource="@(item => item.Id)" IdSource="@(item => item.Id)"
NameSource="@(item => item.Name)" NameSource="@(item => item.Name)"
RatingSource="@(item => item.Rating)" RatingSource="@(item => item.Rating)"
Query="@(new PersonQueryParameters { Name = DecodedQuery, OrderBy = "rating.count" })" Query="@(new PersonQueryParameters { Name = WebUtility.UrlDecode(Query), OrderBy = "rating.count" })"
ItemDownloadingTask="@(PersonsClientService.GetAllPersons)" ItemDownloadingTask="@(PersonsClientService.GetAllPersons)"
PictureDownloadingTask="@((id, action) => PersonsClientService.GetPersonPhoto(id, action))" PictureDownloadingTask="@((id, action) => PersonsClientService.GetPersonPhoto(id, action))"
PosterPlaceholder="/assets/person_poster.png" PosterPlaceholder="/assets/person_poster.png"
GetGlobalRatingMethod="@((id, action) => PersonsClientService.GetPersonGlobalRating(id, action))"/> GetGlobalRatingMethod="@((id, action) => PersonsClientService.GetPersonGlobalRating(id, action))"/>
<UsersSearchResultPanelComponent Query="@(WebUtility.UrlDecode(Query))"/>
</div> </div>