@inject SDK.Client Client @inject DepotService DepotService @inject LocalizationService LocalizationService @if (ListItems.Any()) { @if (Groups.Count > 1) { @foreach (var group in Groups) { @foreach (var item in ListItems.Where(i => i.Groups.Contains(group) || (group == "Uncategorized" && i.Groups.Length == 0))) { } } } else { @foreach (var item in ListItems) { } } } else if (DepotService.GetItemCount() > 0) { } else if (Loaded) { } @code { [Parameter] public EventCallback OnItemSelected { get; set; } IEnumerable ListItems { get; set; } = new List(); List Groups = new(); bool Loaded = false; protected override void OnInitialized() { base.OnInitialized(); DepotService.OnItemsFiltered += LoadFilteredItems; } async Task LoadFilteredItems(IEnumerable listItems) { ListItems = listItems; Loaded = true; await UpdateGroups(); } async Task UpdateGroups() { Groups = ListItems.DistinctBy(i => i.Key).SelectMany(i => i.Groups).Distinct().ToList(); if (ListItems.DistinctBy(i => i.Key).Any(i => i.Groups == null || i.Groups.Length == 0)) Groups.Add(LocalizationService.GetString("Uncategorized")); await InvokeAsync(StateHasChanged); } public void Dispose() { DepotService.OnItemsFiltered -= LoadFilteredItems; } }