Files
jsmr/JSMR.UI.Blazor/Pages/Creators.razor
2025-11-10 20:31:50 -05:00

142 lines
3.7 KiB
Plaintext

@page "/creators"
@inject VoiceWorksClient Client
@inject IJSRuntime JS
@using JSMR.Application.Common.Search
@using JSMR.Application.Creators.Queries.Search
@using JSMR.Application.Creators.Queries.Search.Contracts
@using JSMR.UI.Blazor.Components
@using JSMR.UI.Blazor.Services
<PageTitle>Creators</PageTitle>
<h1>Creators</h1>
<MudTextField @bind-Value="Keywords" Immediate="true" DebounceInterval="500" Label="Filter" Variant="Variant.Text" Adornment="@Adornment.Start" AdornmentIcon="@Icons.Material.Outlined.Search" />
@if (searchResults is null)
{
<p>Loading…</p>
}
else if (searchResults.Items.Length == 0)
{
<p>No results.</p>
}
else
{
<MudDataGrid Items="@searchResults.Items" Style="table-layout: fixed">
<Columns>
<PropertyColumn Property="x => x.Name" Title="Name" />
<PropertyColumn Property="x => x.VoiceWorkCount" Title="Voice Works" HeaderStyle="width: 14em" />
<TemplateColumn Title="Favorite" HeaderStyle="width: 8em">
<CellTemplate>
<MudIconButton Size="@Size.Small" Icon="@Icons.Material.Filled.Favorite" Color="@(context.Item.Favorite? Color.Secondary: Color.Dark)" />
</CellTemplate>
</TemplateColumn>
<TemplateColumn Title="Blacklisted" HeaderStyle="width: 8em">
<CellTemplate>
<MudIconButton Size="@Size.Small" Icon="@Icons.Material.Filled.Block" Color="@(context.Item.Blacklisted? Color.Secondary: Color.Dark)" />
</CellTemplate>
</TemplateColumn>
</Columns>
</MudDataGrid>
<JPagination @bind-PageNumber="PageNumber" @bind-PageSize="PageSize" @bind-TotalItems="searchResults.TotalItems" />
}
<style>
.mud-table-root {
table-layout: fixed;
}
.j-pager {
position: fixed;
bottom: 0;
left: 0;
right: 0;
justify-content: center;
z-index: 2;
background: var(--mud-palette-background);
padding: .5em 1em;
}
</style>
@code {
private string? keywords;
public string? Keywords
{
get { return keywords; }
set
{
keywords = value;
_ = UpdateDataAsync(true);
}
}
private int pageNumber = 1;
public int PageNumber
{
get { return pageNumber; }
set
{
pageNumber = value;
_ = UpdateDataAsync(false);
}
}
int pageSize = 100;
public int PageSize
{
get { return pageSize; }
set
{
pageSize = value;
_ = UpdateDataAsync(true);
}
}
SearchResult<CreatorSearchItem>? searchResults;
protected override Task OnInitializedAsync()
{
_ = LoadCreatorsAsync();
return Task.CompletedTask;
}
private async Task UpdateDataAsync(bool resetPageNumber)
{
if (resetPageNumber)
pageNumber = 1;
await LoadCreatorsAsync();
}
private async Task LoadCreatorsAsync()
{
SearchCreatorsRequest request = new(
Options: new()
{
PageNumber = PageNumber,
PageSize = pageSize,
Criteria = new()
{
Name = Keywords
},
SortOptions =
[
new(CreatorSortField.Name, Application.Common.Search.SortDirection.Ascending)
]
}
);
await JS.InvokeVoidAsync("pageHelpers.scrollToTop");
var result = await Client.SearchAsync(request);
searchResults = result?.Results ?? new();
await InvokeAsync(StateHasChanged);
}
}