Put games table in a card, use loading indicator

This commit is contained in:
Pat Hartl 2023-03-03 17:34:50 -06:00
parent 7b6fd7cb0f
commit 68ec83f681

View file

@ -3,39 +3,49 @@
@inject GameService GameService @inject GameService GameService
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
<Table TItem="Game" DataSource="@Games"> <Card Title="Games">
<Column TData="string"> <Body>
<Image Src="@GetIcon(context)" Height="32" Width="32" Preview="false"></Image> <Table TItem="Game" DataSource="@Games" Loading="@Loading">
</Column> <Column TData="string">
<PropertyColumn Property="g => g.Title" Sortable /> <Image Src="@GetIcon(context)" Height="32" Width="32" Preview="false"></Image>
<PropertyColumn Property="g => g.SortTitle" Sortable /> </Column>
<PropertyColumn Property="g => g.ReleasedOn" Format="MM/dd/yyyy" Sortable /> <PropertyColumn Property="g => g.Title" Sortable />
<PropertyColumn Property="g => g.CreatedOn" Format="MM/dd/yyyy hh:mm" Sortable /> <PropertyColumn Property="g => g.SortTitle" Sortable />
<PropertyColumn Property="g => g.CreatedBy" Sortable> <PropertyColumn Property="g => g.ReleasedOn" Format="MM/dd/yyyy" Sortable />
@context.CreatedBy?.UserName <PropertyColumn Property="g => g.CreatedOn" Format="MM/dd/yyyy hh:mm" Sortable />
</PropertyColumn> <PropertyColumn Property="g => g.CreatedBy" Sortable>
<PropertyColumn Property="g => g.UpdatedOn" Format="MM/dd/yyyy hh:mm" Sortable /> @context.CreatedBy?.UserName
<PropertyColumn Property="g => g.UpdatedBy" Sortable> </PropertyColumn>
@context.UpdatedBy?.UserName <PropertyColumn Property="g => g.UpdatedOn" Format="MM/dd/yyyy hh:mm" Sortable />
</PropertyColumn> <PropertyColumn Property="g => g.UpdatedBy" Sortable>
<ActionColumn Title=""> @context.UpdatedBy?.UserName
<Space> </PropertyColumn>
<SpaceItem> <ActionColumn Title="">
<Button OnClick="() => Edit(context)">Edit</Button> <Space Style="display: flex; justify-content: end">
</SpaceItem> <SpaceItem>
</Space> <Button Type="@ButtonType.Text" Icon="@IconType.Outline.Edit" OnClick="() => Edit(context)" />
</ActionColumn> </SpaceItem>
</Table> </Space>
</ActionColumn>
</Table>
</Body>
</Card>
@code { @code {
IEnumerable<Game> Games { get; set; } = new List<Game>(); IEnumerable<Game> Games { get; set; } = new List<Game>();
private string Search { get; set; }
protected override async Task OnInitializedAsync() bool Loading = true;
protected override void OnAfterRender(bool firstRender)
{ {
Games = GameService.Get().OrderBy(g => String.IsNullOrWhiteSpace(g.SortTitle) ? g.Title : g.SortTitle).ToList(); if (firstRender)
{
Games = GameService.Get().OrderBy(g => String.IsNullOrWhiteSpace(g.SortTitle) ? g.Title : g.SortTitle).ToList();
StateHasChanged(); Loading = false;
StateHasChanged();
}
} }
private string GetIcon(Game game) private string GetIcon(Game game)