From fe350955a00ec061d2ee9aadee484eda023f5a2c Mon Sep 17 00:00:00 2001 From: Alexis DRAI Date: Sun, 26 Feb 2023 16:47:47 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20give=20up=20on=20pictures=20in?= =?UTF-8?q?=20inventory=20for=20now?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blazor_lab/Components/InventoryItem.razor | 5 ++++- blazor_lab/Components/InventoryItem.razor.cs | 20 +++----------------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/blazor_lab/Components/InventoryItem.razor b/blazor_lab/Components/InventoryItem.razor index 789ca64..e19e94d 100644 --- a/blazor_lab/Components/InventoryItem.razor +++ b/blazor_lab/Components/InventoryItem.razor @@ -13,7 +13,10 @@ @if (InventoryModel is not null && IsInInventory) {
- @InventoryModel.ItemName + @if (InventoryModel.NumberItem > 0) + { +
@InventoryModel.ItemName
+ }
@InventoryModel.NumberItem
} diff --git a/blazor_lab/Components/InventoryItem.razor.cs b/blazor_lab/Components/InventoryItem.razor.cs index 6eb88a0..1d26a07 100644 --- a/blazor_lab/Components/InventoryItem.razor.cs +++ b/blazor_lab/Components/InventoryItem.razor.cs @@ -1,6 +1,7 @@ using blazor_lab.Services; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Web; +using Minecraft.Crafting.Api; using Minecraft.Crafting.Api.Models; using System.Diagnostics; using Item = blazor_lab.Models.Item; @@ -27,9 +28,6 @@ namespace blazor_lab.Components [CascadingParameter] public Inventory? InventoryParent { get; set; } - [Inject] - public IDataService DataService { get; set; } - public InventoryModel InventoryModel { get; set; } = new InventoryModel(); public InventoryItem() @@ -54,7 +52,7 @@ namespace blazor_lab.Components { InventoryModel = InventoryParent!.CurrentDragItem!; InventoryModel.Position = Position; - InventoryParent.InventoryContent.Add(InventoryModel); + InventoryParent.InventoryContent.Insert(Position, InventoryModel); } else { @@ -64,6 +62,7 @@ namespace blazor_lab.Components } } } + StateHasChanged(); } internal void OnDragEnd() @@ -92,18 +91,5 @@ namespace blazor_lab.Components } } } - - public async Task GetItemImageBase64() - { - // FIXME probably not great to inject a service in each item and query the whole database everytime we display it - - if (InventoryParent is not null) - { - return (await DataService.List(0, await DataService.Count())) - .FirstOrDefault(i => i.DisplayName == InventoryModel.ItemName)? - .ImageBase64; - } - else return null; - } } }