From 6180be8ee707d798b473ed715bb043c740f6a22e Mon Sep 17 00:00:00 2001 From: Egamorf Date: Wed, 16 Apr 2025 01:17:05 +0200 Subject: [PATCH] Add game row --- .../Pages/Games/Components/GameBase.cs | 42 +++++++++++++++++++ .../Pages/Games/Components/GameRow.razor | 38 +++++++++++++++++ .../Pages/Games/Components/GameRow.razor.css | 1 + .../Games/{GameBase.razor => Game.razor} | 0 .../{GameBase.razor.cs => Game.razor.cs} | 2 +- .../{GameBase.razor.css => Game.razor.css} | 0 .../CreateStaticResourceKey.cs | 2 + .../GameIdeas.WebAPI/Files/GameIdeas.fr.json | 3 +- 8 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameBase.cs create mode 100644 src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameRow.razor create mode 100644 src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameRow.razor.css rename src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/{GameBase.razor => Game.razor} (100%) rename src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/{GameBase.razor.cs => Game.razor.cs} (97%) rename src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/{GameBase.razor.css => Game.razor.css} (100%) diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameBase.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameBase.cs new file mode 100644 index 0000000..894a3a9 --- /dev/null +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameBase.cs @@ -0,0 +1,42 @@ +using GameIdeas.Shared.Dto; +using Microsoft.AspNetCore.Components; + +namespace GameIdeas.BlazorApp.Pages.Games.Components; + +public class GameBase : ComponentBase +{ + [Parameter] public GameDto GameDto { get; set; } = new(); + [Inject] public NavigationManager NavigationManager { get; set; } = default!; + + protected void HandleDetailClicked() + { + NavigationManager.NavigateTo($"/Game/Detail/{GameDto.Id}"); + } + + protected void HandlePlatformClicked(PlatformDto platform) + { + if (platform.Url != null) + { + NavigationManager.NavigateTo(platform.Url); + } + } + + protected string GetFormatedStorageSpace() + { + if (GameDto.StorageSpace == null) + { + return string.Empty; + } + + int quotien = (int)Math.Round((decimal)GameDto.StorageSpace) / 1000; + string unit = quotien switch + { + 0 => "Mo", + 1 => "Go", + 2 => "To", + _ => string.Empty + }; + + return $"{GameDto.StorageSpace % 1000:g1} {unit}"; + } +} diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameRow.razor b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameRow.razor new file mode 100644 index 0000000..99fa5d3 --- /dev/null +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameRow.razor @@ -0,0 +1,38 @@ +@using GameIdeas.BlazorApp.Shared.Constants +@inherits GameBase + +
+ + + @GameDto.Title + + @GameDto.ReleaseDate?.ToShortDateString() ?? @ResourcesKey.Unknown + +
+ @foreach (var platform in GameDto.Platforms ?? []) + { +
HandlePlatformClicked(platform))> + @platform.Label +
+ } +
+ +
+ @foreach (var tag in GameDto.Tags ?? []) + { +
+ @tag.Label +
+ } +
+ + @GetFormatedStorageSpace() + +
+ @GameDto.Interest + /5 +
+ + +
\ No newline at end of file diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameRow.razor.css b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameRow.razor.css new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameRow.razor.css @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/GameBase.razor b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Game.razor similarity index 100% rename from src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/GameBase.razor rename to src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Game.razor diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/GameBase.razor.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Game.razor.cs similarity index 97% rename from src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/GameBase.razor.cs rename to src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Game.razor.cs index e356f4a..2f09114 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/GameBase.razor.cs +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Game.razor.cs @@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Components; namespace GameIdeas.BlazorApp.Pages.Games; -public partial class GameBase () +public partial class Game { [Inject] private IGameGateway GameGateway { get; set; } = default!; diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/GameBase.razor.css b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Game.razor.css similarity index 100% rename from src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/GameBase.razor.css rename to src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Game.razor.css diff --git a/src/GameIdeas/GameIdeas.Resources/CreateStaticResourceKey.cs b/src/GameIdeas/GameIdeas.Resources/CreateStaticResourceKey.cs index f39a66e..aa5b8fb 100644 --- a/src/GameIdeas/GameIdeas.Resources/CreateStaticResourceKey.cs +++ b/src/GameIdeas/GameIdeas.Resources/CreateStaticResourceKey.cs @@ -38,6 +38,7 @@ public class Translations (TranslationService translationService) public string ErrorCreateGame => translationService.Translate(nameof(ErrorCreateGame)); public string InvalidTitle => translationService.Translate(nameof(InvalidTitle)); public string InvalidInterest => translationService.Translate(nameof(InvalidInterest)); + public string Unknown => translationService.Translate(nameof(Unknown)); } public static class ResourcesKey @@ -84,4 +85,5 @@ public static class ResourcesKey public static string ErrorCreateGame => _instance?.ErrorCreateGame ?? throw new InvalidOperationException("ResourcesKey.ErrorCreateGame is not initialized."); public static string InvalidTitle => _instance?.InvalidTitle ?? throw new InvalidOperationException("ResourcesKey.InvalidTitle is not initialized."); public static string InvalidInterest => _instance?.InvalidInterest ?? throw new InvalidOperationException("ResourcesKey.InvalidInterest is not initialized."); + public static string Unknown => _instance?.Unknown ?? throw new InvalidOperationException("ResourcesKey.Unknown is not initialized."); } \ No newline at end of file diff --git a/src/GameIdeas/Server/GameIdeas.WebAPI/Files/GameIdeas.fr.json b/src/GameIdeas/Server/GameIdeas.WebAPI/Files/GameIdeas.fr.json index 0dcf122..30cf2c1 100644 --- a/src/GameIdeas/Server/GameIdeas.WebAPI/Files/GameIdeas.fr.json +++ b/src/GameIdeas/Server/GameIdeas.WebAPI/Files/GameIdeas.fr.json @@ -33,5 +33,6 @@ "PlaceholderAdd": "Ajouter un nouveau", "ErrorCreateGame": "Erreur lors de la Création d'un jeu", "InvalidTitle": "Le titre est incorrect", - "InvalidInterest": "L'interêt est incorrect'" + "InvalidInterest": "L'interêt est incorrect", + "Unknown": "Inconnu" } \ No newline at end of file