Add release date and storage filter
All checks were successful
Game Ideas build for PR / build_blazor_app (pull_request) Successful in 34s

This commit is contained in:
2025-04-20 03:35:57 +02:00
parent 7fd9639eed
commit ba329f442b
18 changed files with 153 additions and 40 deletions

View File

@@ -22,4 +22,19 @@ public static class GameHelper
_ => "--yellow",
};
}
public static string GetFormatedStorageSpace(double? storageValue)
{
if (storageValue == null)
{
return string.Empty;
}
return storageValue switch
{
>= 1000000 => $"{storageValue / 1000000:f1} To",
>= 1000 => $"{storageValue / 1000:f1} Go",
_ => $"{storageValue:f1} Mo"
};
}
}

View File

@@ -12,19 +12,4 @@ public class GameBase : ComponentBase
{
NavigationManager.NavigateTo($"/Games/Detail/{GameDto.Id}");
}
protected string GetFormatedStorageSpace()
{
if (GameDto.StorageSpace == null)
{
return string.Empty;
}
return GameDto.StorageSpace switch
{
>= 1000000 => $"{GameDto.StorageSpace / 1000000:f1} To",
>= 1000 => $"{GameDto.StorageSpace / 1000:f1} Go",
_ => $"{GameDto.StorageSpace:f1} Mo"
};
}
}

View File

@@ -28,7 +28,7 @@
}
</div>
<span class="storage">@GetFormatedStorageSpace()</span>
<span class="storage">@GameHelper.GetFormatedStorageSpace(GameDto.StorageSpace)</span>
<div class="interest">
<span class="value" style="@($"color: var({GameHelper.GetInterestColor(GameDto.Interest, 5)})")">

View File

@@ -22,5 +22,11 @@
<SelectSearch TItem="PublisherDto" Placeholder="@ResourcesKey.Publishers" GetLabel="@(p => p.Name)"
@bind-Values=GameFilter.Publishers @bind-Values:after=HandleValueChanged Theme="Theme" Items="Categories?.Publishers" />
<SelectSearch TItem="int" Placeholder="@ResourcesKey.ReleaseDate" GetLabel="@(p => p.ToString())"
@bind-Values=GameFilter.ReleaseYears @bind-Values:after=HandleValueChanged Theme="Theme" Items="Categories?.ReleaseYears" />
<SelectSearch TItem="StorageSpaceDto" Placeholder="@ResourcesKey.StorageSize" GetLabel="@GetStorageSpaceLabel"
@bind-Values=GameFilter.StorageSpaces @bind-Values:after=HandleValueChanged Theme="Theme" Items="StorageSpaces" />
<span class="title">@ResourcesKey.LastAdd</span>
</div>

View File

@@ -1,4 +1,7 @@
using GameIdeas.BlazorApp.Helpers;
using GameIdeas.BlazorApp.Pages.Games.Header;
using GameIdeas.BlazorApp.Shared.Components.Select.Models;
using GameIdeas.Resources;
using GameIdeas.Shared.Dto;
using Microsoft.AspNetCore.Components;
@@ -11,9 +14,43 @@ public partial class AdvancedGameFilter
[Parameter] public EventCallback<GameFilterParams> GameFilterChanged { get; set; }
private readonly SelectTheme Theme = SelectTheme.AdvancedFilter;
private readonly List<StorageSpaceDto> StorageSpaces = [
new() { MaxSize = 100 },
new() { MinSize = 100, MaxSize = 1000 },
new() { MinSize = 1000, MaxSize = 5000 },
new() { MinSize = 5000, MaxSize = 10000 },
new() { MinSize = 10000, MaxSize = 20000 },
new() { MinSize = 20000, MaxSize = 40000 },
new() { MinSize = 40000, MaxSize = 100000 },
new() { MinSize = 100000 },
];
private async Task HandleValueChanged()
{
await GameFilterChanged.InvokeAsync(GameFilter);
}
private static string GetStorageSpaceLabel(StorageSpaceDto storageSpace)
{
if (storageSpace.MinSize == null && storageSpace.MaxSize != null)
{
return string.Format(ResourcesKey.MinStorageSpaceFormat,
GameHelper.GetFormatedStorageSpace(storageSpace.MinSize));
}
if (storageSpace.MinSize != null && storageSpace.MaxSize == null)
{
return string.Format(ResourcesKey.MaxStorageSpaceFormat,
GameHelper.GetFormatedStorageSpace(storageSpace.MaxSize));
}
if (storageSpace.MinSize != null && storageSpace.MaxSize != null)
{
return string.Format(ResourcesKey.MinMaxStorageSpaceFormat,
GameHelper.GetFormatedStorageSpace(storageSpace.MinSize),
GameHelper.GetFormatedStorageSpace(storageSpace.MaxSize));
}
throw new ArgumentNullException(ResourcesKey.ErrorStorageSpaceLabel);
}
}

