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 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); } }