using BlazorAppClean.Models; using BlazorAppClean.Services; using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; using System.Collections.ObjectModel; using System.Collections.Specialized; namespace BlazorAppClean.Components { public partial class InventoryComponent { [Inject] public IDataService DataService { get; set; } private int totalItem; public Item CurrentDragItem { get; set; } [CascadingParameter] public InventoryComponent Parent { get; set; } public List RecipeItems { get; set; } public List Items { get; set; } = new List(); public ObservableCollection Actions { get; set; } [Inject] internal IJSRuntime JavaScriptRuntime { get; set; } public InventoryComponent() { Actions = new ObservableCollection(); Actions.CollectionChanged += OnActionsCollectionChanged; this.RecipeItems = new List { null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null }; } protected override async Task OnAfterRenderAsync(bool firstRender) { base.OnAfterRenderAsync(firstRender); if (!firstRender) { return; } Items = await DataService.getAll(); totalItem = await DataService.Count(); StateHasChanged(); } private void OnActionsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) { JavaScriptRuntime.InvokeVoidAsync("Crafting.AddActions", e.NewItems); } } }