Files
game-ideas/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Games.razor.cs
Egamorf 58da2e6843
All checks were successful
Game Ideas deploy / build-test-deploy (push) Successful in 1m13s
Run code clean and fix messages (#45)
Reviewed-on: #45
2025-05-07 01:28:37 +02:00

78 lines
2.2 KiB
C#

using GameIdeas.BlazorApp.Pages.Games.Filter;
using GameIdeas.BlazorApp.Pages.Games.Gateways;
using GameIdeas.BlazorApp.Shared.Components.Popup;
using GameIdeas.BlazorApp.Shared.Models;
using GameIdeas.Shared.Dto;
using GameIdeas.Shared.Enum;
using Microsoft.AspNetCore.Components;
namespace GameIdeas.BlazorApp.Pages.Games;
public partial class Games
{
[Inject] private IGameGateway GameGateway { get; set; } = default!;
private DisplayType DisplayType = DisplayType.List;
private GameFilterParams GameFilter = new();
private Popup? ManualAddPopup;
private bool IsLoading = false;
private CategoriesDto? Categories;
private IEnumerable<GameDto> GamesDto = [];
private int CurrentPage;
protected override async Task OnInitializedAsync()
{
CurrentPage = 1;
GameFilter.SortType = Filter.GameFilter.SortTypes
.First(st => st.SortType == SortType.Ascending);
GameFilter.SortProperty = Filter.GameFilter.GameProperties
.First(gp => gp.PropertyName == nameof(GameIdeas.Shared.Model.Game.Title));
await HandleFetchDatas();
await base.OnInitializedAsync();
}
private void HandleAddClicked(AddType addType)
{
switch (addType)
{
case AddType.Manual:
ManualAddPopup?.Open();
break;
case AddType.Auto:
break;
default:
break;
}
}
private void HandleBackdropManualAddClicked()
{
ManualAddPopup?.Close();
}
private async Task HandleFetchDatas(bool loadCategories = true, bool displayLoader = true)
{
try
{
IsLoading = displayLoader;
if (loadCategories)
Categories = await GameGateway.FetchCategories();
GamesDto = await GameGateway.FetchGames(GameFilter, CurrentPage);
}
catch (Exception)
{
throw;
}
finally
{
IsLoading = false;
}
}
private async Task HandleFilterChanged(GameFilterParams args)
{
GameFilter = args;
await HandleFetchDatas(loadCategories: false, displayLoader: false);
}
}