View File

@@ -1,5 +1,6 @@

namespace GameIdeas.Shared.Dto;
using GameIdeas.Shared.Dto;
namespace GameIdeas.BlazorApp.Pages.Games.Filter;
public class GameFilterParams
{
@@ -14,6 +15,5 @@ public class GameFilterParams
public int MinInterest { get; set; } = 1;
public int MaxInterest { get; set; } = 5;
public List<int>? ReleaseYears { get; set; }
public int? MinStorageSize { get; set; }
public int? MaxStorageSize { get; set; }
public List<StorageSpaceDto>? StorageSpaces { get; set; }
}

View File

@@ -40,5 +40,5 @@
</div>
<Popup @ref=ManualAddPopup BackdropFilterClicked="HandleBackdropManualAddClicked" Closable=false>
<GameCreationForm Categories="Categories" OnSubmit="() => HandleFetchDatas(true)" />
<GameCreationForm Categories="Categories" OnSubmit="() => HandleFetchDatas()" />
</Popup>

View File

@@ -1,3 +1,4 @@
using GameIdeas.BlazorApp.Pages.Games.Filter;
using GameIdeas.BlazorApp.Pages.Games.Gateways;
using GameIdeas.BlazorApp.Shared.Components.Popup;
using GameIdeas.BlazorApp.Shared.Models;
@@ -28,7 +29,7 @@ public partial class Game
GameFilter.SortProperty= Filter.GameFilter.GameProperties
.First(gp => gp.PropertyName == nameof(GameIdeas.Shared.Model.Game.Title));
await HandleFetchDatas(true);
await HandleFetchDatas();
await base.OnInitializedAsync();
}
@@ -49,11 +50,11 @@ public partial class Game
{
ManualAddPopup?.Close();
}
private async Task HandleFetchDatas(bool loadCategories = false)
private async Task HandleFetchDatas(bool loadCategories = true, bool displayLoader = true)
{
try
{
IsLoading = true;
IsLoading = displayLoader;
if (loadCategories)
Categories = await GameGateway.FetchCategories();
@@ -72,6 +73,6 @@ public partial class Game
private async Task HandleFilterChanged(GameFilterParams args)
{
GameFilter = args;
await HandleFetchDatas(false);
await HandleFetchDatas(loadCategories: false, displayLoader: false);
}
}

View File

@@ -1,4 +1,5 @@
using GameIdeas.BlazorApp.Services;
using GameIdeas.BlazorApp.Pages.Games.Filter;
using GameIdeas.BlazorApp.Services;
using GameIdeas.BlazorApp.Shared.Constants;
using GameIdeas.BlazorApp.Shared.Exceptions;
using GameIdeas.Resources;
@@ -44,16 +45,13 @@ public class GameGateway(IHttpClientService httpClientService) : IGameGateway
Title = filterParams.Title,
MaxInterest = filterParams.MaxInterest,
MinInterest = filterParams.MinInterest,
MaxStorageSize = filterParams.MaxStorageSize,
MinStorageSize = filterParams.MinStorageSize,
ReleaseYears = filterParams.ReleaseYears,
StorageSpaces = filterParams.StorageSpaces,
DeveloperIds = filterParams.Developers?.Select(d => d.Id ?? 0).ToList(),
PublisherIds = filterParams.Publishers?.Select(d => d.Id ?? 0).ToList(),
PlatformIds = filterParams.Platforms?.Select(d => d.Id ?? 0).ToList(),
PropertyIds = filterParams.Properties?.Select(d => d.Id ?? 0).ToList(),
ReleaseYears = filterParams.ReleaseYears,
TagIds = filterParams.Tags?.Select(d => d.Id ?? 0).ToList(),
SortType = filterParams.SortType?.SortType,
SortPropertyName = filterParams.SortProperty?.PropertyName
};
var result = await httpClientService.FetchDataAsync<IEnumerable<GameDto>>(Endpoints.Game.Fetch(filter));

View File

@@ -1,4 +1,5 @@
using GameIdeas.Shared.Dto;
using GameIdeas.BlazorApp.Pages.Games.Filter;
using GameIdeas.Shared.Dto;
namespace GameIdeas.BlazorApp.Pages.Games.Gateways;

View File

@@ -21,7 +21,7 @@ public partial class SearchInput
Text = string.Empty;
Timer = new()
{
Interval = 1000,
Interval = 500,
AutoReset = false,
};