From a1d931836a4b0294d9d57fc9e095f4c7fdd96d58 Mon Sep 17 00:00:00 2001 From: Egamorf Date: Sat, 12 Apr 2025 22:55:19 +0200 Subject: [PATCH 1/5] Add popup component --- .../Pages/Games/GameBase.razor | 7 ++- .../Pages/Games/GameBase.razor.cs | 19 +++++++ .../Pages/Games/Header/GameHeader.razor | 6 +-- .../Pages/Games/Header/GameHeader.razor.cs | 3 ++ .../BackdropFilter/BackdropFilter.razor.js | 2 +- .../Shared/Components/Popup/Popup.razor | 15 ++++++ .../Shared/Components/Popup/Popup.razor.cs | 49 +++++++++++++++++++ .../Shared/Components/Popup/Popup.razor.css | 27 ++++++++++ .../Components/Search/SearchInput.razor | 6 ++- .../Components/Search/SearchInput.razor.cs | 6 +-- .../Components/Select/SelectList.razor.cs | 7 +-- .../Shared}/Constants/Icons.cs | 23 +++++---- 12 files changed, 146 insertions(+), 24 deletions(-) create mode 100644 src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Popup/Popup.razor create mode 100644 src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Popup/Popup.razor.cs create mode 100644 src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Popup/Popup.razor.css rename src/GameIdeas/{GameIdeas.Shared => Client/GameIdeas.BlazorApp/Shared}/Constants/Icons.cs (62%) diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/GameBase.razor b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/GameBase.razor index dd434a7..9a1cfc0 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/GameBase.razor +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/GameBase.razor @@ -3,22 +3,25 @@ @using GameIdeas.BlazorApp.Pages.Games.Filter @using GameIdeas.BlazorApp.Pages.Games.Header @using GameIdeas.BlazorApp.Shared.Components +@using GameIdeas.BlazorApp.Shared.Components.Popup @using GameIdeas.Resources @layout MainLayout @ResourcesKey.GamesIdeas - +
-
+ + + diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/GameBase.razor.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/GameBase.razor.cs index 60ab45d..92aff27 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/GameBase.razor.cs +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/GameBase.razor.cs @@ -1,4 +1,5 @@ using GameIdeas.BlazorApp.Pages.Games.Filter; +using GameIdeas.BlazorApp.Shared.Components.Popup; using GameIdeas.BlazorApp.Shared.Models; namespace GameIdeas.BlazorApp.Pages.Games; @@ -7,4 +8,22 @@ public partial class GameBase () { private DisplayType DisplayType = DisplayType.List; private GameFilterParams GameFilterParams = new(); + private Popup? ManualAddPopup; + private void HandleAddClicked(AddType addType) + { + switch (addType) + { + case AddType.Manual: + ManualAddPopup?.Open(); + break; + case AddType.Auto: + break; + default: + break; + } + } + private void HandleBackdropManualAddClicked() + { + ManualAddPopup?.Close(); + } } \ No newline at end of file diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Header/GameHeader.razor b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Header/GameHeader.razor index c222be4..c948e2d 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Header/GameHeader.razor +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Header/GameHeader.razor @@ -22,11 +22,9 @@ - + Theme="SelectListTheme.Navigation" AlignRight=true>
diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Header/GameHeader.razor.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Header/GameHeader.razor.cs index a854eaf..0f5f2d9 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Header/GameHeader.razor.cs +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Header/GameHeader.razor.cs @@ -1,4 +1,5 @@ using GameIdeas.BlazorApp.Shared.Components.Account; +using GameIdeas.BlazorApp.Shared.Components.Select; using GameIdeas.BlazorApp.Shared.Components.Select.Models; using GameIdeas.BlazorApp.Shared.Models; using GameIdeas.Resources; @@ -18,6 +19,7 @@ public partial class GameHeader : ComponentBase ]; private AccountSettings? AccountSettings; + private SelectList? SelectListAdd; private void HandleIconClicked() { @@ -26,6 +28,7 @@ public partial class GameHeader : ComponentBase private async Task HandleAddTypeClickedAsync(AddType value) { + SelectListAdd?.Close(); await AddTypeChanged.InvokeAsync(value); } diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/BackdropFilter/BackdropFilter.razor.js b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/BackdropFilter/BackdropFilter.razor.js index 3f2b25b..ef50573 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/BackdropFilter/BackdropFilter.razor.js +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/BackdropFilter/BackdropFilter.razor.js @@ -1,3 +1,3 @@ window.setBodyOverflow = (overflow) => { - document.getElementsByTagName('html')[0].style.overflow = overflow; + document.getElementsByClassName('page')[0].style.overflow = overflow; } diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Popup/Popup.razor b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Popup/Popup.razor new file mode 100644 index 0000000..cc66ca4 --- /dev/null +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Popup/Popup.razor @@ -0,0 +1,15 @@ +@using GameIdeas.BlazorApp.Shared.Components.BackdropFilter +@using GameIdeas.BlazorApp.Shared.Constants + + + + \ No newline at end of file diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Popup/Popup.razor.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Popup/Popup.razor.cs new file mode 100644 index 0000000..2b18c50 --- /dev/null +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Popup/Popup.razor.cs @@ -0,0 +1,49 @@ +using Microsoft.AspNetCore.Components; + +namespace GameIdeas.BlazorApp.Shared.Components.Popup; + +public partial class Popup +{ + [Parameter] public RenderFragment? ChildContent { get; set; } + [Parameter] public bool IsDrawerOpen { get; set; } + [Parameter] public EventCallback BackdropFilterClicked { get; set; } + [Parameter] public bool Closable { get; set; } = true; + + private BackdropFilter.BackdropFilter? BackdropFilter; + public bool IsOpen { get; set; } + + protected override async Task OnParametersSetAsync() + { + await base.OnParametersSetAsync(); + if (BackdropFilter?.IsVisible == true && IsOpen) + { + await BackdropFilter.Hide(); + } + + if (BackdropFilter?.IsVisible == false && IsOpen) + { + await BackdropFilter.Show(); + } + } + + public async Task Open() + { + IsOpen = true; + await BackdropFilter?.Show()!; + StateHasChanged(); + } + + public async Task Close() + { + IsOpen = false; + await BackdropFilter?.Hide()!; + StateHasChanged(); + } + + private async Task HandleBackdropFilterClicked() + { + await BackdropFilterClicked.InvokeAsync(); + } + + private string GetDisplayStyle() => IsOpen ? "display: flex;" : "display: none;"; +} \ No newline at end of file diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Popup/Popup.razor.css b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Popup/Popup.razor.css new file mode 100644 index 0000000..dee8bf6 --- /dev/null +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Popup/Popup.razor.css @@ -0,0 +1,27 @@ +.popup-wrapper { + display: none; + justify-content: center; + align-items: center; + position: fixed; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + z-index: var(--index-popup); +} + +.popup-content { + position: relative; + background-color: var(--dropdown-content); + padding: 10px; + border-radius: var(--big-radius); + box-shadow: var(--drop-shadow); +} + +.popup-content button{ + top: 10px; + right: 10px; + position: absolute; + background: transparent; + border: none; + outline: none; +} diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Search/SearchInput.razor b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Search/SearchInput.razor index f94456b..91c332f 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Search/SearchInput.razor +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Search/SearchInput.razor @@ -1,4 +1,6 @@ -@using GameIdeas.Shared.Constants +@using GameIdeas.BlazorApp.Shared.Constants +@using GameIdeas.Shared.Constants +
- @ClearIcon + @Icons.Shared.Close;
} diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Search/SearchInput.razor.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Search/SearchInput.razor.cs index 5b8ddfd..3ee67df 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Search/SearchInput.razor.cs +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Search/SearchInput.razor.cs @@ -1,3 +1,4 @@ +using GameIdeas.BlazorApp.Shared.Constants; using GameIdeas.Shared.Constants; using Microsoft.AspNetCore.Components; @@ -14,7 +15,6 @@ public partial class SearchInput [Parameter] public SearchInputIcon Icon { get; set; } private ElementReference InputText; - private readonly MarkupString ClearIcon = new(Icons.Search.Clear); protected override void OnInitialized() { @@ -52,8 +52,8 @@ public partial class SearchInput { return Icon switch { - SearchInputIcon.Dropdown => new MarkupString(Icons.Search.Triangle), - SearchInputIcon.Search => new MarkupString(Icons.Search.Glass), + SearchInputIcon.Dropdown => Icons.Search.Triangle, + SearchInputIcon.Search => Icons.Search.Glass, _ => new MarkupString() }; } diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Select/SelectList.razor.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Select/SelectList.razor.cs index ffcd07b..375fa2f 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Select/SelectList.razor.cs +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Select/SelectList.razor.cs @@ -17,10 +17,11 @@ public partial class SelectList private bool IsContentOpen = false; - private void HandleButtonClicked() - { + public void Close() => + IsContentOpen = false; + + private void HandleButtonClicked() => IsContentOpen = !IsContentOpen; - } private void HandleContentClosed() { diff --git a/src/GameIdeas/GameIdeas.Shared/Constants/Icons.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Constants/Icons.cs similarity index 62% rename from src/GameIdeas/GameIdeas.Shared/Constants/Icons.cs rename to src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Constants/Icons.cs index 5c2f030..26ade56 100644 --- a/src/GameIdeas/GameIdeas.Shared/Constants/Icons.cs +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Constants/Icons.cs @@ -1,4 +1,6 @@ -namespace GameIdeas.Shared.Constants; +using Microsoft.AspNetCore.Components; + +namespace GameIdeas.BlazorApp.Shared.Constants; public static class Icons { @@ -8,16 +10,19 @@ public static class Icons public static class Search { - public const string Clear = OpenBraket + - "" + - CloseBraket; - - public const string Glass = OpenBraket + + public readonly static MarkupString Glass = new(OpenBraket + "" + - CloseBraket; + CloseBraket); - public const string Triangle = OpenBraket + + public readonly static MarkupString Triangle = new(OpenBraket + "" + - CloseBraket; + CloseBraket); + } + + public static class Shared + { + public readonly static MarkupString Close = new(OpenBraket + + "" + + CloseBraket); } } -- 2.39.5 From 4e687e87ee4fd53414cd2e56d78a4b87c6c06367 Mon Sep 17 00:00:00 2001 From: Egamorf Date: Sun, 13 Apr 2025 01:57:57 +0200 Subject: [PATCH 2/5] Add popup form --- .../Games/Components/GameCreationForm.razor | 50 +++++++++++++++++ .../Components/GameCreationForm.razor.cs | 28 ++++++++++ .../Components/GameCreationForm.razor.css | 54 +++++++++++++++++++ .../Components/GameCreationForm.razor.js | 10 ++++ .../Games/Filter/AdvancedGameFilter.razor | 8 +-- .../Pages/Games/Filter/GameFilter.razor | 4 +- .../Pages/Games/Filter/GameFilterParams.cs | 5 +- .../Pages/Games/GameBase.razor | 3 +- .../BackdropFilter/BackdropFilter.razor.css | 2 +- .../Shared/Components/Popup/Popup.razor.css | 20 +++++-- .../Components/Search/SearchInput.razor.css | 1 + .../Components/Select/Models/SelectTheme.cs | 3 +- .../Select/MultipleSelectList.razor.css | 14 +++-- .../GameIdeas.BlazorApp/wwwroot/index.html | 1 + .../CreateStaticResourceKey.cs | 16 ++++-- .../GameIdeas.WebAPI/Files/GameIdeas.fr.json | 8 ++- 16 files changed, 204 insertions(+), 23 deletions(-) create mode 100644 src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor create mode 100644 src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.cs create mode 100644 src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.css create mode 100644 src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.js diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor new file mode 100644 index 0000000..e755d54 --- /dev/null +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor @@ -0,0 +1,50 @@ +@using GameIdeas.BlazorApp.Shared.Components.Select +@using GameIdeas.Shared.Dto + + +
+
+
+
@ResourcesKey.Title :
+ +
+
+
@ResourcesKey.ReleaseDate :
+ +
+
+
@ResourcesKey.StorageSize :
+ +
+
+
@ResourcesKey.Developers :
+ +
+
+
@ResourcesKey.Publishers :
+ +
+
+
+
+
@ResourcesKey.Interest :
+
+
+
@ResourcesKey.Properties :
+ +
+
+
@ResourcesKey.Genres :
+ +
+
+
@ResourcesKey.Platforms :
+ +
+
+
+
+
@ResourcesKey.Description :
+ +
+
\ No newline at end of file diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.cs new file mode 100644 index 0000000..43baf8d --- /dev/null +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.cs @@ -0,0 +1,28 @@ +using GameIdeas.BlazorApp.Shared.Components.Select.Models; +using GameIdeas.Shared.Dto; +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Forms; +using Microsoft.JSInterop; + +namespace GameIdeas.BlazorApp.Pages.Games.Components; + +public partial class GameCreationForm +{ + [Inject] private IJSRuntime Js { get; set; } = default!; + + private GameDto GameDto = new(); + private EditContext? EditContext; + private readonly SelectListTheme SelectListTheme = SelectListTheme.Creation; + + protected override void OnInitialized() + { + EditContext = new(GameDto); + base.OnInitialized(); + } + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + await Js.InvokeVoidAsync("addResizeGameFormListener"); + await base.OnAfterRenderAsync(firstRender); + } +} \ No newline at end of file diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.css b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.css new file mode 100644 index 0000000..f9907c0 --- /dev/null +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.css @@ -0,0 +1,54 @@ +.game-form { + display: flex; + flex-direction: row; + gap: 20px; +} + +.container { + display: flex; + flex-direction: column; + gap: 8px; +} + +.input-game { + display: grid; + grid-template-columns: auto 200px; + grid-gap: 8px; + height: 24px; +} + +.label { + text-wrap: nowrap; + align-content: center; + font-weight: bold; + grid-column: 1; +} + +input { + width: 100%; + background: var(--input-secondary); + border: solid 1px var(--input-selected); + outline: none; + border-radius: var(--small-radius); + grid-column: 2; + box-sizing: border-box; + color: var(--white); +} + +.description-container { + margin-top: 8px; + display: grid; + grid-template-columns: auto 1fr; + grid-gap: 8px; +} + +.description { + min-height: 140px; +} + +#label-description { + text-wrap: nowrap; + align-content: center; + font-weight: bold; + height: 24px; +} \ No newline at end of file diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.js b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.js new file mode 100644 index 0000000..1d2ed31 --- /dev/null +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.js @@ -0,0 +1,10 @@ +function resizeFormContent() { + const label = document.getElementById('first-label'); + const targetLabel = document.getElementById('label-description'); + targetLabel.style.width = window.getComputedStyle(label).getPropertyValue("width"); +} + +window.addResizeGameFormListener = () => { + resizeFormContent(); + window.addEventListener('resize', resizeFormContent); +}; \ No newline at end of file diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/AdvancedGameFilter.razor b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/AdvancedGameFilter.razor index 5dab57c..b918a9f 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/AdvancedGameFilter.razor +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/AdvancedGameFilter.razor @@ -6,14 +6,14 @@
@@ -32,7 +32,7 @@ @@ -44,7 +44,7 @@ diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/GameFilter.razor b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/GameFilter.razor index 06a2942..25c16a0 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/GameFilter.razor +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/GameFilter.razor @@ -40,7 +40,7 @@
@@ -48,7 +48,7 @@ diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/GameFilterParams.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/GameFilterParams.cs index 4290ab3..5c5a65c 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/GameFilterParams.cs +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/GameFilterParams.cs @@ -8,8 +8,9 @@ public class GameFilterParams public SortType? SortType { get; set; } public Func? SortProperty { get; set; } public string? SearchName { get; set; } - public IEnumerable? Plateforms { get; set; } - public IEnumerable? Genres { get; set; } + public IEnumerable? Platforms { get; set; } + public IEnumerable? Properties { get; set; } + public IEnumerable? Tags { get; set; } public IEnumerable? Publishers { get; set; } public IEnumerable? Developers { get; set; } public IEnumerable? StorageSizes { get; set; } diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/GameBase.razor b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/GameBase.razor index 9a1cfc0..b72d4b0 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/GameBase.razor +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/GameBase.razor @@ -1,5 +1,6 @@ @page "/Games" @using GameIdeas.BlazorApp.Layouts +@using GameIdeas.BlazorApp.Pages.Games.Components @using GameIdeas.BlazorApp.Pages.Games.Filter @using GameIdeas.BlazorApp.Pages.Games.Header @using GameIdeas.BlazorApp.Shared.Components @@ -23,5 +24,5 @@ - + diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/BackdropFilter/BackdropFilter.razor.css b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/BackdropFilter/BackdropFilter.razor.css index 5d089d1..cb99b96 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/BackdropFilter/BackdropFilter.razor.css +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/BackdropFilter/BackdropFilter.razor.css @@ -5,7 +5,7 @@ } .backdrop-filter.overlay { - background-color: var(--grey-filter); + background-color: rgba(0, 0, 0, 0.2); } .backdrop-filter.transparent { diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Popup/Popup.razor.css b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Popup/Popup.razor.css index dee8bf6..66222e6 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Popup/Popup.razor.css +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Popup/Popup.razor.css @@ -17,11 +17,25 @@ box-shadow: var(--drop-shadow); } -.popup-content button{ - top: 10px; - right: 10px; +.popup-content button { + top: 4px; + right: 4px; position: absolute; background: transparent; border: none; outline: none; + padding: 0; + height: 20px; + width: 20px; +} + + .popup-content button svg { + height: 18px; + fill: var(--white); + } + +.popup-content button:hover { + cursor: pointer; + background: var(--input-selected); + border-radius: var(--small-radius); } diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Search/SearchInput.razor.css b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Search/SearchInput.razor.css index 01ca8c0..62963d5 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Search/SearchInput.razor.css +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Search/SearchInput.razor.css @@ -24,6 +24,7 @@ background: none !important; color: var(--white); height: 100%; + width: 100%; padding: 0; min-width: 0; } diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Select/Models/SelectTheme.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Select/Models/SelectTheme.cs index b045d58..df43019 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Select/Models/SelectTheme.cs +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Select/Models/SelectTheme.cs @@ -5,5 +5,6 @@ public enum SelectListTheme Navigation, Sort, Filter, - AdvancedFilter + AdvancedFilter, + Creation } diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Select/MultipleSelectList.razor.css b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Select/MultipleSelectList.razor.css index db31296..ab8485c 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Select/MultipleSelectList.razor.css +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Select/MultipleSelectList.razor.css @@ -30,14 +30,22 @@ margin: 2px 6px; border-bottom: 2px solid var(--input-selected); } - +/* Advanced filter */ ::deep .select-button.advancedfilter .search-container { height: 24px; background: var(--input-secondary); } -::deep .select-button.advancedfilter .search-container input::placeholder { - color: #bbb; + ::deep .select-button.advancedfilter .search-container input::placeholder { + color: #bbb; + } + +/* Creation */ +::deep .select-button.creation .search-container { + height: 24px; + background: var(--input-secondary); + border: solid 1px var(--input-selected); + box-sizing: border-box; } /* width */ diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/wwwroot/index.html b/src/GameIdeas/Client/GameIdeas.BlazorApp/wwwroot/index.html index 13a0479..bc8684e 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/wwwroot/index.html +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/wwwroot/index.html @@ -28,6 +28,7 @@ + diff --git a/src/GameIdeas/GameIdeas.Resources/CreateStaticResourceKey.cs b/src/GameIdeas/GameIdeas.Resources/CreateStaticResourceKey.cs index 46e8b34..76c8330 100644 --- a/src/GameIdeas/GameIdeas.Resources/CreateStaticResourceKey.cs +++ b/src/GameIdeas/GameIdeas.Resources/CreateStaticResourceKey.cs @@ -18,9 +18,13 @@ public class Translations (TranslationService translationService) public string Genres => translationService.Translate(nameof(Genres)); public string Publishers => translationService.Translate(nameof(Publishers)); public string Developers => translationService.Translate(nameof(Developers)); - public string StorageSizes => translationService.Translate(nameof(StorageSizes)); + public string StorageSize => translationService.Translate(nameof(StorageSize)); public string LastModification => translationService.Translate(nameof(LastModification)); - public string ReleaseDates => translationService.Translate(nameof(ReleaseDates)); + public string ReleaseDate => translationService.Translate(nameof(ReleaseDate)); + public string Title => translationService.Translate(nameof(Title)); + public string Interest => translationService.Translate(nameof(Interest)); + public string Properties => translationService.Translate(nameof(Properties)); + public string Description => translationService.Translate(nameof(Description)); } public static class ResourcesKey @@ -47,7 +51,11 @@ public static class ResourcesKey public static string Genres => _instance?.Genres ?? throw new InvalidOperationException("ResourcesKey.Genres is not initialized."); public static string Publishers => _instance?.Publishers ?? throw new InvalidOperationException("ResourcesKey.Publishers is not initialized."); public static string Developers => _instance?.Developers ?? throw new InvalidOperationException("ResourcesKey.Developers is not initialized."); - public static string StorageSizes => _instance?.StorageSizes ?? throw new InvalidOperationException("ResourcesKey.StorageSizes is not initialized."); + public static string StorageSize => _instance?.StorageSize ?? throw new InvalidOperationException("ResourcesKey.StorageSize is not initialized."); public static string LastModification => _instance?.LastModification ?? throw new InvalidOperationException("ResourcesKey.LastModification is not initialized."); - public static string ReleaseDates => _instance?.ReleaseDates ?? throw new InvalidOperationException("ResourcesKey.ReleaseDates is not initialized."); + public static string ReleaseDate => _instance?.ReleaseDate ?? throw new InvalidOperationException("ResourcesKey.ReleaseDate is not initialized."); + public static string Title => _instance?.Title ?? throw new InvalidOperationException("ResourcesKey.Title is not initialized."); + public static string Interest => _instance?.Interest ?? throw new InvalidOperationException("ResourcesKey.Interest is not initialized."); + public static string Properties => _instance?.Properties ?? throw new InvalidOperationException("ResourcesKey.Properties is not initialized."); + public static string Description => _instance?.Description ?? throw new InvalidOperationException("ResourcesKey.Description 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 e065f5e..95521b7 100644 --- a/src/GameIdeas/Server/GameIdeas.WebAPI/Files/GameIdeas.fr.json +++ b/src/GameIdeas/Server/GameIdeas.WebAPI/Files/GameIdeas.fr.json @@ -14,7 +14,11 @@ "Genres": "Genres", "Publishers": "Editeurs", "Developers": "Développeurs", - "StorageSizes": "Taille d'espace", + "StorageSize": "Taille d'espace", "LastModification": "Dernière modifications", - "ReleaseDates": "Dates de parution" + "ReleaseDate": "Date de parution", + "Title": "Titre", + "Interest": "Intérêt", + "Properties": "Propriétés", + "Description": "Description" } \ No newline at end of file -- 2.39.5 From b8eed9b0d7957378255cf42a2675ce6a2cda65cd Mon Sep 17 00:00:00 2001 From: Egamorf Date: Sun, 13 Apr 2025 13:37:03 +0200 Subject: [PATCH 3/5] Fix form sizing --- .../Components/GameCreationForm.razor.cs | 12 ++++++++--- .../Components/GameCreationForm.razor.css | 5 +++++ .../Components/GameCreationForm.razor.js | 7 +------ .../Shared/Components/Popup/Popup.razor | 21 +++++++++++-------- .../Shared/Components/Popup/Popup.razor.cs | 5 ++++- .../Shared/Components/Popup/Popup.razor.css | 2 +- 6 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.cs index 43baf8d..edf6d17 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.cs +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.cs @@ -1,3 +1,4 @@ +using GameIdeas.BlazorApp.Shared.Components.Popup; using GameIdeas.BlazorApp.Shared.Components.Select.Models; using GameIdeas.Shared.Dto; using Microsoft.AspNetCore.Components; @@ -9,6 +10,7 @@ namespace GameIdeas.BlazorApp.Pages.Games.Components; public partial class GameCreationForm { [Inject] private IJSRuntime Js { get; set; } = default!; + [CascadingParameter] private Popup? Popup { get; set; } private GameDto GameDto = new(); private EditContext? EditContext; @@ -17,12 +19,16 @@ public partial class GameCreationForm protected override void OnInitialized() { EditContext = new(GameDto); + if (Popup != null) + { + Popup.StateChanged += async (_, isOpen) => await HandlePopupStateChanged(); + } + base.OnInitialized(); } - protected override async Task OnAfterRenderAsync(bool firstRender) + private async Task HandlePopupStateChanged() { - await Js.InvokeVoidAsync("addResizeGameFormListener"); - await base.OnAfterRenderAsync(firstRender); + await Js.InvokeVoidAsync("resizeGameForm"); } } \ No newline at end of file diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.css b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.css index f9907c0..87a6bcd 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.css +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.css @@ -35,6 +35,11 @@ input { color: var(--white); } + input[type="date"]::-webkit-calendar-picker-indicator { + filter: invert(1); + cursor: pointer; + } + .description-container { margin-top: 8px; display: grid; diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.js b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.js index 1d2ed31..ab5b850 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.js +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.js @@ -1,10 +1,5 @@ -function resizeFormContent() { +window.resizeGameForm = () => { const label = document.getElementById('first-label'); const targetLabel = document.getElementById('label-description'); targetLabel.style.width = window.getComputedStyle(label).getPropertyValue("width"); -} - -window.addResizeGameFormListener = () => { - resizeFormContent(); - window.addEventListener('resize', resizeFormContent); }; \ No newline at end of file diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Popup/Popup.razor b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Popup/Popup.razor index cc66ca4..794bb5e 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Popup/Popup.razor +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Popup/Popup.razor @@ -1,15 +1,18 @@ @using GameIdeas.BlazorApp.Shared.Components.BackdropFilter @using GameIdeas.BlazorApp.Shared.Constants - + + + + \ No newline at end of file diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Popup/Popup.razor.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Popup/Popup.razor.cs index 2b18c50..af8af70 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Popup/Popup.razor.cs +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Popup/Popup.razor.cs @@ -8,9 +8,10 @@ public partial class Popup [Parameter] public bool IsDrawerOpen { get; set; } [Parameter] public EventCallback BackdropFilterClicked { get; set; } [Parameter] public bool Closable { get; set; } = true; + public bool IsOpen { get; set; } + public EventHandler? StateChanged { get; set; } private BackdropFilter.BackdropFilter? BackdropFilter; - public bool IsOpen { get; set; } protected override async Task OnParametersSetAsync() { @@ -30,6 +31,7 @@ public partial class Popup { IsOpen = true; await BackdropFilter?.Show()!; + StateChanged?.Invoke(null, IsOpen); StateHasChanged(); } @@ -37,6 +39,7 @@ public partial class Popup { IsOpen = false; await BackdropFilter?.Hide()!; + StateChanged?.Invoke(null, IsOpen); StateHasChanged(); } diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Popup/Popup.razor.css b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Popup/Popup.razor.css index 66222e6..754be81 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Popup/Popup.razor.css +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Popup/Popup.razor.css @@ -29,7 +29,7 @@ width: 20px; } - .popup-content button svg { + ::deep .popup-content button svg { height: 18px; fill: var(--white); } -- 2.39.5 From 0fb5f8d682733d1153cb9d6661240bdee5438039 Mon Sep 17 00:00:00 2001 From: Egamorf Date: Sun, 13 Apr 2025 14:28:44 +0200 Subject: [PATCH 4/5] Add slider to form --- .../GameIdeas.BlazorApp.csproj | 2 +- .../Layouts/MainLayout.razor | 10 +-- .../Layouts/MainLayout.razor.css | 5 +- .../Games/Components/GameCreationForm.razor | 4 + .../Components/GameCreationForm.razor.cs | 2 + .../Components/GameCreationForm.razor.css | 5 ++ .../Pages/Games/Filter/GameFilter.razor | 4 +- .../Pages/Games/Filter/GameFilter.razor.cs | 2 +- .../Pages/Games/Filter/GameFilterParams.cs | 4 +- .../Shared/Components/Slider/Slider.razor | 11 +++ .../Shared/Components/Slider/Slider.razor.cs | 30 +++++++ .../Shared/Components/Slider/Slider.razor.css | 89 +++++++++++++++++++ .../Shared/Components/Slider/SliderParams.cs | 8 ++ .../Components/SliderRange/SliderRange.razor | 12 +-- .../SliderRange/SliderRange.razor.cs | 18 ++-- .../SliderRange/SliderRangeParams.cs | 2 - .../GameIdeas.BlazorApp/wwwroot/css/app.css | 1 - src/GameIdeas/GameIdeas.Shared/Dto/GameDto.cs | 4 +- 18 files changed, 179 insertions(+), 34 deletions(-) create mode 100644 src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Slider/Slider.razor create mode 100644 src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Slider/Slider.razor.cs create mode 100644 src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Slider/Slider.razor.css create mode 100644 src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Slider/SliderParams.cs diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/GameIdeas.BlazorApp.csproj b/src/GameIdeas/Client/GameIdeas.BlazorApp/GameIdeas.BlazorApp.csproj index 0388002..4595e9d 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/GameIdeas.BlazorApp.csproj +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/GameIdeas.BlazorApp.csproj @@ -1,4 +1,4 @@ - + net9.0 diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Layouts/MainLayout.razor b/src/GameIdeas/Client/GameIdeas.BlazorApp/Layouts/MainLayout.razor index 81e4bfe..8b1aa4e 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Layouts/MainLayout.razor +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Layouts/MainLayout.razor @@ -5,8 +5,8 @@ @Body - - - - -
\ No newline at end of file +
+ + + +
\ No newline at end of file diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Layouts/MainLayout.razor.css b/src/GameIdeas/Client/GameIdeas.BlazorApp/Layouts/MainLayout.razor.css index 407f5bd..60ead01 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Layouts/MainLayout.razor.css +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Layouts/MainLayout.razor.css @@ -37,10 +37,11 @@ } .background { - height: 100%; - width: 100%; + height: 100vh; + width: 100vw; background: var(--background); position: fixed; + overflow: hidden; top: 0; left: 0; z-index: var(--index-background); diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor index e755d54..f639a03 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor @@ -1,4 +1,5 @@ @using GameIdeas.BlazorApp.Shared.Components.Select +@using GameIdeas.BlazorApp.Shared.Components.Slider @using GameIdeas.Shared.Dto @@ -28,6 +29,9 @@
@ResourcesKey.Interest :
+
+ +
@ResourcesKey.Properties :
diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.cs index edf6d17..4462f53 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.cs +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.cs @@ -1,5 +1,6 @@ using GameIdeas.BlazorApp.Shared.Components.Popup; using GameIdeas.BlazorApp.Shared.Components.Select.Models; +using GameIdeas.BlazorApp.Shared.Components.Slider; using GameIdeas.Shared.Dto; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Forms; @@ -15,6 +16,7 @@ public partial class GameCreationForm private GameDto GameDto = new(); private EditContext? EditContext; private readonly SelectListTheme SelectListTheme = SelectListTheme.Creation; + private readonly SliderParams SliderParams = new() { Gap = 1, Min = 1, Max = 5 }; protected override void OnInitialized() { diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.css b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.css index 87a6bcd..7e0f33a 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.css +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.css @@ -56,4 +56,9 @@ input { align-content: center; font-weight: bold; height: 24px; +} + +.slider { + padding: 0 20px; + align-content: center; } \ No newline at end of file diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/GameFilter.razor b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/GameFilter.razor index 25c16a0..48fca5e 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/GameFilter.razor +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/GameFilter.razor @@ -54,8 +54,8 @@
+ @bind-Max=GameFilterParams.MaxRating + @bind-Min=GameFilterParams.MinRating />
diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/GameFilter.razor.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/GameFilter.razor.cs index 49d7461..b97008c 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/GameFilter.razor.cs +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/GameFilter.razor.cs @@ -41,7 +41,7 @@ public partial class GameFilter private EditContext? EditContext; private readonly SliderRangeParams SliderRangeParams = - new() { Min = 1, ValueMin = 1, ValueMax = 5, Max = 5 }; + new() { Min = 1, Max = 5 }; protected override void OnInitialized() { diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/GameFilterParams.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/GameFilterParams.cs index 5c5a65c..77b9354 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/GameFilterParams.cs +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/GameFilterParams.cs @@ -16,6 +16,6 @@ public class GameFilterParams public IEnumerable? StorageSizes { get; set; } public IEnumerable? LastModification { get; set; } public IEnumerable? ReleaseDates { get; set; } - public int MaxRating { get; set; } - public int MinRating { get; set; } + public int MaxRating { get; set; } = 5; + public int MinRating { get; set; } = 1; } diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Slider/Slider.razor b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Slider/Slider.razor new file mode 100644 index 0000000..d4db8aa --- /dev/null +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Slider/Slider.razor @@ -0,0 +1,11 @@ +
+
+ + + +
+ @Params.Min + @Params.Max +
+
diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Slider/Slider.razor.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Slider/Slider.razor.cs new file mode 100644 index 0000000..007bf0a --- /dev/null +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Slider/Slider.razor.cs @@ -0,0 +1,30 @@ +using Microsoft.AspNetCore.Components; + +namespace GameIdeas.BlazorApp.Shared.Components.Slider; + +public partial class Slider +{ + [Parameter] public SliderParams Params { get; set; } = new(); + [Parameter] public int Value { get; set; } + [Parameter] public EventCallback ValueChanged { get; set; } + + private async Task HandleSlideOnInput() + { + await ValueChanged.InvokeAsync(Value); + } + + private string StatusColor(int value) + { + string str = "--thumb-color: var({0});"; + + int firstTier = (int)Math.Floor(0.33 * Params.Max); + int secondTier = (int)Math.Ceiling(0.66 * Params.Max); + + return value switch + { + int x when x <= firstTier => string.Format(str, "--red"), + int x when x >= secondTier => string.Format(str, "--green"), + _ => string.Format(str, "--yellow"), + }; + } +} \ No newline at end of file diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Slider/Slider.razor.css b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Slider/Slider.razor.css new file mode 100644 index 0000000..5954b37 --- /dev/null +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Slider/Slider.razor.css @@ -0,0 +1,89 @@ +.container { + position: relative; + width: 100%; + z-index: var(--index-component) +} + +input[type="range"] { + -webkit-appearance: none; + -moz-appearance: none; + appearance: none; + width: 100%; + outline: none; + margin: auto; + position: absolute; + top: 0; + bottom: 0; + background-color: transparent; + pointer-events: none; +} + +.slider-track { + width: 100%; + height: 2px; + margin: auto; + border-radius: 2px; + background: var(--input-primary); + +} + +input[type="range"]::-webkit-slider-runnable-track { + -webkit-appearance: none; + height: 2px; +} + +input[type="range"]::-moz-range-track { + -moz-appearance: none; + height: 2px; +} + +input[type="range"]::-ms-track { + appearance: none; + height: 2px; +} + +input[type="range"]::-webkit-slider-thumb { + -webkit-appearance: none; + height: 1em; + width: 1em; + background-color: var(--thumb-color); + cursor: pointer; + margin-top: -6px; + pointer-events: auto; + border-radius: 50%; +} + +input[type="range"]::-moz-range-thumb { + -webkit-appearance: none; + height: 1em; + width: 1em; + cursor: pointer; + border-radius: 50%; + background-color: var(--thumb-color); + pointer-events: auto; + border: none; +} + +input[type="range"]::-ms-thumb { + appearance: none; + height: 1em; + width: 1em; + cursor: pointer; + border-radius: 50%; + background-color: var(--thumb-color); + pointer-events: auto; +} + +.values { + display: flex; + position: absolute; + margin-top: 2px; + width: 100%; + font-weight: bold; + justify-content: space-between; +} + +.value { + width: 1em; + text-align:center; +} diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Slider/SliderParams.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Slider/SliderParams.cs new file mode 100644 index 0000000..5ba67e0 --- /dev/null +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Slider/SliderParams.cs @@ -0,0 +1,8 @@ +namespace GameIdeas.BlazorApp.Shared.Components.Slider; + +public class SliderParams +{ + public int Min{ get; set; } + public int Max { get; set; } + public int Gap { get; set; } = 0; +} diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/SliderRange/SliderRange.razor b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/SliderRange/SliderRange.razor index f0eb5ab..ca54e27 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/SliderRange/SliderRange.razor +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/SliderRange/SliderRange.razor @@ -1,13 +1,13 @@ 
- - + +
- @Params.ValueMin - @Params.ValueMax + @Min + @Max
diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/SliderRange/SliderRange.razor.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/SliderRange/SliderRange.razor.cs index 41841cb..2fee237 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/SliderRange/SliderRange.razor.cs +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/SliderRange/SliderRange.razor.cs @@ -13,30 +13,28 @@ public partial class SliderRange private async Task HandleSlideTwoInput() { - if (Params.ValueMax - Params.ValueMin <= Params.Gap) + if (Max - Min <= Params.Gap) { - Params.ValueMin = Params.ValueMax - Params.Gap; + Min = Max - Params.Gap; } - Max = Params.Max; - await MaxChanged.InvokeAsync(Params.Max); + await MaxChanged.InvokeAsync(Max); } private async Task HandleSlideOnInput() { - if (Params.ValueMax - Params.ValueMin <= Params.Gap) + if (Max - Min <= Params.Gap) { - Params.ValueMax = Params.ValueMin + Params.Gap; + Max = Min + Params.Gap; } - Min = Params.Min; - await MinChanged.InvokeAsync(Params.Min); + await MinChanged.InvokeAsync(Min); } private string FillColor() { - var percent1 = (double)(Params.ValueMin - Params.Min) / (Params.Max - Params.Min) * 100; - var percent2 = (double)(Params.ValueMax - Params.Min) / (Params.Max - Params.Min) * 100; + var percent1 = (double)(Min - Params.Min) / (Params.Max - Params.Min) * 100; + var percent2 = (double)(Max - Params.Min) / (Params.Max - Params.Min) * 100; return $"background: linear-gradient(to right, var(--line) {percent1}% , var(--violet) {percent1}% , var(--violet) {percent2}%, var(--line) {percent2}%)"; } diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/SliderRange/SliderRangeParams.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/SliderRange/SliderRangeParams.cs index b82f00b..7b65539 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/SliderRange/SliderRangeParams.cs +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/SliderRange/SliderRangeParams.cs @@ -4,7 +4,5 @@ public class SliderRangeParams { public int Min{ get; set; } public int Max { get; set; } - public int ValueMin { get; set; } - public int ValueMax { get; set; } public int Gap { get; set; } = 0; } diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/wwwroot/css/app.css b/src/GameIdeas/Client/GameIdeas.BlazorApp/wwwroot/css/app.css index 54720d9..7580dab 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/wwwroot/css/app.css +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/wwwroot/css/app.css @@ -33,7 +33,6 @@ html { font-family: 'Noto Sans', sans-serif; font-size: 12px; color: var(--white); - overflow: hidden; } html, body, #app { diff --git a/src/GameIdeas/GameIdeas.Shared/Dto/GameDto.cs b/src/GameIdeas/GameIdeas.Shared/Dto/GameDto.cs index 44e685b..7917133 100644 --- a/src/GameIdeas/GameIdeas.Shared/Dto/GameDto.cs +++ b/src/GameIdeas/GameIdeas.Shared/Dto/GameDto.cs @@ -7,13 +7,13 @@ public class GameDto public DateTime? ReleaseDate { get; set; } public DateTime? CreationDate { get; set; } public UserDto? CreationUser { get; set; } - public int? CreationUserId { get; set; } + public int CreationUserId { get; set; } public DateTime? ModificationDate { get; set; } public UserDto? ModificationUser { get; set; } public int? ModificationUserId { get; set; } public double? StorageSpace { get; set; } public string? Description { get; set; } - public int? Interest { get; set; } + public int Interest { get; set; } = 3; public IEnumerable? Platforms { get; set; } public IEnumerable? Properties { get; set; } public IEnumerable? Tags { get; set; } -- 2.39.5 From 7e66e695825f2790447c6a275eba8d4cbdf0015c Mon Sep 17 00:00:00 2001 From: Egamorf Date: Sun, 13 Apr 2025 17:10:42 +0200 Subject: [PATCH 5/5] Fetch all categories for creation --- .../GameIdeas.BlazorApp.csproj | 2 +- .../Games/Components/GameCreationForm.razor | 35 +++-- .../Components/GameCreationForm.razor.cs | 24 +++- .../Components/GameCreationForm.razor.css | 4 + .../Games/Filter/AdvancedGameFilter.razor | 7 - .../Games/Filter/AdvancedGameFilter.razor.cs | 52 -------- .../Pages/Games/Filter/GameFilter.razor | 12 +- .../Pages/Games/Filter/GameFilter.razor.cs | 29 +--- .../Pages/Games/Filter/GameFilterParams.cs | 2 +- .../Pages/Games/Gateways/GameGateway.cs | 24 ++++ .../Pages/Games/Gateways/IGameGateway.cs | 8 ++ .../Pages/Games/Header/GameHeader.razor | 2 +- .../Pages/Games/Header/GameHeader.razor.cs | 6 +- .../Client/GameIdeas.BlazorApp/Program.cs | 4 +- .../Services/AuthentificationService.cs | 21 --- .../Services/HttpClientService.cs | 125 ++++++++++++++++++ .../Services/IHttpClientService.cs | 12 ++ .../Components/Account/AccountSettings.razor | 2 +- .../Account/AccountSettings.razor.cs | 16 +-- .../Components/Select/Models/SelectElement.cs | 6 +- .../Shared/Components/Select/SelectList.razor | 9 +- .../Components/Select/SelectList.razor.cs | 10 +- .../Shared/Constants/Endpoints.cs | 14 ++ .../Exceptions/CategoryNotFoundException.cs | 3 + .../CreateStaticResourceKey.cs | 18 +++ .../GameIdeas.Shared/Dto/CategoriesDto.cs | 10 ++ .../Controllers/CategoryController.cs | 26 ++++ .../Controllers/GameController.cs | 4 +- .../GameIdeas.WebAPI/Files/GameIdeas.fr.json | 11 +- .../Server/GameIdeas.WebAPI/Program.cs | 8 +- .../Services/CategoryService.cs | 28 ++++ .../GameIdeas.WebAPI/Services/GameService.cs | 3 +- .../Services/Interfaces/ICategoryService.cs | 8 ++ .../Services/Interfaces/IGameService.cs | 12 ++ .../GameIdeas.WebAPI/Services/UserService.cs | 5 - 35 files changed, 392 insertions(+), 170 deletions(-) create mode 100644 src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Gateways/GameGateway.cs create mode 100644 src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Gateways/IGameGateway.cs delete mode 100644 src/GameIdeas/Client/GameIdeas.BlazorApp/Services/AuthentificationService.cs create mode 100644 src/GameIdeas/Client/GameIdeas.BlazorApp/Services/HttpClientService.cs create mode 100644 src/GameIdeas/Client/GameIdeas.BlazorApp/Services/IHttpClientService.cs create mode 100644 src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Constants/Endpoints.cs create mode 100644 src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Exceptions/CategoryNotFoundException.cs create mode 100644 src/GameIdeas/GameIdeas.Shared/Dto/CategoriesDto.cs create mode 100644 src/GameIdeas/Server/GameIdeas.WebAPI/Controllers/CategoryController.cs create mode 100644 src/GameIdeas/Server/GameIdeas.WebAPI/Services/CategoryService.cs create mode 100644 src/GameIdeas/Server/GameIdeas.WebAPI/Services/Interfaces/ICategoryService.cs create mode 100644 src/GameIdeas/Server/GameIdeas.WebAPI/Services/Interfaces/IGameService.cs delete mode 100644 src/GameIdeas/Server/GameIdeas.WebAPI/Services/UserService.cs diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/GameIdeas.BlazorApp.csproj b/src/GameIdeas/Client/GameIdeas.BlazorApp/GameIdeas.BlazorApp.csproj index 4595e9d..0388002 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/GameIdeas.BlazorApp.csproj +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/GameIdeas.BlazorApp.csproj @@ -1,4 +1,4 @@ - + net9.0 diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor index f639a03..7354efa 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor @@ -1,29 +1,32 @@ @using GameIdeas.BlazorApp.Shared.Components.Select +@using GameIdeas.BlazorApp.Shared.Components.Select.Models @using GameIdeas.BlazorApp.Shared.Components.Slider @using GameIdeas.Shared.Dto - +
@ResourcesKey.Title :
- +
@ResourcesKey.ReleaseDate :
- +
-
@ResourcesKey.StorageSize :
- +
@ResourcesKey.StorageSizeMo :
+
@ResourcesKey.Developers :
- +
@ResourcesKey.Publishers :
- +
@@ -35,15 +38,19 @@
@ResourcesKey.Properties :
- +
@ResourcesKey.Genres :
- + +
@ResourcesKey.Platforms :
- +
@@ -51,4 +58,12 @@
@ResourcesKey.Description :
+
+ + +
\ No newline at end of file diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.cs index 4462f53..97c0854 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.cs +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.cs @@ -1,3 +1,4 @@ +using GameIdeas.BlazorApp.Pages.Games.Gateways; using GameIdeas.BlazorApp.Shared.Components.Popup; using GameIdeas.BlazorApp.Shared.Components.Select.Models; using GameIdeas.BlazorApp.Shared.Components.Slider; @@ -11,26 +12,45 @@ namespace GameIdeas.BlazorApp.Pages.Games.Components; public partial class GameCreationForm { [Inject] private IJSRuntime Js { get; set; } = default!; + [Inject] private IGameGateway GameGateway { get; set; } = default!; [CascadingParameter] private Popup? Popup { get; set; } private GameDto GameDto = new(); + private CategoriesDto CategoriesDto = new(); private EditContext? EditContext; private readonly SelectListTheme SelectListTheme = SelectListTheme.Creation; private readonly SliderParams SliderParams = new() { Gap = 1, Min = 1, Max = 5 }; - protected override void OnInitialized() + protected override async Task OnInitializedAsync() { EditContext = new(GameDto); + CategoriesDto = await GameGateway.FetchCategories(); + if (Popup != null) { Popup.StateChanged += async (_, isOpen) => await HandlePopupStateChanged(); } - base.OnInitialized(); + await base.OnInitializedAsync(); } private async Task HandlePopupStateChanged() { await Js.InvokeVoidAsync("resizeGameForm"); } + + private void HandleOnCancel() + { + Popup?.Close(); + } + + private async Task HandleOnSubmit(EditContext args) + { + if (EditContext?.Validate() == false) + { + return; + } + + + } } \ No newline at end of file diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.css b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.css index 7e0f33a..b28e0a8 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.css +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameCreationForm.razor.css @@ -61,4 +61,8 @@ input { .slider { padding: 0 20px; align-content: center; +} + +input[type="number"]::-webkit-inner-spin-button { + -webkit-appearance: none; } \ No newline at end of file diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/AdvancedGameFilter.razor b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/AdvancedGameFilter.razor index b918a9f..8c1dd8f 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/AdvancedGameFilter.razor +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/AdvancedGameFilter.razor @@ -5,13 +5,11 @@
@@ -19,31 +17,26 @@ diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/AdvancedGameFilter.razor.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/AdvancedGameFilter.razor.cs index dfa5e1b..cb74ed4 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/AdvancedGameFilter.razor.cs +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/AdvancedGameFilter.razor.cs @@ -7,56 +7,4 @@ public partial class AdvancedGameFilter { [Parameter] public GameFilterParams? GameFilterParams { get; set; } [Parameter] public EventCallback GameFilterParamsChanged { get; set; } - - - private readonly IEnumerable> Plateforms = [ - new() { Item = "Steam", Label = "Steam" }, - new() { Item = "GOG", Label = "GOG" }, - new() { Item = "Epic games", Label = "Epic games" }, - new() { Item = "Ubisoft", Label = "Ubisoft" }, - ]; - - private readonly IEnumerable> Genres = [ - new() { Item = "Rogue Like", Label = "Rogue Like" }, - new() { Item = "Aventure", Label = "Aventure" }, - new() { Item = "RPG", Label = "RPG" }, - new() { Item = "Fast FPS", Label = "Fast FPS" }, - ]; - - private readonly IEnumerable> Publishers = [ - new() { Item = "Electronic Arts", Label = "Electronic Arts" }, - new() { Item = "Ubisoft", Label = "Ubisoft" }, - new() { Item = "Activision Blizzard", Label = "Activision Blizzard" }, - new() { Item = "Bethesda", Label = "Bethesda" } - ]; - - private readonly IEnumerable> Developers = [ - new() { Item = "CD Projekt Red", Label = "CD Projekt Red" }, - new() { Item = "Naughty Dog", Label = "Naughty Dog" }, - new() { Item = "Rockstar Games", Label = "Rockstar Games" }, - new() { Item = "FromSoftware", Label = "FromSoftware" }, - ]; - - private readonly IEnumerable> StorageSizes = [ - new() { Item = "1 Go", Label = "1 Go" }, - new() { Item = "10 Go", Label = "10 Go" }, - new() { Item = "50 Go", Label = "50 Go" }, - new() { Item = "100 Go", Label = "100 Go" }, - ]; - - private readonly IEnumerable> LastModifiedDates = [ - new() { Item = "2023-12-15", Label = "15 Décembre 2023" }, - new() { Item = "2024-01-20", Label = "20 Janvier 2024" }, - new() { Item = "2024-02-05", Label = "5 Février 2024" }, - new() { Item = "2024-03-10", Label = "10 Mars 2024" }, - ]; - - private readonly IEnumerable> ReleaseDates = [ - new() { Item = "2023-11-11", Label = "11 Novembre 2023" }, - new() { Item = "2024-01-25", Label = "25 Janvier 2024" }, - new() { Item = "2024-03-03", Label = "3 Mars 2024" }, - new() { Item = "2024-04-15", Label = "15 Avril 2024" }, - ]; - - } \ No newline at end of file diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/GameFilter.razor b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/GameFilter.razor index 48fca5e..414cda9 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/GameFilter.razor +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/GameFilter.razor @@ -4,13 +4,13 @@ @using GameIdeas.BlazorApp.Shared.Components.SliderRange @using GameIdeas.BlazorApp.Shared.Models @using GameIdeas.Shared.Dto +@using GameIdeas.Shared.Enum
-
@@ -38,7 +38,6 @@
@@ -46,7 +45,6 @@
diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/GameFilter.razor.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/GameFilter.razor.cs index b97008c..8ffe951 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/GameFilter.razor.cs +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/GameFilter.razor.cs @@ -15,28 +15,14 @@ public partial class GameFilter [Parameter] public DisplayType DisplayType { get; set; } [Parameter] public EventCallback DisplayTypeChanged { get; set; } - private readonly IEnumerable>> SortTypes = [ - new() { Item = _ => SortType.Ascending, Label = "Ascendant", IsSelected = true }, - new() { Item = _ => SortType.Descending, Label = "Descendant" } + private readonly IEnumerable> SortTypes = [ + new(SortType.Ascending, "Ascendant") { IsSelected = true }, + new(SortType.Descending, "Descendant") ]; private readonly IEnumerable>> GameProperties = [ - new() { Item = game => game?.Title, Label = "Nom", IsSelected = true }, - new() { Item = game => game?.ReleaseDate, Label = "Date de parution" } - ]; - - private readonly IEnumerable> Plateforms = [ - new() { Item = "Steam", Label = "Steam" }, - new() { Item = "GOG", Label = "GOG" }, - new() { Item = "Epic games", Label = "Epic games" }, - new() { Item = "Ubisoft", Label = "Ubisoft" }, - ]; - - private readonly IEnumerable> Genres = [ - new() { Item = "Rogue Like", Label = "Rogue Like" }, - new() { Item = "Aventure", Label = "Aventure" }, - new() { Item = "RPG", Label = "RPG" }, - new() { Item = "Fast FPS", Label = "Fast FPS" }, + new(game => game?.Title, "Nom") { IsSelected = true }, + new(game => game?.ReleaseDate, "Date de parution"), ]; private EditContext? EditContext; @@ -52,11 +38,6 @@ public partial class GameFilter }; } - private void HandleSortTypeChanged(Func getHeader) - { - GameFilterParams.SortType = (SortType?)getHeader(null) ?? SortType.Ascending; - } - private async Task HandleDisplayClicked(DisplayType displayType) { DisplayType = displayType; diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/GameFilterParams.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/GameFilterParams.cs index 77b9354..d95d5c4 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/GameFilterParams.cs +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Filter/GameFilterParams.cs @@ -5,7 +5,7 @@ namespace GameIdeas.BlazorApp.Pages.Games.Filter; public class GameFilterParams { - public SortType? SortType { get; set; } + public SortType SortType { get; set; } = SortType.Ascending; public Func? SortProperty { get; set; } public string? SearchName { get; set; } public IEnumerable? Platforms { get; set; } diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Gateways/GameGateway.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Gateways/GameGateway.cs new file mode 100644 index 0000000..92af68b --- /dev/null +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Gateways/GameGateway.cs @@ -0,0 +1,24 @@ +using GameIdeas.BlazorApp.Services; +using GameIdeas.BlazorApp.Shared.Constants; +using GameIdeas.BlazorApp.Shared.Exceptions; +using GameIdeas.Resources; +using GameIdeas.Shared.Dto; + +namespace GameIdeas.BlazorApp.Pages.Games.Gateways; + +public class GameGateway(IHttpClientService httpClientService) : IGameGateway +{ + public async Task FetchCategories() + { + try + { + var result = await httpClientService.FetchDataAsync(Endpoints.Category.AllCategories); + + return result ?? throw new InvalidOperationException(ResourcesKey.ErrorFetchCategories); + } + catch (Exception) + { + throw new CategoryNotFoundException(ResourcesKey.ErrorFetchCategories); + } + } +} diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Gateways/IGameGateway.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Gateways/IGameGateway.cs new file mode 100644 index 0000000..7d71440 --- /dev/null +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Gateways/IGameGateway.cs @@ -0,0 +1,8 @@ +using GameIdeas.Shared.Dto; + +namespace GameIdeas.BlazorApp.Pages.Games.Gateways; + +public interface IGameGateway +{ + Task FetchCategories(); +} diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Header/GameHeader.razor b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Header/GameHeader.razor index c948e2d..515e557 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Header/GameHeader.razor +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Header/GameHeader.razor @@ -23,7 +23,7 @@
diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Header/GameHeader.razor.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Header/GameHeader.razor.cs index 0f5f2d9..936b5bc 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Header/GameHeader.razor.cs +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Header/GameHeader.razor.cs @@ -14,12 +14,12 @@ public partial class GameHeader : ComponentBase private readonly IEnumerable> SelectElements = [ - new SelectElement { Item = AddType.Manual, Label = ResourcesKey.ManualAdd }, - new SelectElement { Item = AddType.Auto, Label = ResourcesKey.AutoAdd } + new SelectElement(AddType.Manual, ResourcesKey.ManualAdd), + new SelectElement (AddType.Auto, ResourcesKey.AutoAdd) ]; private AccountSettings? AccountSettings; - private SelectList? SelectListAdd; + private SelectList? SelectListAdd; private void HandleIconClicked() { diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Program.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Program.cs index e35dffa..98b893b 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Program.cs +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Program.cs @@ -1,5 +1,6 @@ using System.Net.Http.Json; using GameIdeas.BlazorApp; +using GameIdeas.BlazorApp.Pages.Games.Gateways; using GameIdeas.BlazorApp.Services; using GameIdeas.Resources; using Microsoft.AspNetCore.Components.Web; @@ -22,7 +23,8 @@ builder.Services.AddHttpClient( client.Timeout = TimeSpan.FromMinutes(3); }); -builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Services/AuthentificationService.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Services/AuthentificationService.cs deleted file mode 100644 index 380b679..0000000 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Services/AuthentificationService.cs +++ /dev/null @@ -1,21 +0,0 @@ -namespace GameIdeas.BlazorApp.Services; - -public class AuthentificationService -{ - private bool isLogin; - - public bool IsLogin - { - get { return isLogin; } - } - - public void Login() - { - isLogin = true; - } - - public void Logout() - { - isLogin = false; - } -} diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Services/HttpClientService.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Services/HttpClientService.cs new file mode 100644 index 0000000..f0c39ac --- /dev/null +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Services/HttpClientService.cs @@ -0,0 +1,125 @@ +using GameIdeas.Resources; +using System.Net.Http.Headers; +using System.Text.Json.Serialization; +using System.Text.Json; +using System.Text; + +namespace GameIdeas.BlazorApp.Services; + +public class HttpClientService(IHttpClientFactory httpClientFactory, ILoggerFactory loggerFactory) : IHttpClientService +{ + private readonly HttpClient httpClient = httpClientFactory.CreateClient("GameIdeas.WebAPI"); + private readonly ILogger logger = loggerFactory.CreateLogger(); + + private readonly JsonSerializerOptions _optionsCamelCase = new() + { + PropertyNamingPolicy = JsonNamingPolicy.CamelCase, + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault + }; + + private readonly JsonSerializerOptions _optionsCaseInsensitive = new() + { + PropertyNameCaseInsensitive = true, + ReferenceHandler = ReferenceHandler.Preserve + }; + + public async Task PostAsync(string url, object data) + { + var jsonContent = JsonSerializer.Serialize(data, _optionsCamelCase); + var content = new StringContent(jsonContent, Encoding.UTF8, "application/json"); + var response = await httpClient.PostAsync(url, content); + + return await GetResultValue(response, ResourcesKey.ErrorWhenPostingData); + } + + public async Task PutAsync(string url, object data) + { + var jsonContent = JsonSerializer.Serialize(data, _optionsCamelCase); + var content = new StringContent(jsonContent, Encoding.UTF8, "application/json"); + var response = await httpClient.PutAsync(url, content); + + return await GetResultValue(response, ResourcesKey.ErrorWhenPutingData); + } + + public async Task DeleteAsync(string? url) + { + var response = await httpClient.DeleteAsync(url); + + return await GetResultValue(response, ResourcesKey.ErrorWhenDeletingData); + } + + public async Task FetchDataAsync(string? url) + { + var response = await httpClient.GetAsync(url); + + return await GetResultValue(response, ResourcesKey.ErrorWhenFetchingData); + } + + public async Task FetchBytesAsync(string? url) + { + var response = await httpClient.GetAsync(url); + + if (response.IsSuccessStatusCode) + { + return await response.Content.ReadAsByteArrayAsync(); + } + + throw new HttpRequestException( + $"{ResourcesKey.ErrorWhenFetchingData} + StatusCode: {response.StatusCode} " + + $"+ Reason: {response.ReasonPhrase}"); + } + + public async Task FetchStreamAsync(string? url) + { + var response = await httpClient.GetAsync(url); + + if (response.IsSuccessStatusCode) + { + return await response.Content.ReadAsStreamAsync(); + } + + throw new HttpRequestException($"{ResourcesKey.ErrorWhenFetchingData} + StatusCode: {response.StatusCode} " + + $"+ Reason: {response.ReasonPhrase}"); + } + + public async Task PostFileAsync(string? url, Stream fileStream, string fileName, string contentType) + { + using var content = new MultipartFormDataContent(); + + var streamContent = new StreamContent(fileStream); + streamContent.Headers.ContentType = new MediaTypeHeaderValue(contentType); + content.Add(streamContent, "file", fileName); + + var response = await httpClient.PostAsync(url, content); + + return await GetResultValue(response, ResourcesKey.ErrorWhenPostingData); + } + + private async Task GetResultValue(HttpResponseMessage response, string errorMessage) + { + if (response.IsSuccessStatusCode) + { + try + { + var responseContent = await response.Content.ReadAsStringAsync(); + + if (string.IsNullOrWhiteSpace(responseContent)) + { + return default; + } + + var result = JsonSerializer.Deserialize(responseContent, _optionsCaseInsensitive); + + return result; + } + catch (Exception ex) + { + throw new JsonException(ex.Message); + } + } + + logger.LogError(ResourcesKey.RequestFailedStatusFormat, response.StatusCode); + throw new HttpRequestException( + $"{errorMessage} + StatusCode: {response.StatusCode} + Reason: {response.ReasonPhrase}"); + } +} diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Services/IHttpClientService.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Services/IHttpClientService.cs new file mode 100644 index 0000000..299ab00 --- /dev/null +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Services/IHttpClientService.cs @@ -0,0 +1,12 @@ +namespace GameIdeas.BlazorApp.Services; + +public interface IHttpClientService +{ + Task PostAsync(string url, object data); + Task PutAsync(string url, object data); + Task DeleteAsync(string? url); + Task FetchDataAsync(string? url); + Task FetchBytesAsync(string? url); + Task FetchStreamAsync(string? url); + Task PostFileAsync(string? url, Stream fileStream, string fileName, string contentType); +} diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Account/AccountSettings.razor b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Account/AccountSettings.razor index 5b111c2..98094ae 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Account/AccountSettings.razor +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Account/AccountSettings.razor @@ -3,7 +3,7 @@