From e4d482059ccb00017918bf0caf804cdc4019dd14 Mon Sep 17 00:00:00 2001 From: Alexis DRAI Date: Sat, 25 Feb 2023 17:09:34 +0100 Subject: [PATCH] :sparkles: Set up Inventory page, let it take care of grid Items --- blazor_lab/Components/InventoryGrid.razor.cs | 23 ++++++-------------- blazor_lab/Pages/Inventory.razor | 12 ++++++++-- blazor_lab/Pages/Inventory.razor.cs | 21 ++++++++++++++++-- blazor_lab/Pages/Inventory.razor.css | 4 ++++ 4 files changed, 40 insertions(+), 20 deletions(-) create mode 100644 blazor_lab/Pages/Inventory.razor.css diff --git a/blazor_lab/Components/InventoryGrid.razor.cs b/blazor_lab/Components/InventoryGrid.razor.cs index 8f4f551..13696f3 100644 --- a/blazor_lab/Components/InventoryGrid.razor.cs +++ b/blazor_lab/Components/InventoryGrid.razor.cs @@ -1,5 +1,4 @@ -using blazor_lab.Services; -using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components; using Minecraft.Crafting.Api.Models; @@ -11,20 +10,12 @@ namespace blazor_lab.Components [Parameter] public List Inventory { get; set; } - public List Items { get; set; } = new List(); - - [Inject] - public IConfiguration Config { get; set; } - - - [Inject] - private DataApiService dataApiService { get; set; } - - - protected override async Task OnInitializedAsync() - { - Items = await dataApiService.All(); - } + /// + /// Used by GetItemImageBase64 in this component, rather than calling our DataService every time. + /// A very basic cache, not kept up to date in any way, but event listeners could be set up in the future + /// + [Parameter] + public List Items { get; set; } public string GetItemImageBase64(string displayName) { diff --git a/blazor_lab/Pages/Inventory.razor b/blazor_lab/Pages/Inventory.razor index 6837b6b..8db9eac 100644 --- a/blazor_lab/Pages/Inventory.razor +++ b/blazor_lab/Pages/Inventory.razor @@ -2,6 +2,14 @@ @using Minecraft.Crafting.Api.Models @using blazor_lab.Components -

Inventory

+
+
+

@Localizer["my_inventory"]

- \ No newline at end of file + +
+
+

@Localizer["list_of_items"]

+ +
+
\ No newline at end of file diff --git a/blazor_lab/Pages/Inventory.razor.cs b/blazor_lab/Pages/Inventory.razor.cs index b5b367f..759fcfb 100644 --- a/blazor_lab/Pages/Inventory.razor.cs +++ b/blazor_lab/Pages/Inventory.razor.cs @@ -1,9 +1,26 @@ -using Minecraft.Crafting.Api.Models; +using blazor_lab.Services; +using Microsoft.AspNetCore.Components; +using Microsoft.Extensions.Localization; +using Minecraft.Crafting.Api.Models; +using System.Diagnostics; namespace blazor_lab.Pages { public partial class Inventory { - private List Stuff = Enumerable.Range(1, 18).Select(_ => new InventoryModel()).ToList(); + private List Items = new(); + + [Inject] + public IStringLocalizer Localizer { get; set; } + + [Inject] + private DataApiService DataApiService { get; set; } + + protected override async Task OnInitializedAsync() + { + Items = await DataApiService.All(); + } + + private List FreshInventory = Enumerable.Range(1, 18).Select(_ => new InventoryModel()).ToList(); } } diff --git a/blazor_lab/Pages/Inventory.razor.css b/blazor_lab/Pages/Inventory.razor.css new file mode 100644 index 0000000..ff5602f --- /dev/null +++ b/blazor_lab/Pages/Inventory.razor.css @@ -0,0 +1,4 @@ +.side-by-side { + display: flex; + flex-direction: row; +}